From 2eebe1ee6628a0f17acf219750787d7838eb9bdd Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 23 Jan 2024 12:29:14 +0100 Subject: [PATCH] `tools/update-go-azure-sdk`: updating both the Base Layer and Resource Manager submodules Dependent on (and can't be fully tested until) https://github.com/hashicorp/pandora/issues/3601 is rolled out. --- internal/tools/update-go-azure-sdk/main.go | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/tools/update-go-azure-sdk/main.go b/internal/tools/update-go-azure-sdk/main.go index 1d4c8a9f10c84..efca5ba96233b 100644 --- a/internal/tools/update-go-azure-sdk/main.go +++ b/internal/tools/update-go-azure-sdk/main.go @@ -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 @@ -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