mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-15 10:03:44 -06:00
aws: Fix OID connect provider updates + simplify + add tests
This commit is contained in:
parent
caa82d70ca
commit
ab4b06a95d
@ -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)
|
||||
@ -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)
|
||||
|
@ -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"),
|
||||
),
|
||||
},
|
||||
},
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user