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

Updating ResourcePolicy create and update handlers to support stack tags #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pns-amzn
Copy link
Contributor

Issue #, if available:

Description of changes:

  • Add support to create and update stack tags to ResourcePolicy (RP) CloudFormation stacks by updating the RP create and update handlers.
  • Update RP create and update handler tests.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines -116 to -143
static Set<Tag> convertResourcePolicyTagToOrganizationTag(final Set<software.amazon.organizations.resourcepolicy.Tag> tags) {
final Set<Tag> tagsToReturn = new HashSet<>();
if (tags == null) return tagsToReturn;
for (software.amazon.organizations.resourcepolicy.Tag inputTag : tags) {
Tag tag = Tag.builder()
.key(inputTag.getKey())
.value(inputTag.getValue())
.build();
tagsToReturn.add(tag);
}
return tagsToReturn;
}

static Set<String> getTagKeysToRemove(
Set<Tag> oldTags, Set<Tag> newTags) {
final Set<String> oldTagKeys = getTagKeySet(oldTags);
final Set<String> newTagKeys = getTagKeySet(newTags);
return Sets.difference(oldTagKeys, newTagKeys);
}

static Set<Tag> getTagsToAddOrUpdate(
Set<Tag> oldTags, Set<Tag> newTags) {
return Sets.difference(newTags, oldTags);
}

static Set<String> getTagKeySet(Set<Tag> oldTags) {
return oldTags.stream().map(Tag::key).collect(Collectors.toSet());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these to TagsHelper

@@ -86,10 +87,11 @@ public void handleRequest_NoTags_SimpleSuccess() {

@Test
public void handleRequest_WithTags_SimpleSuccess() {
final ResourceModel model = generateInitialResourceModel(false, TEST_RESOURCEPOLICY_CONTENT);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and few others had incorrectly set the hasTags to false, have updated them to true

Comment on lines -148 to -149
assertThat(TagTestResourceHelper.tagsEqual(response.getResourceModel().getTags(), TagTestResourceHelper.updatedTags));
assertThat(TagTestResourceHelper.correctTagsInTagAndUntagRequests(tagsToAddOrUpdate, tagKeysToRemove));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Were missing isTrue() and thus were never getting tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant