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

r/ssm_parameter: allow adding tags to a parameter if overwrite is specified #18640

Merged
merged 2 commits into from
Apr 8, 2021

Conversation

anGie44
Copy link
Contributor

@anGie44 anGie44 commented Apr 7, 2021

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #18550

Description

  • Tags w/Overwrite handling added to allow for both arguments; in the case of overwrite present in a configuration, we pass the value into the PutParameter request, but if tags is also present in a configuration, we use the SSM UpdateTags method to modify the resource after creation. if overwrite is not present, however, can set the Tags field in the PutParameter request without issue.

  • Previously, handling of the argument overwrite was handled internally in the resource code with the following, however it did not entirely respect a user configuration when no value was provided.

func shouldUpdateSsmParameter(d *schema.ResourceData) bool {
	// If the user has specified a preference, return their preference
	if value, ok := d.GetOkExists("overwrite"); ok {
		return value.(bool)
	}

	// Since the user has not specified a preference, obey lifecycle rules
	// if it is not a new resource, otherwise overwrite should be set to false.
	return !d.IsNewResource()
}

Output from acceptance testing:

--- PASS: TestAccAWSSSMParameter_fullPath (165.00s)
--- PASS: TestAccAWSSSMParameter_overwriteWithTags (165.01s)
--- PASS: TestAccAWSSSMParameter_secure (165.04s)
--- PASS: TestAccAWSSSMParameter_disappears (183.90s)
--- PASS: TestAccAWSSSMParameter_noOverwriteWithTags (192.69s)
--- PASS: TestAccAWSSSMParameter_DataType_AwsEc2Image (204.60s)
--- PASS: TestAccAWSSSMParameter_basic (226.48s)
--- PASS: TestAccAWSSSMParameter_secure_with_key (244.31s)
--- PASS: TestAccAWSSSMParameter_changeNameForcesNew (268.60s)
--- PASS: TestAccAWSSSMParameter_updateType (270.31s)
--- PASS: TestAccAWSSSMParameter_secure_keyUpdate (278.30s)
--- PASS: TestAccAWSSSMParameter_overwrite (279.19s)
--- PASS: TestAccAWSSSMParameter_updateDescription (279.19s)
--- PASS: TestAccAWSSSMParameter_updateToOverwriteWithTags (279.73s)
--- PASS: TestAccAWSSSMParameter_tags (310.08s)
--- PASS: TestAccAWSSSMParameter_Tier_IntelligentTieringToStandard (310.36s)
--- PASS: TestAccAWSSSMParameter_Tier (311.24s)
--- PASS: TestAccAWSSSMParameter_Tier_IntelligentTieringToAdvanced (313.25s)

@ghost ghost added size/L Managed by automation to categorize the size of a PR. service/ssm Issues and PRs that pertain to the ssm service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Apr 7, 2021
@anGie44 anGie44 added bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. labels Apr 7, 2021
@anGie44 anGie44 force-pushed the b-ssm-parameter-tags-with-overwrite branch from 47fe036 to 3108b4b Compare April 7, 2021 23:26
@ghost ghost added size/XL 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 7, 2021
@anGie44 anGie44 marked this pull request as ready for review April 8, 2021 00:06
@anGie44 anGie44 requested a review from a team as a code owner April 8, 2021 00:06
anGie44 added a commit that referenced this pull request Apr 8, 2021
@bflad bflad self-assigned this Apr 8, 2021
@bflad bflad added this to the v3.36.0 milestone Apr 8, 2021
@anGie44 anGie44 force-pushed the b-ssm-parameter-tags-with-overwrite branch from 38685d9 to 1ca7758 Compare April 8, 2021 19:06
@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Apr 8, 2021
@anGie44 anGie44 force-pushed the b-ssm-parameter-tags-with-overwrite branch 2 times, most recently from 551c73f to bb2ec8d Compare April 8, 2021 20:51
@anGie44 anGie44 force-pushed the b-ssm-parameter-tags-with-overwrite branch from bb2ec8d to 4548347 Compare April 8, 2021 20:54

log.Printf("[INFO] Deleting SSM Parameter: %s", d.Id())
if d.HasChange("data_type") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

..turns out you can't actually change a "data_type" tho (i tried going from image -> text, but not vice versa yet)

Error: error updating SSM parameter (tf-acc-test-1338304779148665738): ValidationException: You can’t change a parameter’s data type.
        	status code: 400, request id: d166482e-29ef-4f9c-822d-6c8a0f0f99ca

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.

Looks good to me, thank you for the fix and the additional testing 🚀

Output from acceptance testing in AWS Commercial:

--- PASS: TestAccAWSSSMParameter_disappears (31.88s)
--- PASS: TestAccAWSSSMParameter_basic (36.73s)
--- PASS: TestAccAWSSSMParameter_fullPath (36.73s)
--- PASS: TestAccAWSSSMParameter_secure (36.92s)
--- PASS: TestAccAWSSSMParameter_noOverwriteWithTags (38.54s)
--- PASS: TestAccAWSSSMParameter_overwriteWithTags (39.69s)
--- PASS: TestAccAWSSSMParameter_DataType_AwsEc2Image (40.38s)
--- PASS: TestAccAWSSSMParameter_secure_with_key (41.69s)
--- PASS: TestAccAWSSSMParameter_updateType (50.25s)
--- PASS: TestAccAWSSSMParameter_updateDescription (50.27s)
--- PASS: TestAccAWSSSMParameter_changeNameForcesNew (51.27s)
--- PASS: TestAccAWSSSMParameter_updateToOverwriteWithTags (51.48s)
--- PASS: TestAccAWSSSMParameter_overwrite (51.52s)
--- PASS: TestAccAWSSSMParameter_secure_keyUpdate (58.47s)
--- PASS: TestAccAWSSSMParameter_Tier_IntelligentTieringToStandard (63.90s)
--- PASS: TestAccAWSSSMParameter_tags (64.67s)
--- PASS: TestAccAWSSSMParameter_Tier (64.86s)
--- PASS: TestAccAWSSSMParameter_Tier_IntelligentTieringToAdvanced (66.90s)

Output from acceptance testing in AWS GovCloud (US):

--- PASS: TestAccAWSSSMParameter_disappears (25.89s)
--- PASS: TestAccAWSSSMParameter_secure (35.59s)
--- PASS: TestAccAWSSSMParameter_fullPath (35.60s)
--- PASS: TestAccAWSSSMParameter_basic (35.67s)
--- PASS: TestAccAWSSSMParameter_noOverwriteWithTags (35.73s)
--- PASS: TestAccAWSSSMParameter_overwriteWithTags (35.80s)
--- PASS: TestAccAWSSSMParameter_secure_with_key (39.31s)
--- PASS: TestAccAWSSSMParameter_DataType_AwsEc2Image (39.65s)
--- PASS: TestAccAWSSSMParameter_updateType (47.83s)
--- PASS: TestAccAWSSSMParameter_updateDescription (47.88s)
--- PASS: TestAccAWSSSMParameter_overwrite (48.34s)
--- PASS: TestAccAWSSSMParameter_updateToOverwriteWithTags (49.94s)
--- PASS: TestAccAWSSSMParameter_changeNameForcesNew (51.84s)
--- PASS: TestAccAWSSSMParameter_secure_keyUpdate (55.09s)
--- PASS: TestAccAWSSSMParameter_Tier (64.34s)
--- PASS: TestAccAWSSSMParameter_tags (65.55s)
--- PASS: TestAccAWSSSMParameter_Tier_IntelligentTieringToStandard (65.80s)
--- PASS: TestAccAWSSSMParameter_Tier_IntelligentTieringToAdvanced (68.56s)

@bflad bflad merged commit 973b00a into main Apr 8, 2021
@bflad bflad deleted the b-ssm-parameter-tags-with-overwrite branch April 8, 2021 23:20
@ghost
Copy link

ghost commented Apr 9, 2021

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented May 9, 2021

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 as resolved and limited conversation to collaborators May 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/ssm Issues and PRs that pertain to the ssm service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new AWS provider 3.35 can't set aws_ssm_parameter with tags and overwrite
2 participants