Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ test_nodejs: provider install_nodejs_sdk

.PHONY: schema_squeeze
schema_squeeze: bin/$(CODEGEN)
bin/$(CODEGEN) squeeze $(PROVIDER_VERSION)
bin/$(CODEGEN) squeeze

.PHONY: explode_schema
explode_schema: dist/docs-schema.json
Expand Down Expand Up @@ -232,12 +232,12 @@ bin/$(CODEGEN): .make/prebuild .make/provider_mod_download provider/cmd/$(CODEGE
# Writes schema-full.json and metadata-compact.json to bin/
# Also re-calculates files in versions/ at same time
bin/schema-full.json bin/metadata-compact.json &: bin/$(CODEGEN) $(SPECS) versions/az-provider-list.json versions/v${PREVIOUS_MAJOR_VERSION}.yaml versions/v${MAJOR_VERSION}-config.yaml versions/v${MAJOR_VERSION}-spec.yaml versions/v${MAJOR_VERSION}-removed.json versions/v${MAJOR_VERSION}-removed-resources.json versions/v${NEXT_MAJOR_VERSION}-removed-resources.json
bin/$(CODEGEN) schema $(PROVIDER_VERSION)
bin/$(CODEGEN) schema

# Docs schema - treat as phony becasuse it's committed so we always need to rebuild it.
.PHONY: provider/cmd/pulumi-resource-azure-native/schema.json
provider/cmd/pulumi-resource-azure-native/schema.json: bin/$(CODEGEN) $(SPECS) versions/v${PREVIOUS_MAJOR_VERSION}.yaml versions/v${MAJOR_VERSION}-config.yaml versions/v${MAJOR_VERSION}-removed-resources.json
bin/$(CODEGEN) docs $(PROVIDER_VERSION)
bin/$(CODEGEN) docs

bin/$(LOCAL_PROVIDER_FILENAME): .make/prebuild .make/provider_mod_download provider/cmd/$(PROVIDER)/*.go .make/provider_prebuild $(PROVIDER_PKG)
cd provider && \
Expand Down Expand Up @@ -363,7 +363,7 @@ export FAKE_MODULE
@# Unmark this is as an up-to-date local build
rm -f .make/prepublish_go
rm -rf $$(find sdk/pulumi-azure-native-sdk -mindepth 1 -maxdepth 1 ! -name ".git")
bin/$(CODEGEN) go $(PROVIDER_VERSION)
bin/$(CODEGEN) go
@# Tidy up all go.mod files
find sdk/pulumi-azure-native-sdk -type d -maxdepth 1 -exec sh -c "cd \"{}\" && go mod tidy" \;
@touch $@
Expand Down
26 changes: 17 additions & 9 deletions provider/cmd/pulumi-gen-azure-native/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"path"
"path/filepath"
"strings"
"text/template"

"github.com/segmentio/encoding/json"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/gen"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/resources"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/squeeze"
embeddedVersion "github.com/pulumi/pulumi-azure-native/v2/provider/pkg/version"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/versioning"
gogen "github.com/pulumi/pulumi/pkg/v3/codegen/go"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
Expand All @@ -33,10 +33,18 @@ func main() {

languages := os.Args[1]

version := ""
// The third argument is the optional version.
// Exactly one of the CLI arg or embedded version must be set.
if len(os.Args) == 3 {
version = os.Args[2]
if embeddedVersion.Version != "" {
panic(fmt.Sprintf("embedded version already set to %s", embeddedVersion.Version))
}
embeddedVersion.Version = os.Args[2]
} else if embeddedVersion.Version == "" {
panic("no version provided via CLI argument or ldflags")
}
// Use the one true version everywhere.
version := embeddedVersion.GetVersion()

wd, err := os.Getwd()
if err != nil {
Expand Down Expand Up @@ -70,7 +78,7 @@ func main() {
VersionsFilter: apiVersions,
},
RootDir: wd,
Version: version,
Version: version.String(),
}

switch languages {
Expand Down Expand Up @@ -104,7 +112,7 @@ func main() {
if codegenSchemaOutputPath == "" {
codegenSchemaOutputPath = path.Join("bin", "schema-full.json")
}
if err = emitSchema(buildSchemaResult.PackageSpec, version, codegenSchemaOutputPath); err != nil {
if err = emitSchema(buildSchemaResult.PackageSpec, version.String(), codegenSchemaOutputPath); err != nil {
panic(err)
}
fmt.Printf("Emitted %s.\n", codegenSchemaOutputPath)
Expand Down Expand Up @@ -148,12 +156,12 @@ func main() {
panic(err)
}
squeezedInvokes := versioning.FindRemovedInvokesFromResources(buildSchemaResult.Modules, squeezedResources)
majorVersion := strings.Split(version, ".")[0]
err = gen.EmitFile(path.Join("versions", fmt.Sprintf("v%s-removed-resources.json", majorVersion)), squeezedResources)
majorVersion := version.Major
err = gen.EmitFile(path.Join("versions", fmt.Sprintf("v%d-removed-resources.json", majorVersion)), squeezedResources)
if err != nil {
panic(err)
}
err = gen.EmitFile(path.Join("versions", fmt.Sprintf("v%s-removed-invokes.yaml", majorVersion)), squeezedInvokes)
err = gen.EmitFile(path.Join("versions", fmt.Sprintf("v%d-removed-invokes.yaml", majorVersion)), squeezedInvokes)
if err != nil {
panic(err)
}
Expand All @@ -170,7 +178,7 @@ func main() {
panic(err)
}
outdir := path.Join(".", "sdk", "pulumi-azure-native-sdk")
pkgSpec.Version = version
pkgSpec.Version = version.String()
err = emitSplitPackage(&pkgSpec, "go", outdir)
if err != nil {
panic(err)
Expand Down
20 changes: 6 additions & 14 deletions provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ func PulumiSchema(rootDir string, modules openapi.AzureModules, versioning Versi
for moduleName, moduleVersions := range util.MapOrdered(modules) {
resourcePaths := map[openapi.ResourceName]map[string][]openapi.ApiVersion{}

versions := util.SortedKeys(moduleVersions)
allVersions := util.SortedKeys(moduleVersions)
// The version in the parsed module is "" for the default version.
for _, moduleVersion := range versions {
for moduleVersion, versionResources := range util.MapOrdered(moduleVersions) {
var sdkVersion openapi.SdkVersion
var apiVersion *openapi.ApiVersion
if moduleVersion.IsDefault() {
Expand All @@ -305,7 +305,7 @@ func PulumiSchema(rootDir string, modules openapi.AzureModules, versioning Versi
moduleName: moduleName,
apiVersion: apiVersion,
sdkVersion: sdkVersion,
allVersions: versions,
allVersions: allVersions,
examples: exampleMap,
versioning: versioning,
caseSensitiveTypes: caseSensitiveTypes,
Expand All @@ -328,24 +328,16 @@ func PulumiSchema(rootDir string, modules openapi.AzureModules, versioning Versi
golangImportAliases[goModuleName(gen.moduleName, gen.sdkVersion)] = moduleName.Lowered()

// Populate resources and get invokes.
items := moduleVersions[moduleVersion]
var resources []string
for resource := range items.Resources {
resources = append(resources, resource)
}
sort.Strings(resources)

for _, typeName := range resources {
resource := items.Resources[typeName]
nestedResourceBodyRefs := findNestedResourceBodyRefs(resource, items.Resources)
for typeName, resource := range util.MapOrdered(versionResources.Resources) {
nestedResourceBodyRefs := findNestedResourceBodyRefs(resource, versionResources.Resources)
err := gen.genResources(typeName, resource, nestedResourceBodyRefs)
if err != nil {
return nil, err
}
}

// Populate invokes.
gen.genInvokes(items.Invokes)
gen.genInvokes(versionResources.Invokes)

forceNewTypes = append(forceNewTypes, gen.forceNewTypes...)
gen.mergeResourcePathsInto(resourcePaths)
Expand Down