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

New functionality: add Teardown parameter #36

Open
maslick opened this issue Oct 13, 2021 · 1 comment
Open

New functionality: add Teardown parameter #36

maslick opened this issue Oct 13, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@maslick
Copy link

maslick commented Oct 13, 2021

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.:

  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).

@shantgup
Copy link
Collaborator

I will keep this as a FR.

@shantgup shantgup added the enhancement New feature or request label Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants