Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MaxSesessionDuration to iam_role for federated users #3977

Merged
merged 7 commits into from
Apr 4, 2018

Conversation

stephencoe
Copy link
Contributor

Description

Adding max_session_duration to iam_role fixes #3976

Changes

  • bump aws provider
  • add max_session_duration

@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. dependencies Used to indicate dependency changes. labels Mar 29, 2018
@stephencoe stephencoe changed the title Iam role maxsesessionduration for federated users Add MaxSesessionDuration to iam_role for federated users Mar 29, 2018
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. dependencies Used to indicate dependency changes. labels Mar 29, 2018
@stephencoe
Copy link
Contributor Author

this is my first PR into TF, I am unsure why CI failed 😕

@bflad
Copy link
Contributor

bflad commented Mar 29, 2018

My recommendation is to split the SDK update into it's own PR first (generally we merge these really fast)

@@ -39,884 +39,892 @@
"revisionTime": "2017-07-27T15:54:43Z"
},
{
"checksumSHA1": "y1bmVkrw6lKwgq8z+S3GzO1F5JE=",
"checksumSHA1": "N+8JQQqczoq0UfwXrcVqqRDcb5E=",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you accidentally govendor the root? I think it'll complain about that. See any of the recent Deps: Bump aws-sdk-go PRs for how it's done (we're hoping to automate this shortly)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I will split that out

@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/XXL Managed by automation to categorize the size of a PR. dependencies Used to indicate dependency changes. labels Mar 29, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 29, 2018
Optional: true,
Default: 3600,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(int64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about replace custom function with existing validation.IntBetween() instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, this should be updated to ValidateFunc: validation.IntBetween(3600, 43200)

@bflad bflad added service/iam Issues and PRs that pertain to the iam service. enhancement Requests to existing resources that expand the functionality or scope. labels Apr 2, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @stephencoe! 👋 Thanks for submitting this! Can you please see the feedback below and let us know if you have any questions or do not have time to implement them?

if d.HasChange("max_session_duration") {
roleMaxDurationInput := &iam.UpdateRoleInput{
RoleName: aws.String(d.Id()),
MaxSessionDuration: aws.Int64(d.Get("assume_role_policy").(int64)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it has two issues:

  • Copy-paste typo of which attribute to grab, should be "max_session_duration"
  • schema.TypeInt returns a regular int, so I believe this needs to be aws.Int64(int64(d.Get("max_session_duration").(int)))

}
_, err := iamconn.UpdateRole(roleMaxDurationInput)
if err != nil {
if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes here:

  • This can be simplified and use the SDK provided constant with if isAWSErr(err, iam.ErrCodeNoSuchEntityException, "") {
  • The error message needs to be updated

@@ -158,6 +158,40 @@ func TestAccAWSIAMRole_force_detach_policies(t *testing.T) {
})
}

func TestAccAWSIAMRole_testMaxSessionDuration(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop the second test before MaxSessionDuration

@@ -261,6 +295,39 @@ func testAccAddAwsIAMRolePolicy(n string) resource.TestCheckFunc {
}
}

func testMaxSessionDuration(rName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature here should be:

func testAccCheckIAMRoleConfig_MaxSessionDuration(rName string, maxSessionDuration int) string {

Then accept the parameter in the HCL configuration:

  max_session_duration = %d

So we can remove the other two test configurations.

@@ -49,6 +49,8 @@ The following arguments are supported:
See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
* `description` - (Optional) The description of the role.

* `max_session_duration` - (Optional) Max duration of a federated role
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably note that the duration is in seconds and defaults to 3600. The SDK documentation sums it up pretty well:

The maximum session duration (in seconds) that you want to set for the specified role. If you do not specify a value for this setting, the default maximum of one hour is applied. This setting can have a value from 1 hour to 12 hours.

Optional: true,
Default: 3600,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(int64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, this should be updated to ValidateFunc: validation.IntBetween(3600, 43200)

resource "aws_iam_role" "role" {
name = "test-role-%s"
path = "/"
max_session_duration = 46800
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the tests are updated, this should test the hard edges of the validation at 43201 and 3599.

),
},
{
Config: testMaxSessionDuration_too_long(rName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We expect these configurations to fail, which can be accomplished with:

{
  Config:      testAccCheckIAMRoleConfig_MaxSessionDuration(rName, 43201),
  ExpectError: regexp.MustCompile(`error message here`),
},

@jonotto
Copy link

jonotto commented Apr 2, 2018

This will also fix duplicate enhancement request #3969

@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Apr 4, 2018
@stephencoe
Copy link
Contributor Author

@bflad thanks for the feedback, sorry its not been updated sooner :)

@ghost ghost added the size/M Managed by automation to categorize the size of a PR. label Apr 4, 2018
@@ -137,6 +145,10 @@ func resourceAwsIamRoleCreate(d *schema.ResourceData, meta interface{}) error {
request.Description = aws.String(v.(string))
}

if v, ok := d.GetOk("max_session_duration"); ok {
request.MaxSessionDuration = aws.Int64(v.(int64))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== RUN   TestAccAWSIAMRole_MaxSessionDuration
panic: interface conversion: interface {} is int, not int64

goroutine 227 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsIamRoleCreate(0xc4202c3810, 0x3542900, 0xc4208a0500, 0xc4202c3810, 0x0)
	/Users/bflad/go/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_iam_role.go:149 +0x6da

I will fix this on merge.

{
Config: testAccCheckIAMRoleConfig_MaxSessionDuration(rName, 3700),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists("aws_iam_role.test", &conf),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- FAIL: TestAccAWSIAMRole_MaxSessionDuration (6.39s)
	testing.go:518: Step 0 error: Check failed: Check 1/2 error: Not found: aws_iam_role.test

The resource is named role in the test configuration. I will fix this on merge.

@bflad bflad added this to the v1.14.0 milestone Apr 4, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed up the panic and acceptance testing in my branch which I'll use to merge keeping your commits. Thanks for the contribution! 🚀

make testacc TEST=./aws TESTARGS='-run=TestAccAWSIAMRole'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSIAMRole -timeout 120m
=== RUN   TestAccAWSIAMRolePolicy_importBasic
--- PASS: TestAccAWSIAMRolePolicy_importBasic (10.90s)
=== RUN   TestAccAWSIAMRole_importBasic
--- PASS: TestAccAWSIAMRole_importBasic (8.02s)
=== RUN   TestAccAWSIAMRolePolicy_basic
--- PASS: TestAccAWSIAMRolePolicy_basic (15.84s)
=== RUN   TestAccAWSIAMRolePolicy_namePrefix
--- PASS: TestAccAWSIAMRolePolicy_namePrefix (8.09s)
=== RUN   TestAccAWSIAMRolePolicy_generatedName
--- PASS: TestAccAWSIAMRolePolicy_generatedName (8.36s)
=== RUN   TestAccAWSIAMRolePolicy_invalidJSON
--- PASS: TestAccAWSIAMRolePolicy_invalidJSON (1.24s)
=== RUN   TestAccAWSIAMRole_basic
--- PASS: TestAccAWSIAMRole_basic (8.96s)
=== RUN   TestAccAWSIAMRole_basicWithDescription
--- PASS: TestAccAWSIAMRole_basicWithDescription (19.16s)
=== RUN   TestAccAWSIAMRole_namePrefix
--- PASS: TestAccAWSIAMRole_namePrefix (7.15s)
=== RUN   TestAccAWSIAMRole_testNameChange
--- PASS: TestAccAWSIAMRole_testNameChange (14.99s)
=== RUN   TestAccAWSIAMRole_badJSON
--- PASS: TestAccAWSIAMRole_badJSON (1.55s)
=== RUN   TestAccAWSIAMRole_force_detach_policies
--- PASS: TestAccAWSIAMRole_force_detach_policies (7.85s)
=== RUN   TestAccAWSIAMRole_MaxSessionDuration
--- PASS: TestAccAWSIAMRole_MaxSessionDuration (13.85s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	126.014s

@bflad bflad merged commit 06c4a51 into hashicorp:master Apr 4, 2018
bflad added a commit that referenced this pull request Apr 4, 2018
@bflad
Copy link
Contributor

bflad commented Apr 6, 2018

This has been released in version 1.14.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 6, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add MaxSessionDuration to iam_role
4 participants