ばーろぐわにる

SIerからWEB系?インフラエンジニアにジョブチェンジした見習いの備忘録。投稿内容は私個人の意見であり、所属企業・部門見解を代表するものではありません。

terraform-aws-providerでECS Capacity Providerが削除できるようになったので検証してみた

最近全然ブログを書いていなかったのでリハビリブログです。

ECS Capacity Provider(CP)は必要なタスク数に応じて自動的にEC2 Auto Scaling Group(ASG)のスケールイン・アウトを行ってくれるので便利でしたが、一度作成すると削除できないというちょっと扱いづらい仕様がありました。少し前についに削除機能が追加され、aws-sdk-goも対応、そしてterraform-provider-awsもこれに対応しました。そこで今回はちゃんと削除されるかどうか検証してみます。削除機能はterraform-provider-awsの2.67.0以降で利用可能です。

github.com

CP作成

以前にCPとASGを作成するリポジトリを作っていたのでそれを利用してTerraformで作成します。

github.com

$ git clone https://github.com/waneal/terraform-test-ecs-capacity-auto-scaling.git
$ cd terraform-test-ecs-capacity-auto-scaling
$ terraform init
$ terraform apply

作成されていることを確認します。

$ aws ecs describe-capacity-providers --capacity-providers tmp-cluster-ec2
{
    "capacityProviders": [
        {
            "capacityProviderArn": "arn:aws:ecs:ap-northeast-1:XXXXXXXXXXX:capacity-provider/tmp-cluster-ec2",
            "name": "tmp-cluster-ec2",
            "status": "ACTIVE",
            "autoScalingGroupProvider": {
                "autoScalingGroupArn": "arn:aws:autoscaling:ap-northeast-1:XXXXXXXXXXX:autoScalingGroup:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXautoScalingGroupName/tmp-asg",
                "managedScaling": {
                    "status": "ENABLED",
                    "targetCapacity": 100,
                    "minimumScalingStepSize": 1,
                    "maximumScalingStepSize": 100
                },
                "managedTerminationProtection": "DISABLED"
            },
            "tags": []
        }
    ]
}

CP削除

$ terraform destroy

CPが削除されていることを確認します

$ aws ecs describe-capacity-providers --capacity-providers tmp-cluster-ec2
{
    "capacityProviders": [
        {
            "capacityProviderArn": "arn:aws:ecs:ap-northeast-1:XXXXXXXXXXX:capacity-provider/tmp-cluster-ec2",
            "name": "tmp-cluster-ec2",
            "status": "INACTIVE",
            "autoScalingGroupProvider": {
                "autoScalingGroupArn": "arn:aws:autoscaling:ap-northeast-1:XXXXXXXXXXX:autoScalingGroup:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXautoScalingGroupName/tmp-asg",
                "managedScaling": {
                    "status": "ENABLED",
                    "targetCapacity": 100,
                    "minimumScalingStepSize": 1,
                    "maximumScalingStepSize": 100
                },
                "managedTerminationProtection": "DISABLED"
            },
            "updateStatus": "DELETE_COMPLETE",
            "tags": []
        }
    ]
}

"updateStatus": "DELETE_COMPLETE" から正しく削除されていることがわかりました。