diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 784baee..4ff0c91 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,11 +14,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Unshallow run: git fetch --prune --unshallow - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - name: Test @@ -30,10 +30,10 @@ jobs: GPG_PRIVATE_KEY: ${{ secrets.TERRAFORM_GPG_PRIVATE_KEY }} PASSPHRASE: ${{ secrets.TERRAFORM_GPG_PASSPHRASE }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: version: latest - args: release --rm-dist --skip-publish --snapshot + args: release --clean --snapshot env: GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2171bb1..e6f6c7e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,11 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Unshallow run: git fetch --prune --unshallow - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - name: Test @@ -26,10 +26,10 @@ jobs: GPG_PRIVATE_KEY: ${{ secrets.TERRAFORM_GPG_PRIVATE_KEY }} PASSPHRASE: ${{ secrets.TERRAFORM_GPG_PASSPHRASE }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: version: latest - args: release --rm-dist + args: release --clean env: GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/main.go b/main.go index 9e2f544..ff9e629 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,10 @@ package main import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "terraform-provider-spinnaker/spinnaker" + "terraform-provider-spinnaker/spinnaker" ) func main() { diff --git a/spinnaker/api/application.go b/spinnaker/api/application.go index 4450481..ab41d66 100644 --- a/spinnaker/api/application.go +++ b/spinnaker/api/application.go @@ -15,7 +15,7 @@ import ( ) func GetApplication(client *gate.GatewayClient, applicationName string, dest interface{}) error { - app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)}) + app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)}) if resp != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { return fmt.Errorf("Application '%s' not found\n", applicationName) @@ -25,7 +25,7 @@ func GetApplication(client *gate.GatewayClient, applicationName string, dest int } if err != nil { - return FormatAPIErrorMessage ("ApplicationControllerApi.GetApplicationUsingGET", err) + return FormatAPIErrorMessage("ApplicationControllerApi.GetApplicationUsingGET", err) } if err := mapstructure.Decode(app, dest); err != nil { @@ -37,16 +37,16 @@ func GetApplication(client *gate.GatewayClient, applicationName string, dest int func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, email, applicationDescription string, platformHealthOnly, platformHealthOnlyShowOverride bool, - cloud_providers []interface{}, permissions *schema.Set) error { + cloud_providers []interface{}, permissions *schema.Set) error { jobType := "createApplication" jobDescription := fmt.Sprintf("Create Application: %s", applicationName) - app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)}) + app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)}) if resp != nil && resp.StatusCode == http.StatusOK && err == nil { jobType = "updateApplication" jobDescription = fmt.Sprintf("Update Application: %s", applicationName) } - + app = map[string]interface{}{ "instancePort": 80, "name": applicationName, @@ -56,28 +56,30 @@ func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, emai "description": applicationDescription, } - if len(cloud_providers) > 0 { + if len(cloud_providers) > 0 { providers_csv := "" for i := range cloud_providers { - if (i > 0) { providers_csv += "," } + if i > 0 { + providers_csv += "," + } providers_csv += cloud_providers[i].(string) } app["cloudProviders"] = providers_csv } - if permissions.Len() == 1 { + if permissions.Len() == 1 { permissions_object := make(map[string]interface{}) list := permissions.List() for k, value := range list[0].(map[string]interface{}) { switch key := k; key { - case "read": - permissions_object["READ"] = value - case "execute": - permissions_object["EXECUTE"] = value - case "write": - permissions_object["WRITE"] = value - default: - return fmt.Errorf("invalid permissions type of %s", key) + case "read": + permissions_object["READ"] = value + case "execute": + permissions_object["EXECUTE"] = value + case "write": + permissions_object["WRITE"] = value + default: + return fmt.Errorf("invalid permissions type of %s", key) } } app["permissions"] = permissions_object @@ -91,7 +93,7 @@ func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, emai ref, _, err := client.TaskControllerApi.TaskUsingPOST1(client.Context, createAppTask) if err != nil { - return FormatAPIErrorMessage ("TaskControllerApi.TaskUsingPOST1", err) + return FormatAPIErrorMessage("TaskControllerApi.TaskUsingPOST1", err) } toks := strings.Split(ref["ref"].(string), "/") @@ -99,17 +101,22 @@ func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, emai task, resp, err := client.TaskControllerApi.GetTaskUsingGET1(client.Context, id) attempts := 0 - for (task == nil || !taskCompleted(task)) && attempts < 5 { + maxAttempts := 40 + for (task == nil || !taskCompleted(task)) && attempts < maxAttempts { toks := strings.Split(ref["ref"].(string), "/") id := toks[len(toks)-1] task, resp, err = client.TaskControllerApi.GetTaskUsingGET1(client.Context, id) attempts += 1 - time.Sleep(time.Duration(attempts*attempts) * time.Second) + sleepDuration := time.Duration(attempts*attempts) * time.Second + if sleepDuration > 30*time.Second { + sleepDuration = 30 * time.Second + } + time.Sleep(sleepDuration) } if err != nil { - return FormatAPIErrorMessage ("TaskControllerApi.GetTaskUsingGET1", err) + return FormatAPIErrorMessage("TaskControllerApi.GetTaskUsingGET1", err) } if resp.StatusCode < 200 || resp.StatusCode > 299 { return fmt.Errorf("Encountered an error saving application, status code: %d\n", resp.StatusCode) @@ -138,7 +145,7 @@ func DeleteAppliation(client *gate.GatewayClient, applicationName string) error _, resp, err := client.TaskControllerApi.TaskUsingPOST1(client.Context, deleteAppTask) if err != nil { - return FormatAPIErrorMessage ("TaskControllerApi.TaskUsingPOST1", err) + return FormatAPIErrorMessage("TaskControllerApi.TaskUsingPOST1", err) } if resp.StatusCode != http.StatusOK { diff --git a/spinnaker/api/pipeline.go b/spinnaker/api/pipeline.go index c376a52..dc711f3 100644 --- a/spinnaker/api/pipeline.go +++ b/spinnaker/api/pipeline.go @@ -12,7 +12,7 @@ func CreatePipeline(client *gate.GatewayClient, pipeline interface{}) error { resp, err := client.PipelineControllerApi.SavePipelineUsingPOST(client.Context, pipeline, nil) if err != nil { - return FormatAPIErrorMessage ("PipelineControllerApi.SavePipelineUsingPOST", err) + return FormatAPIErrorMessage("PipelineControllerApi.SavePipelineUsingPOST", err) } if resp.StatusCode != http.StatusOK { @@ -33,7 +33,7 @@ func GetPipeline(client *gate.GatewayClient, applicationName, pipelineName strin } return jsonMap, fmt.Errorf("Encountered an error getting pipeline %s, %s\n", pipelineName, - FormatAPIErrorMessage ("PipelineControllerApi.GetPipelineConfigUsingGET", err)) + FormatAPIErrorMessage("PipelineControllerApi.GetPipelineConfigUsingGET", err)) } if resp.StatusCode != http.StatusOK { @@ -58,7 +58,7 @@ func UpdatePipeline(client *gate.GatewayClient, pipelineID string, pipeline inte _, resp, err := client.PipelineControllerApi.UpdatePipelineUsingPUT(client.Context, pipelineID, pipeline) if err != nil { - return FormatAPIErrorMessage ("PipelineControllerApi.UpdatePipelineUsingPUT", err) + return FormatAPIErrorMessage("PipelineControllerApi.UpdatePipelineUsingPUT", err) } if resp.StatusCode != http.StatusOK { @@ -72,7 +72,7 @@ func DeletePipeline(client *gate.GatewayClient, applicationName, pipelineName st resp, err := client.PipelineControllerApi.DeletePipelineUsingDELETE(client.Context, applicationName, pipelineName) if err != nil { - return FormatAPIErrorMessage ("PipelineControllerApi.DeletePipelineUsingDELETE", err) + return FormatAPIErrorMessage("PipelineControllerApi.DeletePipelineUsingDELETE", err) } if resp.StatusCode != http.StatusOK {