Open rene84 opened 1 year ago
Please find the most basic set of templates and shell scripts to create, move and clean-up a LogGroup between two stacks. Assumes account and region is included in the profile that is passed as an argument to the script. Next step is to do this in Typescript.
As an aside: it proves that the resource doesn't have to be defined in exactly the same way in the target template as in the source template, because I modified the value for DeletionPolicy
from Retain to Delete
1-setup.sh -> create a source and target stack. Update source stack by removing a resource that then becomes orphaned 2-move.sh -> import the orphaned resource in target stack 3-cleanup.sh -> delete both stacks
Let's look at potential implementations per step:
aws cloudformation get-template-summary
but honestly we can hard-code this as well because it will be a rather static map of resource type to attributeaws configservice list-discovered-resources
? I guess it's not so nice to make using Config a prerequisite to use this feature and there might be situations where the resource is too new to have been picked up by Config. aws resourcegroupstaggingapi get-resources --resource-arn-list
will return the resource if it exists. This requires us to calcuate the ARN based on the resourceIdentifier value which may not be trivialaws resourcegroupstaggingapi get-resources --resource-type-filters
then iterate through that to match on the resourceIdentifier key and value. Doublecheck if this is also true for resources without tags (cloudformation adds tags as well to most resources) edit: checked and the tags API does NOT return resources that never had tags so this also doesnt work(6) continue normal flow
Added PoC code to implement step 2-move.sh in Typescript.
1-setup.sh -> create a source and target stack. Update source stack by removing a resource that then becomes orphaned
ts-node 2-move.ts
Subject of the issue
I would like to easily refactor stacks, especially move resources from one stack to another that cannot be deleted (either because they contain data or because it will cause downtime)
Expected behavior
One possible implementation would be the following when executing an update-stacks task:
Since this behavior will greatly slow down the deployment of the stack, it should be enabled with a flag. e.g.
This will allow me, as per the example, to simply move a resource from the
tables.yml
to thebastion.yml
assuming theDeletionPolicy
is set toRetain
. Having the flagImportExistingResources
, will only slow down the actual execution, but won't have side-effects if there is nothing to import. After having executed it, one would remove the flag from the task.A challenge will be that such a change may not create new resources in the same action as importing existing resources as per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html#resource-import-considerations