Skip to content

Commit

Permalink
tools/update-go-azure-sdk: updating both the Base Layer and Resourc…
Browse files Browse the repository at this point in the history
…e Manager submodules

Dependent on (and can't be fully tested until) hashicorp/pandora#3601 is rolled out.
  • Loading branch information
tombuildsstuff committed Jan 23, 2024
1 parent 39ff4d7 commit 2eebe1e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions internal/tools/update-go-azure-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ func run(ctx context.Context, input config) error {
}

// 3. Update the version of `hashicorp/go-azure-sdk` used in `terraform-provider-azurerm`
logger.Info("Updating `hashicorp/go-azure-sdk`..")
if err := updateVersionOfGoAzureSDK(ctx, input.azurermRepoPath, input.newSdkVersion); err != nil {
logger.Info("Updating the `hashicorp/go-azure-sdk` base layer..")
if err := updateVersionOfGoAzureSDK(ctx, input.azurermRepoPath, baseLayerSubmoduleType, input.newSdkVersion); err != nil {
return fmt.Errorf("updating the version of go-azure-sdk: %+v", err)
}
logger.Info("Updating the `hashicorp/go-azure-sdk` resource manager submodule..")
if err := updateVersionOfGoAzureSDK(ctx, input.azurermRepoPath, resourceManagerSubmoduleType, input.newSdkVersion); err != nil {
return fmt.Errorf("updating the version of the go-azure-sdk: %+v", err)
}

// 4. Then for each new Service/API Version:
// a. Try updating to the new API Version
Expand Down Expand Up @@ -553,11 +557,23 @@ func parseChangesFromGitDiff(lines []string) changes {
return out
}

func updateVersionOfGoAzureSDK(ctx context.Context, workingDirectory, newApiVersion string) error {
logger.Debug(fmt.Sprintf("Updating the version of `go-azure-sdk` to %q", newApiVersion))
type submoduleType string

const (
// baseLayerSubmoduleType represents the submodule containing the base layer in `hashicorp/go-azure-sdk`
// this is the Go Module `github.com/hashicorp/go-azure-sdk/sdk`
baseLayerSubmoduleType submoduleType = "sdk"

// resourceManagerSubmoduleType represents the submodule containing the Resource Manager SDK in
// `hashicorp/go-azure-sdk` - which is the Go Module `github.com/hashicorp/go-azure-sdk/resource-manager`
resourceManagerSubmoduleType submoduleType = "resource-manager"
)

func updateVersionOfGoAzureSDK(ctx context.Context, workingDirectory string, submodule submoduleType, newApiVersion string) error {
logger.Debug(fmt.Sprintf("Updating the version of `go-azure-sdk`'s %q submodule to %q", string(submodule), newApiVersion))
args := []string{
"get",
fmt.Sprintf("github.com/hashicorp/go-azure-sdk@%s", newApiVersion),
fmt.Sprintf("github.com/hashicorp/go-azure-sdk@%s/%s", string(submodule), newApiVersion),
}
cmd := exec.CommandContext(ctx, "go", args...)
cmd.Dir = workingDirectory
Expand Down

0 comments on commit 2eebe1e

Please sign in to comment.