From 793ea4cea0de793aae14fd9991d3c9551579d065 Mon Sep 17 00:00:00 2001 From: Zack Elliott Date: Tue, 4 Oct 2022 16:32:34 -0500 Subject: [PATCH] Update functionality of 404 responses from alks --- go.mod | 2 +- go.sum | 2 ++ resource_alks_iamrole.go | 14 +++++++++----- resource_alks_iamrole_test.go | 5 ++++- .../github.com/Cox-Automotive/alks-go/iam_role.go | 3 +++ vendor/modules.txt | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f1689ff0..cbb0dc91 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Cox-Automotive/terraform-provider-alks go 1.18 require ( - github.com/Cox-Automotive/alks-go v0.0.0-20221003153830-68567ef62d72 + github.com/Cox-Automotive/alks-go v0.0.0-20221004204541-a25fb5c4f655 github.com/aws/aws-sdk-go v1.31.15 github.com/hashicorp/terraform-plugin-sdk/v2 v2.21.0 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index 5aa2f32d..cdc2e497 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/Cox-Automotive/alks-go v0.0.0-20220819173421-e4df7b313407 h1:3vsLn/7a github.com/Cox-Automotive/alks-go v0.0.0-20220819173421-e4df7b313407/go.mod h1:jJNgXthl59Vt2tJHSC3WZ0vlopV9xqdclfQuLgwHjOw= github.com/Cox-Automotive/alks-go v0.0.0-20221003153830-68567ef62d72 h1:tubP3IYGKaOLYJTLiUzQ6naXAwyWN21GUOB6bML4+6Y= github.com/Cox-Automotive/alks-go v0.0.0-20221003153830-68567ef62d72/go.mod h1:jJNgXthl59Vt2tJHSC3WZ0vlopV9xqdclfQuLgwHjOw= +github.com/Cox-Automotive/alks-go v0.0.0-20221004204541-a25fb5c4f655 h1:akQkFItS/++rMakX7rbK70ouYTG0Q6vxUqxvfzBZ9Wg= +github.com/Cox-Automotive/alks-go v0.0.0-20221004204541-a25fb5c4f655/go.mod h1:jJNgXthl59Vt2tJHSC3WZ0vlopV9xqdclfQuLgwHjOw= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= diff --git a/resource_alks_iamrole.go b/resource_alks_iamrole.go index 20de4436..0ee98476 100644 --- a/resource_alks_iamrole.go +++ b/resource_alks_iamrole.go @@ -195,15 +195,19 @@ func resourceAlksIamRoleRead(ctx context.Context, d *schema.ResourceData, meta i foundRole, err := client.GetIamRole(d.Id()) if err != nil { + // If 404 Role not found error, an error and a role with Exists field set to false will come back from alks-go + // We will log ther error and set id to "" and return nil, letting terraform decide how to handle role not found. + if foundRole != nil { + if foundRole.Exists != true { + log.Printf("[Error] %#v", err) + d.SetId("") + return nil + } + } d.SetId("") return diag.FromErr(err) } - if foundRole.Exists != true { - d.SetId("") - return nil - } - log.Printf("[INFO] alks_iamrole.id %v", d.Id()) _ = d.Set("name", foundRole.RoleName) diff --git a/resource_alks_iamrole_test.go b/resource_alks_iamrole_test.go index be14d737..aa4bfe1a 100644 --- a/resource_alks_iamrole_test.go +++ b/resource_alks_iamrole_test.go @@ -448,7 +448,10 @@ func testAccCheckAlksIamRoleDestroy(role *alks.IamRoleResponse) resource.TestChe respz, err := client.GetIamRole(rs.Primary.ID) if respz != nil { - return fmt.Errorf("Role still exists: %#v (%v)", respz, err) + if respz.Exists == true { + return fmt.Errorf("Role still exists: %#v (%v)", respz, err) + } + } } diff --git a/vendor/github.com/Cox-Automotive/alks-go/iam_role.go b/vendor/github.com/Cox-Automotive/alks-go/iam_role.go index 46bd6c38..8f64c266 100644 --- a/vendor/github.com/Cox-Automotive/alks-go/iam_role.go +++ b/vendor/github.com/Cox-Automotive/alks-go/iam_role.go @@ -560,6 +560,9 @@ func (c *Client) GetIamRole(roleName string) (*GetIamRoleResponse, error) { } if cr.RequestFailed() { + if resp.StatusCode == 404 { + return cr, fmt.Errorf("Error getting role: [%s] %s", cr.BaseResponse.RequestID, strings.Join(cr.GetErrors(), ", ")) + } return nil, fmt.Errorf("Error getting role: [%s] %s", cr.BaseResponse.RequestID, strings.Join(cr.GetErrors(), ", ")) } diff --git a/vendor/modules.txt b/vendor/modules.txt index b81c3615..acca1862 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/Cox-Automotive/alks-go v0.0.0-20221003153830-68567ef62d72 +# github.com/Cox-Automotive/alks-go v0.0.0-20221004204541-a25fb5c4f655 ## explicit; go 1.16 github.com/Cox-Automotive/alks-go # github.com/agext/levenshtein v1.2.2