aws-cloudformation / aws-cloudformation/aws-cloudformation-resource-providers-awsutilities-commandrunner

New functionality: add Teardown parameter

Open
#36 1 comment 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
81
Forks
20
PR merge metrics
No merged PRs in 30d

Description

Right now we can do anything in the bash command (``Command`` parameter) - we can fetch values from e.g. RDS, we can use AWS CLI to get some information, initialise databases, make external calls, etc. But we can also create new resources.

For instance Cloudformation does not support Storage Gateway (yet). So I am using CommandRunner to register Storage Gateway programmatically via AWS CLI, e.g.:

```yaml
StorageGatewayActivator:
Type: AWSUtility::CloudFormation::CommandRunner
Properties:
SubnetId: !Ref SubnetId
Role: !Ref ActivatorInstanceProfile
LogGroup: !Ref ActivatorLogGroup
Command: !Sub |
curl -s "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
alias aws="/usr/local/bin/aws"
key=`curl "http://${StorageGateway.PrivateIp}/?gatewayType=FILE_S3&activationRegion=${AWS::Region}&no_redirect"`
gw=`aws --region ${AWS::Region} storagegateway activate-gateway \
--activation-key $key \
--gateway-type FILE_S3 \
--gateway-name ${AWS::StackName} \
--gateway-timezone GMT+1:00 \
--gateway-region ${AWS::Region} | jq -r .GatewayARN`
sleep 30
diskid=`aws --region ${AWS::Region} storagegateway list-local-disks --gateway-arn $gw | jq -r .Disks[0].DiskId`
aws --region ${AWS::Region} storagegateway add-cache \
--gateway-arn $gw \
--disk-ids $diskid | jq -r .GatewayARN > /command-output.txt
aws --region ${AWS::Region} storagegateway update-gateway-information \
--gateway-arn $gw \
--cloud-watch-log-group-arn ${StorageGWLogGroup.Arn} \
--gateway-name ${AWS::StackName}
aws --region ${AWS::Region} storagegateway create-nfs-file-share \
--client-token token-$RANDOM \
--gateway-arn $gw \
--role ${StorageGatewayRole.Arn} \
--location-arn ${BucketArn} \
--client-list ${NfsClientIp} \
--squash NoSquash \
--vpc-endpoint-dns-name ${S3VpcEndpointDns} \
--file-share-name ${AWS::StackName} \
--bucket-region ${AWS::Region}
DependsOn: StorageGatewayEC2
```

Now suppose I want to remove the stack. The only thing Cloudformation will remove is the Output value from Parameter Store. But it won't deactivate Storage gateway, nor will it detach the nfs file share.

So what we can do, is along with the ``Command`` parameter we can introduce another parameter e.g. ``TeardownCommand`` where we can add some teardown logic (bash script) and start a new CommandRunner stack (inside [DeleteHandler.java](https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-awsutilities-commandrunner/blob/master/src/main/java/software/awsutility/cloudformation/commandrunner/DeleteHandler.java)).

Contributor guide

Open the contributing guide

Research direction

Start with DeleteHandler.java and inspect the deletion path for the existing CommandRunner resource. Add support for a TeardownCommand bash script that runs during stack removal; done means the teardown logic can clean up resources created by Command.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, java
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.