Skip to content

Commit

Permalink
d/iam_session_context: Refactor arguments, attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Jun 28, 2021
1 parent 4947200 commit 8c76c24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 11 additions & 5 deletions aws/data_source_aws_iam_session_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ func dataSourceAwsIAMSessionContext() *schema.Resource {
Required: true,
ValidateFunc: validateArn,
},
"role_name": {
"issuer_arn": {
Type: schema.TypeString,
Computed: true,
},
"issuer_arn": {
"issuer_id": {
Type: schema.TypeString,
Computed: true,
},
"issuer_name": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -54,8 +58,9 @@ func dataSourceAwsIAMSessionContextRead(d *schema.ResourceData, meta interface{}

if roleName, sessionName = roleNameSessionFromARN(arn); roleName == "" {
d.Set("issuer_arn", arn)
d.Set("issuer_id", "")
d.Set("issuer_name", "")
d.Set("session_name", "")
d.Set("role_name", "")

return nil
}
Expand Down Expand Up @@ -90,9 +95,10 @@ func dataSourceAwsIAMSessionContextRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("empty role returned (%s)", roleName)
}

d.Set("session_name", sessionName)
d.Set("role_name", roleName)
d.Set("issuer_arn", role.Arn)
d.Set("issuer_id", role.RoleId)
d.Set("issuer_name", roleName)
d.Set("session_name", sessionName)

return nil
}
Expand Down
11 changes: 6 additions & 5 deletions aws/data_source_aws_iam_session_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func TestAccAWSDataSourceIAMSessionContext_basic(t *testing.T) {
Config: testAccAwsIAMSessionContextConfig(rName, "/", "session-id"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "role_name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_id", resourceName, "unique_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_name", resourceName, "name"),
resource.TestCheckResourceAttr(dataSourceName, "session_name", "session-id"),
),
},
Expand All @@ -126,7 +127,7 @@ func TestAccAWSDataSourceIAMSessionContext_withPath(t *testing.T) {
Config: testAccAwsIAMSessionContextConfig(rName, "/this/is/a/long/path/", "session-id"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "role_name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_name", resourceName, "name"),
resource.TestCheckResourceAttr(dataSourceName, "session_name", "session-id"),
),
},
Expand All @@ -148,7 +149,7 @@ func TestAccAWSDataSourceIAMSessionContext_notAssumedRole(t *testing.T) {
Config: testAccAwsIAMSessionContextNotAssumedConfig(rName, "/"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "role_name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_name", resourceName, "name"),
resource.TestCheckResourceAttr(dataSourceName, "session_name", ""),
),
},
Expand All @@ -170,7 +171,7 @@ func TestAccAWSDataSourceIAMSessionContext_notAssumedRoleWithPath(t *testing.T)
Config: testAccAwsIAMSessionContextNotAssumedConfig(rName, "/this/is/a/long/path/"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "role_name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "issuer_name", resourceName, "name"),
resource.TestCheckResourceAttr(dataSourceName, "session_name", ""),
),
},
Expand All @@ -191,7 +192,7 @@ func TestAccAWSDataSourceIAMSessionContext_notAssumedRoleUser(t *testing.T) {
Config: testAccAwsIAMSessionContextUserConfig(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckResourceAttrGlobalARN(dataSourceName, "arn", "iam", fmt.Sprintf("user/division/extra-division/not-assumed-role/%[1]s", rName)),
resource.TestCheckResourceAttr(dataSourceName, "role_name", ""),
resource.TestCheckResourceAttr(dataSourceName, "issuer_name", ""),
resource.TestCheckResourceAttr(dataSourceName, "session_name", ""),
),
},
Expand Down

0 comments on commit 8c76c24

Please sign in to comment.