Skip to content

Commit

Permalink
Change schema embedding to fix Go linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ringods committed Oct 28, 2024
1 parent e41bc76 commit 4176ec3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion provider/cmd/pulumi-resource-unifi/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
schema.go
schema-embed.json
18 changes: 11 additions & 7 deletions provider/cmd/pulumi-resource-unifi/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build ignore
//go:build ignore

package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"errors"
"io/fs"
"log"
"os"

Expand All @@ -32,7 +32,7 @@ func main() {
log.Fatal("version not found")
}

schemaContents, err := ioutil.ReadFile("./schema.json")
schemaContents, err := os.ReadFile("./schema.json")
if err != nil {
log.Fatal(err)
}
Expand All @@ -49,9 +49,13 @@ func main() {
log.Fatalf("cannot reserialize schema: %v", err)
}

err = ioutil.WriteFile("./schema.go", []byte(fmt.Sprintf(`package main
var pulumiSchema = %#v
`, versionedContents)), 0600)
// Clean up schema.go as it may be present & gitignored and tolerate an error if the file isn't present.
err = os.Remove("./schema.go")
if err != nil && !errors.Is(err, fs.ErrNotExist) {
log.Fatal(err)
}

err = os.WriteFile("./schema-embed.json", versionedContents, 0600)
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions provider/cmd/pulumi-resource-unifi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
package main

import (
_ "embed"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

unifi "github.com/pulumiverse/pulumi-unifi/provider"
"github.com/pulumiverse/pulumi-unifi/provider/pkg/version"
)

//go:embed schema-embed.json
var pulumiSchema []byte

func main() {
// Modify the path to point to the new provider
tfbridge.Main("unifi", version.Version, unifi.Provider(), pulumiSchema)
Expand Down

0 comments on commit 4176ec3

Please sign in to comment.