-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Conversation
Add support to import state for inline IAM user policies using `terraform import <USER>:<POLICY_NAME>`.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 👍
FYI I will add the documentation to |
@bflad thanks for getting this merged. Will keep your suggestions in mind for future changes. 😄 |
Awesome, was just going to ask whether I should add those. 😅 |
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. |
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! |
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
viaaws_iam_user
dynamically.The previous PR also had conflicts after #3031.
Acceptance Tests
r/aws_iam_user_policy
acceptance tests: