Skip to content

Commit

Permalink
Merge pull request #178 from Cox-Automotive/error_handling
Browse files Browse the repository at this point in the history
Error handling
  • Loading branch information
elliottzack429 committed Oct 4, 2022
2 parents 05d6958 + 14e4cfb commit 41cd02b
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 26 deletions.
8 changes: 4 additions & 4 deletions docs/guides/local_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ mkdir -p ~/.terraform.d/plugins &&
**One-liner download for macOS / Linux:**

```sh
mkdir -p ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.0.5/darwin_amd64 &&
mkdir -p ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.6.0/darwin_amd64 &&
curl -Ls https://api.github.com/repos/Cox-Automotive/terraform-provider-alks/releases | jq -r --arg release "v2.5.1" --arg arch "$(uname -s | tr A-Z a-z)" '.[] | select(.tag_name | contains($release)) | .assets[]| select(.browser_download_url | contains($arch)) | select(.browser_download_url | contains("amd64")) | .browser_download_url' |
xargs -n 1 curl -Lo ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.0.5/darwin_amd64/terraform-provider-alks.zip &&
pushd ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.0.5/darwin_amd64 &&
unzip ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.0.5/darwin_amd64/terraform-provider-alks.zip -d terraform-provider-alks-tmp &&
xargs -n 1 curl -Lo ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.6.0/darwin_amd64/terraform-provider-alks.zip &&
pushd ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.6.0/darwin_amd64 &&
unzip ~/.terraform.d/plugins/Cox-Automotive/engineering-enablement/alks/2.6.0/darwin_amd64/terraform-provider-alks.zip -d terraform-provider-alks-tmp &&
mv terraform-provider-alks-tmp/terraform-provider-alks* . &&
chmod +x terraform-provider-alks* &&
rm -rf terraform-provider-alks-tmp &&
Expand Down
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-20220819173421-e4df7b313407
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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Cox-Automotive/alks-go v0.0.0-20220819173421-e4df7b313407 h1:3vsLn/7axoDZXlseWBXghb5YZemEtevxJ3hopeOa8Pk=
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
11 changes: 10 additions & 1 deletion resource_alks_iamrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,17 @@ 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] %s", err)
d.SetId("")
return nil
}
}
d.SetId("")
return nil
return diag.FromErr(err)
}

log.Printf("[INFO] alks_iamrole.id %v", d.Id())
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
26 changes: 26 additions & 0 deletions vendor/github.com/Cox-Automotive/alks-go/api.go

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

104 changes: 104 additions & 0 deletions vendor/github.com/Cox-Automotive/alks-go/iam_ltk.go

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

Loading

0 comments on commit 41cd02b

Please sign in to comment.