cto-a / private-isu-ops

ISUCON研修運営用
0 stars 0 forks source link

fix RunTaskCommandInput for using fargate spot #77

Closed yaggytter closed 3 months ago

harukin721 commented 3 months ago

plan 結果

% terraform plan
╷
│ Error: Insufficient auto_scaling_group_provider blocks
│ 
│   on ecs.tf line 313, in resource "aws_ecs_capacity_provider" "fargate_spot":
│  313: resource "aws_ecs_capacity_provider" "fargate_spot" {
│ 
│ At least 1 "auto_scaling_group_provider" blocks are required.
╵
╷
│ Error: Insufficient auto_scaling_group_provider blocks
│ 
│   on ecs.tf line 317, in resource "aws_ecs_capacity_provider" "fargate":
│  317: resource "aws_ecs_capacity_provider" "fargate" {
│ 
│ At least 1 "auto_scaling_group_provider" blocks are required.
╵
╷
│ Error: Unsupported argument
│ 
│   on ecs.tf line 325, in resource "aws_ecs_cluster" "benchmarker_ecs_cluster":
│  325:   capacity_providers = [
│ 
│ An argument named "capacity_providers" is not expected here.
╵
╷
│ Error: Unsupported block type
│ 
│   on ecs.tf line 330, in resource "aws_ecs_cluster" "benchmarker_ecs_cluster":
│  330:   default_capacity_provider_strategy {
│ 
│ Blocks of type "default_capacity_provider_strategy" are not expected here.
╵
harukin721 commented 3 months ago

👀 https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_capacity_provider

kesompochy commented 3 months ago
@PM-F5F005G0PQ ~/g/g/c/p/lambda_benchmarker_starter (usespot-1|✔) $ npm run build

> lambda_benchmarker_starter@1.0.0 build
> node build.mjs

> lambda_benchmarker_starter@1.0.0 postbuild
> zip -r index.zip index.mjs*

updating: index.mjs (deflated 84%)
updating: index.mjs.map (deflated 60%)
@PM-F5F005G0PQ ~/g/g/c/p/lambda_benchmarker_starter (usespot-1|✚2) $ cd terraform/
@PM-F5F005G0PQ ~/g/g/c/p/l/terraform (usespot-1|✚2) $ env AWS_PROFILE=ctoa2024 terraform plan
aws_sqs_queue.benchmark_queue: Refreshing state... [id=https://sqs.ap-northeast-1.amazonaws.com/009160051284/benchmark_queue]
aws_iam_role.lambda_role: Refreshing state... [id=benchmarker_starter_lambda_role]
aws_apigatewayv2_api.lambda_api: Refreshing state... [id=8ukqooeebg]
aws_apigatewayv2_stage.lambda_stage: Refreshing state... [id=$default]
aws_iam_role_policy_attachment.lambda_policy: Refreshing state... [id=benchmarker_starter_lambda_role-20240729152333366800000001]
aws_iam_role_policy.lambda_sqs_policy: Refreshing state... [id=benchmarker_starter_lambda_role:lambda_sqs_policy]
aws_lambda_function.benchmarker_starter: Refreshing state... [id=bemchmarker_starter]
aws_lambda_permission.api_gw: Refreshing state... [id=AllowExecutionFromAPIGateway]
aws_apigatewayv2_integration.lambda_integration: Refreshing state... [id=jnq12kn]
aws_apigatewayv2_route.lambda_route: Refreshing state... [id=jgw2fgp]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_lambda_function.benchmarker_starter will be updated in-place
  ~ resource "aws_lambda_function" "benchmarker_starter" {
        id                             = "bemchmarker_starter"
      ~ last_modified                  = "2024-07-31T06:57:01.000+0000" -> (known after apply)
      ~ source_code_hash               = "JkdjadD0l1kPYKtCnlU3kdu5oyYIe7ITlfOqfV/EUfw=" -> "5gOGOnilR8PwxYjJE1KbzdjlVbMUGH3D936CmiZRlt0="
        tags                           = {}
        # (27 unchanged attributes hidden)

        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
@PM-F5F005G0PQ ~/g/g/c/p/l/terraform (usespot-1|✚2) $ env AWS_PROFILE=ctoa2024 terraform apply
aws_apigatewayv2_api.lambda_api: Refreshing state... [id=8ukqooeebg]
aws_iam_role.lambda_role: Refreshing state... [id=benchmarker_starter_lambda_role]
aws_sqs_queue.benchmark_queue: Refreshing state... [id=https://sqs.ap-northeast-1.amazonaws.com/009160051284/benchmark_queue]
aws_apigatewayv2_stage.lambda_stage: Refreshing state... [id=$default]
aws_iam_role_policy_attachment.lambda_policy: Refreshing state... [id=benchmarker_starter_lambda_role-20240729152333366800000001]
aws_iam_role_policy.lambda_sqs_policy: Refreshing state... [id=benchmarker_starter_lambda_role:lambda_sqs_policy]
aws_lambda_function.benchmarker_starter: Refreshing state... [id=bemchmarker_starter]
aws_lambda_permission.api_gw: Refreshing state... [id=AllowExecutionFromAPIGateway]
aws_apigatewayv2_integration.lambda_integration: Refreshing state... [id=jnq12kn]
aws_apigatewayv2_route.lambda_route: Refreshing state... [id=jgw2fgp]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_lambda_function.benchmarker_starter will be updated in-place
  ~ resource "aws_lambda_function" "benchmarker_starter" {
        id                             = "bemchmarker_starter"
      ~ last_modified                  = "2024-07-31T06:57:01.000+0000" -> (known after apply)
      ~ source_code_hash               = "JkdjadD0l1kPYKtCnlU3kdu5oyYIe7ITlfOqfV/EUfw=" -> "5gOGOnilR8PwxYjJE1KbzdjlVbMUGH3D936CmiZRlt0="
        tags                           = {}
        # (27 unchanged attributes hidden)

        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_lambda_function.benchmarker_starter: Modifying... [id=bemchmarker_starter]
aws_lambda_function.benchmarker_starter: Modifications complete after 5s [id=bemchmarker_starter]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

sqs_queue_arn = "arn:aws:sqs:ap-northeast-1:009160051284:benchmark_queue"
sqs_queue_url = "https://sqs.ap-northeast-1.amazonaws.com/009160051284/benchmark_queue"

ビルド、適用

yaggytter commented 3 months ago

Terraformでやると、Auto Scalingの設定も必須でしないといけないため、いったんCLIで設定しました。

aws ecs put-cluster-capacity-providers \
    --cluster benchmarker-ecs-cluster \
    --capacity-providers "FARGATE" "FARGATE_SPOT" \
    --default-capacity-provider-strategy capacityProvider=FARGATE_SPOT,weight=1,base=1
yaggytter commented 3 months ago

なので、このプルリクマージしちゃうと上記CLIを実行しないと動かなくなっちゃうので、全然べき等性なくなっちゃうため、このプルリクはマージしないでおきます!