Skip to content

Commit

Permalink
Cognito Roles Attachment: Fixed cast issue, updated test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninir committed Oct 23, 2017
1 parent e7ed12f commit 230b696
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
6 changes: 3 additions & 3 deletions aws/resource_aws_cognito_identity_pool_roles_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func resourceAwsCognitoIdentityPoolRolesAttachmentCreate(d *schema.ResourceData,
return fmt.Errorf("Error validating ambiguous role resolution: %v", errors)
}

params.RoleMappings = expandCognitoIdentityPoolRoleMappingsAttachment(v.([]interface{}))
params.RoleMappings = expandCognitoIdentityPoolRoleMappingsAttachment(v.(*schema.Set).List())
}

log.Sprintf("[DEBUG] Creating Cognito Identity Pool Roles Association: %#v", params)
log.Printf("[DEBUG] Creating Cognito Identity Pool Roles Association: %#v", params)
_, err := conn.SetIdentityPoolRoles(params)
if err != nil {
return fmt.Errorf("Error creating Cognito Identity Pool Roles Association: %s", err)
Expand Down Expand Up @@ -198,7 +198,7 @@ func resourceAwsCognitoIdentityPoolRolesAttachmentUpdate(d *schema.ResourceData,
params.RoleMappings = expandCognitoIdentityPoolRoleMappingsAttachment(mappings)
}

log.Sprintf("[DEBUG] Updating Cognito Identity Pool Roles Association: %#v", params)
log.Printf("[DEBUG] Updating Cognito Identity Pool Roles Association: %#v", params)
_, err := conn.SetIdentityPoolRoles(params)
if err != nil {
return fmt.Errorf("Error updating Cognito Identity Pool Roles Association: %s", err)
Expand Down
47 changes: 28 additions & 19 deletions aws/resource_aws_cognito_identity_pool_roles_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ func testAccCheckAWSCognitoIdentityPoolRolesAttachmentDestroy(s *terraform.State
return nil
}

const baseAWSCognitoIdentityPoolRolesAttachmentConfig = `
func baseAWSCognitoIdentityPoolRolesAttachmentConfig(name string) string {
return fmt.Sprintf(`
resource "aws_cognito_identity_pool" "main" {
identity_pool_name = "identity pool %s"
identity_pool_name = "identity pool %[1]s"
allow_unauthenticated_identities = false
supported_login_providers {
Expand All @@ -199,7 +200,7 @@ resource "aws_cognito_identity_pool" "main" {
# Unauthenticated Role
resource "aws_iam_role" "unauthenticated" {
name = "cognito_unauthenticated_%s"
name = "cognito_unauthenticated_%[1]s"
assume_role_policy = <<EOF
{
Expand All @@ -226,7 +227,7 @@ EOF
}
resource "aws_iam_role_policy" "unauthenticated" {
name = "unauthenticated_policy_%s"
name = "unauthenticated_policy_%[1]s"
role = "${aws_iam_role.unauthenticated.id}"
policy = <<EOF
Expand All @@ -250,7 +251,7 @@ EOF
# Authenticated Role
resource "aws_iam_role" "authenticated" {
name = "cognito_authenticated_%s"
name = "cognito_authenticated_%[1]s"
assume_role_policy = <<EOF
{
Expand All @@ -277,7 +278,7 @@ EOF
}
resource "aws_iam_role_policy" "authenticated" {
name = "authenticated_policy_%s"
name = "authenticated_policy_%[1]s"
role = "${aws_iam_role.authenticated.id}"
policy = <<EOF
Expand All @@ -299,22 +300,23 @@ resource "aws_iam_role_policy" "authenticated" {
}
EOF
}
`
`, name)
}

func testAccAWSCognitoIdentityPoolRolesAttachmentConfig_basic(name string) string {
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig+`
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig(name) + `
resource "aws_cognito_identity_pool_roles_attachment" "main" {
identity_pool_id = "${aws_cognito_identity_pool.main.id}"
roles {
"authenticated" = "${aws_iam_role.authenticated.arn}"
}
}
`, name, name, name, name, name)
`)
}

func testAccAWSCognitoIdentityPoolRolesAttachmentConfig_roleMappings(name string) string {
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig+`
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig(name) + `
resource "aws_cognito_identity_pool_roles_attachment" "main" {
identity_pool_id = "${aws_cognito_identity_pool.main.id}"
Expand All @@ -335,11 +337,11 @@ resource "aws_cognito_identity_pool_roles_attachment" "main" {
"authenticated" = "${aws_iam_role.authenticated.arn}"
}
}
`, name, name, name, name, name)
`)
}

func testAccAWSCognitoIdentityPoolRolesAttachmentConfig_roleMappingsUpdated(name string) string {
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig+`
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig(name) + `
resource "aws_cognito_identity_pool_roles_attachment" "main" {
identity_pool_id = "${aws_cognito_identity_pool.main.id}"
Expand All @@ -354,17 +356,24 @@ resource "aws_cognito_identity_pool_roles_attachment" "main" {
role_arn = "${aws_iam_role.authenticated.arn}"
value = "unpaid"
}
mapping_rule {
claim = "isFoo"
match_type = "Equals"
role_arn = "${aws_iam_role.authenticated.arn}"
value = "bar"
}
}
roles {
"authenticated" = "${aws_iam_role.authenticated.arn}"
}
}
`, name, name, name, name, name)
`)
}

func testAccAWSCognitoIdentityPoolRolesAttachmentConfig_roleMappingsWithAmbiguousRoleResolutionError(name string) string {
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig+`
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig(name) + `
resource "aws_cognito_identity_pool_roles_attachment" "main" {
identity_pool_id = "${aws_cognito_identity_pool.main.id}"
Expand All @@ -384,11 +393,11 @@ resource "aws_cognito_identity_pool_roles_attachment" "main" {
"authenticated" = "${aws_iam_role.authenticated.arn}"
}
}
`, name, name, name, name, name)
`)
}

func testAccAWSCognitoIdentityPoolRolesAttachmentConfig_roleMappingsWithRulesTypeError(name string) string {
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig+`
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig(name) + `
resource "aws_cognito_identity_pool_roles_attachment" "main" {
identity_pool_id = "${aws_cognito_identity_pool.main.id}"
Expand All @@ -402,11 +411,11 @@ resource "aws_cognito_identity_pool_roles_attachment" "main" {
"authenticated" = "${aws_iam_role.authenticated.arn}"
}
}
`, name, name, name, name, name)
`)
}

func testAccAWSCognitoIdentityPoolRolesAttachmentConfig_roleMappingsWithTokenTypeError(name string) string {
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig+`
return fmt.Sprintf(baseAWSCognitoIdentityPoolRolesAttachmentConfig(name) + `
resource "aws_cognito_identity_pool_roles_attachment" "main" {
identity_pool_id = "${aws_cognito_identity_pool.main.id}"
Expand All @@ -427,5 +436,5 @@ resource "aws_cognito_identity_pool_roles_attachment" "main" {
"authenticated" = "${aws_iam_role.authenticated.arn}"
}
}
`, name, name, name, name, name)
`)
}

0 comments on commit 230b696

Please sign in to comment.