Skip to content

Commit

Permalink
aws: Fix OID connect provider updates + simplify + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Apr 7, 2017
1 parent 872ebc6 commit 1506e9e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
13 changes: 3 additions & 10 deletions builtin/providers/aws/resource_aws_iam_openid_connect_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,13 @@ func resourceAwsIamOpenIDConnectProvider() *schema.Resource {
}
}

func stringListToStringSlice(stringList []interface{}) []string {
ret := []string{}
for _, v := range stringList {
ret = append(ret, v.(string))
}
return ret
}

func resourceAwsIamOpenIDConnectProviderCreate(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn

input := &iam.CreateOpenIDConnectProviderInput{
Url: aws.String(d.Get("url").(string)),
ClientIDList: aws.StringSlice(stringListToStringSlice(d.Get("client_id_list").([]interface{}))),
ThumbprintList: aws.StringSlice(stringListToStringSlice(d.Get("thumbprint_list").([]interface{}))),
ClientIDList: expandStringList(d.Get("client_id_list").([]interface{})),
ThumbprintList: expandStringList(d.Get("thumbprint_list").([]interface{})),
}

out, err := iamconn.CreateOpenIDConnectProvider(input)
Expand Down Expand Up @@ -97,6 +89,7 @@ func resourceAwsIamOpenIDConnectProviderUpdate(d *schema.ResourceData, meta inte
if d.HasChange("thumbprint_list") {
input := &iam.UpdateOpenIDConnectProviderThumbprintInput{
OpenIDConnectProviderArn: aws.String(d.Id()),
ThumbprintList: expandStringList(d.Get("thumbprint_list").([]interface{})),
}

_, err := iamconn.UpdateOpenIDConnectProviderThumbprint(input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,42 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSIAMOpenIDConnectProvider_basic(t *testing.T) {
rString := acctest.RandString(5)
url := "accounts.google.com/" + rString

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIAMOpenIDConnectProviderDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccIAMOpenIDConnectProviderConfig,
Config: testAccIAMOpenIDConnectProviderConfig(rString),
Check: resource.ComposeTestCheckFunc(
testAccCheckIAMOpenIDConnectProvider("aws_iam_openid_connect_provider.goog"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "url", url),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "client_id_list.#", "1"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "client_id_list.0",
"266362248691-re108qaeld573ia0l6clj2i5ac7r7291.apps.googleusercontent.com"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "thumbprint_list.#", "0"),
),
},
resource.TestStep{
Config: testAccIAMOpenIDConnectProviderConfig_modified(rString),
Check: resource.ComposeTestCheckFunc(
testAccCheckIAMOpenIDConnectProvider("aws_iam_openid_connect_provider.goog"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "url", url),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "client_id_list.#", "1"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "client_id_list.0",
"266362248691-re108qaeld573ia0l6clj2i5ac7r7291.apps.googleusercontent.com"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "thumbprint_list.#", "2"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "thumbprint_list.0", "cf23df2207d99a74fbe169e3eba035e633b65d94"),
resource.TestCheckResourceAttr("aws_iam_openid_connect_provider.goog", "thumbprint_list.1", "c784713d6f9cb67b55dd84f4e4af7832d42b8f55"),
),
},
},
Expand Down Expand Up @@ -79,12 +101,26 @@ func testAccCheckIAMOpenIDConnectProvider(id string) resource.TestCheckFunc {
}
}

const testAccIAMOpenIDConnectProviderConfig = `
func testAccIAMOpenIDConnectProviderConfig(rString string) string {
return fmt.Sprintf(`
resource "aws_iam_openid_connect_provider" "goog" {
url="https://accounts.google.com"
url="https://accounts.google.com/%s"
client_id_list = [
"266362248691-re108qaeld573ia0l6clj2i5ac7r7291.apps.googleusercontent.com"
]
thumbprint_list = []
}
`
`, rString)
}

func testAccIAMOpenIDConnectProviderConfig_modified(rString string) string {
return fmt.Sprintf(`
resource "aws_iam_openid_connect_provider" "goog" {
url="https://accounts.google.com/%s"
client_id_list = [
"266362248691-re108qaeld573ia0l6clj2i5ac7r7291.apps.googleusercontent.com"
]
thumbprint_list = ["cf23df2207d99a74fbe169e3eba035e633b65d94", "c784713d6f9cb67b55dd84f4e4af7832d42b8f55"]
}
`, rString)
}

0 comments on commit 1506e9e

Please sign in to comment.