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

feat(cloud-formation): Preserve existing tags #1379

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions magenta-lib/src/main/scala/magenta/tasks/ChangeSetTasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CreateChangeSetTask(
)
)

val (stackName, changeSetType, existingParameters) =
val (stackName, changeSetType, existingParameters, currentTags) =
stackLookup.lookup(resources.reporter, cfnClient)

val template = processTemplate(
Expand Down Expand Up @@ -106,12 +106,15 @@ class CreateChangeSetTask(
resources.reporter.verbose(s"Using execution role $role")
)

val mergedTags = currentTags ++ stackTags
resources.reporter.info("Tags: " + mergedTags.mkString(", "))

CloudFormation.createChangeSet(
resources.reporter,
stackLookup.changeSetName,
changeSetType,
stackName,
Some(stackTags),
Some(mergedTags),
template,
awsParameters,
maybeExecutionRole,
Expand Down Expand Up @@ -162,7 +165,7 @@ class CheckChangeSetCreatedTask(
): Unit = {
check(resources.reporter, stopFlag) {
CloudFormation.withCfnClient(keyRing, region, resources) { cfnClient =>
val (stackName, changeSetType, _) =
val (stackName, changeSetType, _, _) =
stackLookup.lookup(resources.reporter, cfnClient)
val changeSetName = stackLookup.changeSetName
val changeSet = CloudFormation.describeChangeSetByName(
Expand Down Expand Up @@ -240,7 +243,8 @@ class ExecuteChangeSetTask(
stopFlag: => Boolean
): Unit = {
CloudFormation.withCfnClient(keyRing, region, resources) { cfnClient =>
val (stackName, _, _) = stackLookup.lookup(resources.reporter, cfnClient)
val (stackName, _, _, _) =
stackLookup.lookup(resources.reporter, cfnClient)
val changeSetName = stackLookup.changeSetName

val changeSet = CloudFormation.describeChangeSetByName(
Expand Down Expand Up @@ -306,7 +310,8 @@ class DeleteChangeSetTask(
stopFlag: => Boolean
): Unit = {
CloudFormation.withCfnClient(keyRing, region, resources) { cfnClient =>
val (stackName, _, _) = stackLookup.lookup(resources.reporter, cfnClient)
val (stackName, _, _, _) =
stackLookup.lookup(resources.reporter, cfnClient)
val changeSetName = stackLookup.changeSetName

CloudFormation.deleteChangeSet(stackName, changeSetName, cfnClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class SetStackPolicyTask(
stopFlag: => Boolean
): Unit = {
CloudFormation.withCfnClient(keyRing, region, resources) { cfnClient =>
val (stackName, changeSetType, _) =
val (stackName, changeSetType, _, _) =
stackLookup.lookup(resources.reporter, cfnClient)
val policyDoc =
toPolicyDoc(stackPolicy, () => accountResourceTypes(cfnClient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CloudFormationStackMetadata(
def lookup(
reporter: DeployReporter,
cfnClient: CloudFormationClient
): (String, ChangeSetType, List[ExistingParameter]) = {
): (String, ChangeSetType, List[ExistingParameter], Map[String, String]) = {
val existingStack = strategy match {
case LookupByName(name) => CloudFormation.describeStack(name, cfnClient)
case LookupByTags(tags) =>
Expand All @@ -123,7 +123,12 @@ class CloudFormationStackMetadata(
reporter
)

(stackName, changeSetType, stackParameters)
val currentTags: Map[String, String] = existingStack match {
case Some(stack) => stack.tags().asScala.map(t => t.key -> t.value).toMap
case _ => Map.empty
}

(stackName, changeSetType, stackParameters, currentTags)
}
}

Expand Down