Skip to content

Commit

Permalink
Update functionality of 404 responses from alks
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottzack429 committed Oct 4, 2022
1 parent 26b1e2a commit 793ea4c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 9 additions & 5 deletions resource_alks_iamrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion resource_alks_iamrole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}

Expand Down
3 changes: 3 additions & 0 deletions vendor/github.com/Cox-Automotive/alks-go/iam_role.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 793ea4c

Please sign in to comment.