0
votes

I've made a CodePipeline pipline CloudFormation template and deployed it as a stack. I'd like to add an action to this existing pipeline via another CloudFormation stack.

From the documentation I can only see pipeline resources which would allow me to create a whole new stack, not edit an existing one by providing an ARN or something similar. There are also no granular resources that provide support for CodePipeline functionality such as actions. See URL below:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codepipeline-pipeline.html

Does anyone know how I can achieve this? By the looks of it I'd say I have to update the template for the pipeline, adding the new action. Assuming this is the only way, how could achieve this from another CloudFormation stack?

So a template would be configured to add a new action in the pipeline template, and then trigger an update of the pipeline stack. I'm guessing I'd have to use a CloudFormation macro and keep the pipeline template stored in s3. I'd then take the template out of s3, add the action, save the change and then what? I've also considered how I might use nested stacks or the Import macro.

Thanks for any help!

1
You can't do this directly. Could do this using custom resource in cfn though. But this would only lead to a drift of the orignal CP stack, if you were to manipulate CP from custom resource. ALternatively, you could develop entire CP resource as custom resource. And then you can implement any behavior you desire on its updates or deletes.Marcin
Other possibility is to use other CP to deploy your first CP. CP can deploy to CFN. So any change in your source code repo of the first CP template, would trigger other CP to deploy the changes to CFN.Marcin
In your second suggestion, how would I trigger the other CP to update the first CP? Thanks for your time. I.e. how would I update the source of my first CP via another CFN template/stack?user13581257
Lets assume we have two CPs - main (mCP) and target (tCP). mCP will deploy a CFN template which creates tCP. For this you store a CFN template of tCP in, e.g. a CC repo. Any change to the template of tCP would be pushed to the CC repo. The change would trigger mCP which would execute Deploy Action with provider of CloudFormation. This action could be set to REPLACE_ON_FAILURE which would create, update or replace the tCP stack. This way you could automate deployments and updates to tCP.Marcin
See answer. Thank you!user13581257

1 Answers

1
votes

@Marcin inspired me to this solutions. Thanks :)

Essentially I did this:

First I created a "Change" pipeline that took the stack template modified during the build stage, that I originally wanted to deploy across multiple stacks in a deploy action, and wrote it out to the path within an s3 bucket.

Second I created a "Deploy" pipeline that used the s3 path pointing to the output of the "Change" pipeline. This pipeline contains a deploy action that uses a SourceArtifact of the outputted template. This is essentially the deploy action I wanted in the "Change" pipeline.

I have now created a CFN template for the "Deploy" pipeline, allowing me to create any number of "Deploy" pipelines pointing to different stacks. When the "Change" pipeline is triggered it's output triggers all the "Deploy" pipelines. My approval and testing process goes into the "Change" pipeline to avoid spam and I can roll back no problem.