Closed6

TerraformをAssumeRoleした状態で実行する

not75743not75743

元ファイル

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.9.0"
    }
  }
}

provider "aws" {
  region = "ap-northeast-1"
}

data "aws_caller_identity" "current" {}

現在のTerraformの実行権限確認

$ echo "data.aws_caller_identity.current" | terraform console
{
  "account_id" = "<AccountID>"
  "arn" = "arn:aws:iam::<AccountID>:user/<User>"
  "id" = "<AccountID>:"
  "user_id" = "<User>"
}
not75743not75743

AssumeRole設定追加

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.9.0"
    }
  }
}

provider "aws" {
  region = "ap-northeast-1"
+  assume_role {
+   role_arn     = "<Switch先RoleArn>"
+  }
}

data "aws_caller_identity" "current" {}
このスクラップは2023/07/28にクローズされました