Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TerraformでAWS環境を構築する際のハマりどころ

 TerraformでAWS環境を構築する際のハマりどころ

Yuki_Kurono

April 11, 2022
Tweet

More Decks by Yuki_Kurono

Other Decks in Technology

Transcript

  1. こんな感じでIAMのアタッチ # ロール resource "aws_iam_role" "lambda_role" { name = "kurono-policy-test-role"

    assume_role_policy = <<EOF ~略~ EOF } #ポリシー data "aws_iam_policy" "kurono-policy-test-policy" { arn = "arn:aws:iam::123456789:policy/kurono-policy-test-policy" } #ポリシーアタッチ resource "aws_iam_policy_attachment" "lambda-execute" { name = "lambda-execute" roles = [aws_iam_role.lambda_role.name] policy_arn = data.aws_iam_policy.kurono-policy-test-policy.arn }
  2. destroyの実行 root@kurono2:~/terraform# terraform destroy aws_iam_role.lambda_role: Refreshing state... [id=kurono-policy-test-role] aws_iam_policy_attachment.lambda-execute: Refreshing

    state... [id=lambda- execute] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: - destroy Terraform will perform the following actions: # aws_iam_policy_attachment.lambda-execute will be destroyed - resource "aws_iam_policy_attachment" "lambda-execute" { - groups = [] -> null - id = "lambda-execute" -> null - name = "lambda-execute" -> null - policy_arn = "arn:aws:iam::123456789:policy/kurono-policy-test- policy" -> null - roles = [ - "kurono-policy-test-role", - "kurono-policy-test-role-2", ] -> null - users = [] -> null }
  3. こんな感じでIAMのアタッチ # ロール resource "aws_iam_role" "lambda_role" { name = "kurono-policy-test-role"

    assume_role_policy = <<EOF ~略~ EOF } #ポリシー data "aws_iam_policy" "kurono-policy-test-policy" { arn = "arn:aws:iam::123456789:policy/kurono-policy-test-policy" } #ポリシーアタッチ resource "aws_iam_policy_attachment" "lambda-execute" { name = "lambda-execute" roles = [aws_iam_role.lambda_role.name] policy_arn = data.aws_iam_policy.kurono-policy-test-policy.arn }