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

resource/aws_iam_user_policy: Add support to import state #3198

Merged
merged 1 commit into from
Feb 27, 2018

Conversation

erran
Copy link
Contributor

@erran erran commented Jan 30, 2018

Description

Add support to import state for inline IAM user policies using terraform import <USER>:<POLICY_NAME>.

Context

Replaces #2931 which attempted to solve this and adding support to import aws_iam_user_policy via aws_iam_user dynamically.

The previous PR also had conflicts after #3031.

Acceptance Tests

r/aws_iam_user_policy acceptance tests:

make testacc TESTARGS="-run 'TestAccAWSIAMUserPolicy_import*'"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -run 'TestAccAWSIAMUserPolicy_import*' -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSIAMUserPolicy_importBasic
--- PASS: TestAccAWSIAMUserPolicy_importBasic (30.10s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       30.619s

Add support to import state for inline IAM user policies using
`terraform import <USER>:<POLICY_NAME>`.
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 30, 2018
@radeksimko radeksimko added service/iam Issues and PRs that pertain to the iam service. enhancement Requests to existing resources that expand the functionality or scope. labels Jan 30, 2018
@bflad bflad added this to the v1.11.0 milestone Feb 27, 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.

LGTM! Thanks for this contribution @erran! 🚀

make testacc TEST=./aws TESTARGS='-run=TestAccAWSIAMUserPolicy_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSIAMUserPolicy_ -timeout 120m
=== RUN   TestAccAWSIAMUserPolicy_importBasic
--- PASS: TestAccAWSIAMUserPolicy_importBasic (9.81s)
=== RUN   TestAccAWSIAMUserPolicy_basic
--- PASS: TestAccAWSIAMUserPolicy_basic (12.61s)
=== RUN   TestAccAWSIAMUserPolicy_namePrefix
--- PASS: TestAccAWSIAMUserPolicy_namePrefix (14.24s)
=== RUN   TestAccAWSIAMUserPolicy_generatedName
--- PASS: TestAccAWSIAMUserPolicy_generatedName (12.62s)
=== RUN   TestAccAWSIAMUserPolicy_multiplePolicies
--- PASS: TestAccAWSIAMUserPolicy_multiplePolicies (24.98s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	74.309s


func TestAccAWSIAMUserPolicy_importBasic(t *testing.T) {
suffix := randomString(10)
resourceName := fmt.Sprintf("aws_iam_user_policy.foo_%s", suffix)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick for the future: each of the acceptance tests are self-contained configurations, so we do not need to randomize the Terraform resource names (only the names in AWS) 👍

CheckDestroy: testAccCheckIAMUserPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAwsIamUserPolicyConfig(suffix),
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick for the future: you can use an existing configuration for import testing

@@ -106,13 +116,22 @@ func resourceAwsIamUserPolicyRead(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return err
}
return d.Set("policy", policy)
if err := d.Set("policy", policy); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick for the future: we do not need to perform error handling of d.Set() for simple string attributes 👍

@bflad bflad merged commit 20ae375 into hashicorp:master Feb 27, 2018
bflad added a commit that referenced this pull request Feb 27, 2018
@erran erran deleted the r-iam-user-policy-import branch February 27, 2018 16:51
@bflad
Copy link
Contributor

bflad commented Feb 27, 2018

FYI I will add the documentation to website/docs/r/iam_user_policy.html.markdown too

@erran
Copy link
Contributor Author

erran commented Feb 27, 2018

@bflad thanks for getting this merged. Will keep your suggestions in mind for future changes. 😄

@erran
Copy link
Contributor Author

erran commented Feb 27, 2018

FYI I will add the documentation to website/docs/r/iam_user_policy.html.markdown too

Awesome, was just going to ask whether I should add those. 😅

bflad added a commit that referenced this pull request Feb 27, 2018
@bflad
Copy link
Contributor

bflad commented Mar 9, 2018

This has been released in version 1.11.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 7, 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 7, 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/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants