{"id":1111,"date":"2021-01-27T17:14:47","date_gmt":"2021-01-27T08:14:47","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/?p=1111"},"modified":"2021-01-28T14:51:06","modified_gmt":"2021-01-28T05:51:06","slug":"terraform_with_assume_role","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2021\/01\/27\/terraform_with_assume_role\/","title":{"rendered":"Terraform\u7528\u306eAWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u6a29\u9650\u7ba1\u7406\u3092\u3001\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u5f62\u5f0f\u3067\u6700\u9069\u5316\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"
\u897f\u85e4\u3067\u3059\u3002<\/p>\n
\u7686\u3055\u3093\u306fTerraform\u3092\u4f7f\u3063\u305fAWS\u30a4\u30f3\u30d5\u30e9\u306e\u5b9f\u88c5\u3092\u3059\u308b\u969b\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u53d6\u308a\u6271\u3044\u306f\u3069\u306e\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u304b\uff1f<\/p>\n
\u3068\u3044\u3046\u5f62\u304c\u591a\u3044\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n
\u3082\u3061\u308d\u3093\u696d\u52d9\u30e6\u30fc\u30b9\u3067\u3042\u308c\u3070\u3001IAM\u306b\u4ed8\u4e0e\u3057\u3066\u3044\u308b\u6a29\u9650\u306f\u5fc5\u8981\u6700\u4f4e\u9650\u306e\u3082\u306e\u306b\u7d5e\u3063\u3066\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u81ea\u4f53\u3082\u95a2\u4fc2\u8005\u306e\u307f\u306b\u914d\u5e03\u3059\u308b\u3067\u3057\u3087\u3046\u3057\u3001\u914d\u5e03\u3057\u305f\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u3082\u4e00\u5b9a\u671f\u9593\u7d4c\u904e\u3057\u305f\u3089\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u81ea\u4f53\u306e\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u904b\u7528\u306b\u5165\u308c\u308b\u3053\u3068\u3067\u3001\u4e0d\u6b63\u4f7f\u7528\u306e\u30ea\u30b9\u30af\u3092\u30d8\u30c3\u30b8\u3067\u304d\u307e\u3059\u3002<\/p>\n
\u30fb\u30fb\u30fb\u305d\u308c\u304c\u3001\u4f8b\u3048\u3070\u500b\u4eba\u4f7f\u7528\u306e\u6642\u306f\u3069\u3046\u3067\u3059\u304b\uff1f
\n\u696d\u52d9\u5229\u7528\u3058\u3083\u306a\u3044\u3057\u3001Terraform\u3067\u65b0\u3057\u3044\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u308b\u305f\u3073\u306b\u6a29\u9650\u4e0d\u8db3\u306b\u5f15\u3063\u639b\u304b\u308b\u306e\u304c\u3081\u3093\u3069\u304f\u3055\u3044\u306e\u3067\u3001Full\u6a29\u9650\u3092\u4e0e\u3048\u305f\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u3067\u3058\u3083\u3093\u3058\u3083\u3093\u691c\u8a3c\u30fb\u30fb\u30fb\u3057\u3066\u307e\u305b\u3093\u304b\uff1f<\/p>\n
\u3082\u3061\u308d\u3093\u500b\u4eba\u306e\u691c\u8a3c\u3092\u6a5f\u52d5\u7684\u306b\u884c\u3044\u305f\u3044\u3068\u304d\u306b\u3001\u7d30\u3084\u304b\u306a\u6a29\u9650\u8a2d\u5b9a\u306b\u82e6\u52b4\u3057\u3066\u3044\u3066\u306f\u672c\u672b\u8ee2\u5012\u3067\u3059\u3002
\n\u3057\u304b\u3057\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u304c\u4f55\u3089\u304b\u306e\u65b9\u6cd5\u3067\u6d41\u51fa\u3057\u3066\u597d\u304d\u52dd\u624b\u306bAWS\u3092\u4f7f\u308f\u308c\u308b\u306e\u3082\u6016\u3044\u3002\u305d\u3046\u3044\u3063\u305f\u4e0d\u5b89\u3082\u89e3\u6d88\u3057\u3066\u304a\u304d\u305f\u3044\u3082\u306e\u3002<\/p>\n
\u305d\u3053\u3067\u3001\u4eca\u56de\u306fTerraform\u306e\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3092\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3092\u7528\u3044\u305f\u5f62\u306b\u5dee\u3057\u66ff\u3048\u308b\u3053\u3068\u3067\u3001\u5c11\u3057\u3067\u3082\u5b89\u5fc3\u3092\u5f97\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
\u76ee\u6307\u3059\u4f53\u5236\u3068\u3057\u307e\u3057\u3066\u306f\u3001<\/p>\n
\u3068\u3044\u3046\u5f62\u306b\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n
\u6539\u5584\u306b\u5411\u3051\u3066\u307e\u305a\u306f\u3001\u5909\u66f4\u524d\u306eTerraform\u5b9f\u884c\u69cb\u6210\u304b\u3089\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3059\u3002
\n\u30b3\u30fc\u30c9\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u4e2d\u304c<\/p>\n
.\n\u251c\u2500\u2500 .env\n\u251c\u2500\u2500 Dockerfile\n\u251c\u2500\u2500 resources.tf\n\u251c\u2500\u2500 docker-compose.yml\n\u2514\u2500\u2500 main.tf\n<\/code><\/pre>\n\u306e\u3088\u3046\u306a\u69cb\u6210\u3060\u3068\u3057\u307e\u3059\u3002\uff08.gitignore<\/code>\u30d5\u30a1\u30a4\u30eb\u3084 .terraform\/<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306a\u3069\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u52d5\u304b\u3059\u4e0a\u3067\u5897\u3048\u3066\u304f\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u90e8\u306f\u5272\u611b\uff09<\/p>\nTerraform\u306e\u5b9f\u884c\u30d0\u30fc\u30b8\u30e7\u30f3\u3084\u3001AWS provider\u306e\u8a2d\u5b9a\u3092 main.tf<\/code>\u306b\u3066<\/p>\nprovider "aws" {\n region = "ap-northeast-1"\n}\n\nterraform {\n required_version = "0.14.5"\n backend "s3" {\n bucket = "<tfstate\u30d5\u30a1\u30a4\u30eb\u3092\u304a\u304fS3\u30d0\u30b1\u30c3\u30c8\u540d>"\n key = "<tfstate\u30d5\u30a1\u30a4\u30eb\u540d>"\n region = "ap-northeast-1"\n }\n required_providers {\n aws = {\n source = "hashicorp\/aws"\n version = "3.25.0"\n }\n }\n}<\/code><\/pre>\n\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3002resources.tf<\/code>\u30d5\u30a1\u30a4\u30eb\u306b\u5404\u7a2eAWS\u30ea\u30bd\u30fc\u30b9\u306e\u8a2d\u5b9a\u3092\u52a0\u3048\u3066\u3044\u304f\u5f62\u3067\u3059\u3002<\/p>\n.env \u30d5\u30a1\u30a4\u30eb\u306b\u306f\u4f7f\u7528\u3059\u308b\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u60c5\u5831\u3092<\/p>\n
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXX\nAWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nAWS_DEFAULT_REGION=ap-northeast-1<\/code><\/pre>\n\u306e\u3088\u3046\u306b\u8a18\u8f09\u3057\u3001docker-compose.yml\u306f<\/p>\n
version: "3"\nservices:\n terraform:\n build: .\n volumes:\n - .:\/app\/\n env_file: .env<\/code><\/pre>\n\u3068\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001
\ndocker-compose run terraform apply<\/code>
\n\u306e\u3088\u3046\u306b\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u5b9f\u884c\u3059\u308bPC\u5185\u306eAWS\u306eprofile\u3092\u6c5a\u3055\u305a\u306b\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u60c5\u5831\u3082\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30fc\u30c9\u30ea\u30dd\u30b8\u30c8\u30ea\u5185\u306b\u96c6\u7d04\u3055\u308c\u308b\u306e\u3067\u53d6\u308a\u6271\u3044\u306f\u3057\u3084\u3059\u3044\u69cb\u6210\u3068\u3057\u3066\u304a\u308a\u307e\u3057\u305f\u3002<\/p>\n
\u3057\u304b\u3057\u3001.env<\/code>\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u306f\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u60c5\u5831\u305d\u306e\u3082\u306e\u3067\u3059\u3002\u5f53\u7136\u3001\u81ea\u5206\u3057\u304b\u89e6\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u306f\u305a\u3067\u3059\u304c\u3001\u3053\u306e\u60c5\u5831\u304c\u4e0d\u6b63\u306b\u53d6\u5f97\u3055\u308c\u305f\u3068\u304d\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u6a29\u9650\u3092\u4f7f\u3063\u3066\u81ea\u7531\u306bAWS\u3092\u5229\u7528\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\u4eca\u56de\u306f\u3053\u306e env\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u304c\u4eee\u306b\u4e0d\u6b63\u306b\u53d6\u5f97\u3055\u308c\u3066\u3082\u3001\u5373\u5ea7\u306bAWS\u306e\u4e0d\u6b63\u5229\u7528\u306f\u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u6539\u5584\u3092\u52a0\u3048\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n
\u30b9\u30a4\u30c3\u30c1\u7528\u30ed\u30fc\u30eb\u306e\u4f5c\u6210<\/h2>\n
\u6539\u5584\u306e\u305f\u3081\u306b\u306f\u307e\u305a\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306b\u7d10\u3065\u3044\u3066\u3044\u305fIAM\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3059\u308b\u300c\u30b9\u30a4\u30c3\u30c1\u5148\u306e\u30ed\u30fc\u30eb\u300d\uff08assume role\u3055\u308c\u308b\u30ed\u30fc\u30eb\uff09\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n
IAM\u30ed\u30fc\u30eb\u306e\u4f5c\u6210\u753b\u9762\u3067\u300c\u5225\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u300d\u3092\u9078\u629e\u3057\u3066\u3001\u81ea\u8eab\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u306eID\u3092\u5165\u529b\u3057\u307e\u3059\u3002
\n\uff08\u81ea\u5206\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\u3082\u753b\u9762\u306f\u300c\u5225\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u300d\u2026\u3068\u3044\u3046\u306e\u304c\u5c11\u3057\u3084\u3084\u3053\u3057\u3044\u3067\u3059\u304c\u3002\u3002\u3002\uff09<\/p>\n
<\/p>\n
\u5165\u529b\u3057\u305f\u3089\u3001\u30a6\u30a3\u30b6\u30fc\u30c9\u306b\u6cbf\u3063\u3066\u6a29\u9650\u3092\u4ed8\u4e0e\u3059\u308b\u753b\u9762\u3067\u3059\u3002
\n\u3044\u304b\u306a\u308b\u69cb\u6210\u3067\u3082\u5f37\u3059\u304e\u308b\u6a29\u9650\u4ed8\u4e0e\u306f\u671b\u307e\u3057\u3044\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u6700\u5c0f\u6a29\u9650\u304b\u3089\u5f90\u3005\u306b\u62e1\u5927\u3057\u3066\u3044\u304f\u306e\u304c\u9244\u5247\u3067\u3059\u304c\u3001\u4eca\u56de\u306e\u6539\u5584\u3067\u306f\u3001\u307e\u305a\u306f\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u304c\u3061\u3083\u3093\u3068\u4f5c\u7528\u3059\u308b\u3053\u3068\u304c\u308f\u304b\u308b\u307e\u3067\u306f\u3001\u5f93\u6765\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306b\u7d10\u3065\u3044\u3066\u3044\u305fIAM\u30e6\u30fc\u30b6\u30fc\u306b\u3064\u3044\u3066\u3044\u305f\u6a29\u9650\u3092\u4ed8\u4e0e\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n
<\/p>\n
\u30bf\u30b0\u306e\u8a2d\u5b9a\u3084\u3001\u4f5c\u6210\u3059\u308b\u30ed\u30fc\u30eb\u540d\u3082\u6307\u5b9a\u3057\u3066\u4f5c\u6210\u5b8c\u4e86\u3067\u3059\u3002
\n\u4eca\u56de\u306f\u3001PowerUserAccess<\/code> \u306e\u6a29\u9650\u3092\u6301\u3063\u305fTerraformRole<\/code>\u3068\u3044\u3046IAM\u30ed\u30fc\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002
\n<\/p>\n\u30b9\u30a4\u30c3\u30c1\u7528\u30ed\u30fc\u30eb\u306e\u300c\u4fe1\u983c\u95a2\u4fc2\u300d\u306e\u8a2d\u5b9a<\/h2>\n
\u4f5c\u6210\u3055\u308c\u305fTerraformRole<\/code>\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002
\n\u73fe\u6642\u70b9\u306e\u307e\u307e\u3067\u306f\u3001\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u304b\u3089\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u304c\u3067\u304d\u308bIAM\u30ed\u30fc\u30eb\u304c\u3067\u304d\u305f\u3060\u3051\u3067\u3059\u3002
\n\u4ee5\u4e0b\u306e\u56f3\u306e\u300c\u4fe1\u983c\u3055\u308c\u305f\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u300d\u306e\u8a18\u8f09\u3092\u898b\u308b\u3068\u3001\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u306eID\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002
\n
\n\u300c\u4fe1\u983c\u95a2\u4fc2\u306e\u7de8\u96c6\u300d\u3092\u958b\u304f\u3068\u5206\u304b\u308b\u306e\u3067\u3059\u304c\u5177\u4f53\u7684\u306b\u306f
\narn:aws:iam::<\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8ID>:root<\/code>\u304b\u3089\u306ests:AssumeRole<\/code>\u3092\u8a31\u53ef\u3059\u308b\u69cb\u6210\u306b\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n\u305d\u308c\u3092\u4eca\u56de\u306e\u7528\u9014\u306b\u5408\u308f\u305b\u3066\u53b3\u5bc6\u306b\u8a2d\u5b9a\u3057\u306a\u304a\u3057\u307e\u3059\u3002
\n\u300c\u4fe1\u983c\u95a2\u4fc2\u306e\u7de8\u96c6\u300d\u3092\u958b\u3044\u3066\u30dd\u30ea\u30b7\u30fc\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n
{\n "Version": "2012-10-17",\n "Statement": [\n {\n "Effect": "Allow",\n "Principal": {\n "AWS": "arn:aws:iam::<\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8ID>:user\/<\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u5143\u306eIAM\u30e6\u30fc\u30b6\u30fc\u540d>"\n },\n "Action": "sts:AssumeRole"\n }\n ]\n}<\/code><\/pre>\nPrincial<\/code>\u90e8\u5206\u3067\u306e\u6307\u5b9a\u3057\u3066\u3044\u308bIAM\u30e6\u30fc\u30b6\u30fc\u306f\u3001\u5f93\u6765\u3088\u308a\u4f7f\u3063\u3066\u3044\u305f\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306eIAM\u30e6\u30fc\u30b6\u30fc\u3067\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u3053\u306e\u30ed\u30fc\u30eb\u306b\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\uff08AssumeRole\uff09\u304c\u884c\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
\n\u3053\u308c\u306b\u3088\u308a\u3001\u6307\u5b9a\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u306eIAM\u30e6\u30fc\u30b6\u30fc\u306e\u307f\u304c\u3053\u306e\u30ed\u30fc\u30eb\u306b\u30b9\u30a4\u30c3\u30c1\u3067\u304d\u308b\u3088\u3046\u306b\u5236\u9650\u3055\u308c\u307e\u3059\u3002<\/p>\n<\/p>\n
\u3055\u3089\u306b<\/p>\n
"Condition": {\n "IpAddress": {\n "aws:SourceIp": "xx.xx.xx.xx"\n }\n }<\/code><\/pre>\n\u3068\u3044\u3046\u3088\u3046\u306aIpAddress<\/code>\u3092\u4f7f\u3063\u305fCondition\u7bc0\u3092\u52a0\u3048\u308c\u3070\u3001\u30a2\u30af\u30bb\u30b9\u5143\u306eIP\u30a2\u30c9\u30ec\u30b9\u3082\u5236\u9650\u3067\u304d\u3001\u6700\u7d42\u7684\u306b\u300c\u6307\u5b9a\u306eIAM\u30e6\u30fc\u30b6\u30fc\u304b\u3064\u3001\u6307\u5b9a\u306eIP\u30a2\u30c9\u30ec\u30b9\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306e\u6642\u306e\u307f\u3001\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3067\u304d\u308b\u300d\u3068\u3044\u3046\u8a2d\u5b9a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<\/p>\n
IAM\u30e6\u30fc\u30b6\u30fc\u306e\u6a29\u9650\u8a2d\u5b9a<\/h2>\n
\u30b9\u30a4\u30c3\u30c1\u5148\u306e\u30ed\u30fc\u30eb\u306e\u8a2d\u5b9a\u306f\u7d42\u308f\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u5f93\u6765\u3088\u308a\u4f7f\u3063\u3066\u3044\u305f\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306eIAM\u30e6\u30fc\u30b6\u30fc\u306e\u8a2d\u5b9a\u3092\u8abf\u6574\u3057\u307e\u3057\u3087\u3046\u3002
\n\u5f93\u6765\u306f\u3053\u306eIAM\u30e6\u30fc\u30b6\u30fc\u306bTerraform\u3067\u5404\u7a2e\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u6a29\u9650\u304c\u3064\u3044\u3066\u3044\u305f\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3064\u3044\u3066\u3044\u305f\u6a29\u9650\u306f\u5168\u3066\u5916\u3057\u307e\u3057\u3087\u3046\u3002
\n\u305d\u3057\u3066\u3001\u6b21\u306e\u3088\u3046\u306a\u30dd\u30ea\u30b7\u30fc\u306e\u307f\u3092\u9069\u7528\u3057\u307e\u3059\u3002<\/p>\n
{\n "Version": "2012-10-17",\n "Statement": [\n {\n "Sid": "1",\n "Effect": "Allow",\n "Action": "sts:AssumeRole",\n "Resource": "arn:aws:iam::<\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8ID>:role\/<\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u5148\u306eIAM\u30ed\u30fc\u30eb\u540d>"\n }\n ]\n}<\/code><\/pre>\n\u6b21\u306e\u3088\u3046\u306a\u5177\u5408\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306eIAM\u30e6\u30fc\u30b6\u30fc\u306b\u306fAssumeRole\u3092\u884c\u3046\u6a29\u9650\u3057\u304b\u3064\u3044\u3066\u306a\u3044\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n
\u4ee5\u4e0a\u3067IAM\u306e\u8a2d\u5b9a\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n
Terraform\u5074\u306e\u8a2d\u5b9a<\/h2>\n
\u4f7f\u7528\u3059\u308bIAM\u30e6\u30fc\u30b6\u30fc\u3001IAM\u30ed\u30fc\u30eb\u306e\u8a2d\u5b9a\u304c\u3067\u304d\u305f\u3089\u6700\u5f8c\u306f\u3001Terraform\u3067\u305d\u308c\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n
\u5177\u4f53\u7684\u306b\u306f<\/p>\n
\n- AWS\u306e\u201cProvider\u201d\u8a2d\u5b9a\u3067\u30ed\u30fc\u30eb\u3092\u6307\u5b9a<\/li>\n
- Terraform\u306e\u201dBackend\u201d\u8a2d\u5b9a\u3067\u30ed\u30fc\u30eb\u3092\u6307\u5b9a<\/li>\n<\/ul>\n
\u306e2\u3064\u3067\u3059\u3002<\/p>\n
\u518d\u63b2\u3068\u306a\u308a\u307e\u3059\u304c\u3001<\/p>\n
provider "aws" {\n region = "ap-northeast-1"\n}\n\nterraform {\n required_version = "0.14.5"\n backend "s3" {\n bucket = "<tfstate\u30d5\u30a1\u30a4\u30eb\u3092\u304a\u304fS3\u30d0\u30b1\u30c3\u30c8\u540d>"\n key = "<tfstate\u30d5\u30a1\u30a4\u30eb\u540d>"\n region = "ap-northeast-1"\n }\n required_providers {\n aws = {\n source = "hashicorp\/aws"\n version = "3.25.0"\n }\n }\n}<\/code><\/pre>\n\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u306b\u5909\u66f4\u3092\u52a0\u3048\u3066\u3002<\/p>\n
provider "aws" {\n region = "ap-northeast-1"\n\n # assume_role\u30d6\u30ed\u30c3\u30af\u3092\u8ffd\u52a0\n assume_role { \n role_arn = "arn:aws:iam::<\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8ID>:role\/<\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u5148\u306eIAM\u30ed\u30fc\u30eb\u540d>"\n }\n\n}\n\nterraform {\n required_version = "0.14.5"\n backend "s3" {\n bucket = "<tfstate\u30d5\u30a1\u30a4\u30eb\u3092\u304a\u304fS3\u30d0\u30b1\u30c3\u30c8\u540d>"\n key = "<tfstate\u30d5\u30a1\u30a4\u30eb\u540d>"\n region = "ap-northeast-1"\n\n # role_arn \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\n role_arn = "arn:aws:iam::<\u81ea\u5206\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8ID>:role\/<\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u5148\u306eIAM\u30ed\u30fc\u30eb\u540d>"\n\n }\n required_providers {\n aws = {\n source = "hashicorp\/aws"\n version = "3.25.0"\n }\n }\n}<\/code><\/pre>\n\u306e\u3088\u3046\u306b<\/p>\n
\nprovider "aws"<\/code>\u306e\u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u3067 assume_role<\/code>\u306e\u30d6\u30ed\u30c3\u30af\u3092\u4f5c\u3063\u3066\u30ed\u30fc\u30eb\u3092\u6307\u5b9a<\/li>\nterraform<\/code>\u306e\u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u3067\u3001backend<\/code>\u306e\u30d6\u30ed\u30c3\u30af\u5185\u3067role_arn<\/code>\u306e\u6307\u5b9a<\/li>\n<\/ul>\n\u3092\u884c\u3044\u307e\u3059\u3002
\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001Terraform\u306e\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u306e\u969b\u306b\u306f\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3057\u305f\u4e0a\u3067\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n
\uff08\u3053\u306e\u8fba\u308a\u306f\u8a2d\u5b9a\u306e\u6307\u5b9a\u65b9\u6cd5\u306e\u8aa4\u308a\u304c\u3042\u3063\u3066\u3082\u3001terraform\u5b9f\u884c\u6642\u306e\u30a8\u30e9\u30fc\u3067\u306f\u8aa4\u308a\u7b87\u6240\u3092\u5177\u4f53\u7684\u306b\u306f\u6307\u6458\u3057\u3066\u304f\u308c\u305a\u7d50\u69cb\u3064\u307e\u3065\u304d\u307e\u3057\u305f\u3002\u3002\u3002\u6307\u5b9a\u306e\u8a18\u8ff0\u65b9\u6cd5\u306b\u306f\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002\uff09<\/p>\n
\u5b9f\u884c\u7d50\u679c<\/h2>\n
\u4ee5\u4e0a\u304c\u554f\u984c\u306a\u304f\u8a2d\u5b9a\u304c\u3067\u304d\u3066\u3044\u308c\u3070\u3001terraform plan<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u3057\u3066\u3082\u3001\u4ee5\u524d\u3068\u5909\u308f\u3089\u305a<\/p>\nNo changes. Infrastructure is up-to-date.\n\nThis means that Terraform did not detect any differences between your\nconfiguration and real physical resources that exist. As a result, no\nactions need to be performed.<\/code><\/pre>\n\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u306f\u305a\u3067\u3059\u3002\u3053\u308c\u3067\u4eca\u5f8c\u306f\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u306e\u65b9\u5f0f\u3067\u3001terraform\u304c\u5b9f\u884c\u3067\u304d\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n
\u3082\u3057\u3001\u4e0a\u8a18\u306eIAM\u30e6\u30fc\u30b6\u30fc\u3068IAM\u30ed\u30fc\u30eb\u306e\u300c\u4fe1\u983c\u95a2\u4fc2\u300d\u8a2d\u5b9a\u3068\u4e00\u81f4\u3057\u306a\u3044\u6761\u4ef6\u3067\u5b9f\u884c\u3057\u305f\u5834\u5408\u3001<\/p>\n
Error: error configuring S3 Backend: IAM Role (arn:aws:iam::111111111111:role\/TerraformRole) cannot be assumed.\n\nThere are a number of possible causes of this - the most common are:\n * The credentials used in order to assume the role are invalid\n * The credentials do not have appropriate permission to assume the role\n * The role ARN is not valid\n\nError: NoCredentialProviders: no valid providers in chain. Deprecated.\n For verbose messaging see aws.Config.CredentialsChainVerboseErrors<\/code><\/pre>\n\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u3001\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb(Assume Role)\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u65e8\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n
\u307e\u3068\u3081<\/h2>\n
\u4ee5\u4e0a\u304cTerraform\u5b9f\u884c\u306b\u304a\u3044\u3066\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3092\u7528\u3044\u305f\u5f62\u306b\u5909\u3048\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n
\u3053\u308c\u306b\u3088\u308a\u3001\u672c\u4ef6\u3067\u306e.env<\/code>\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u305fAWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306f\u3001\u305d\u308c\u5358\u4f53\u3060\u3051\u3067\u306f\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3059\u308b\u6a29\u9650\u3057\u304b\u6301\u305f\u305a\u3001AWS\u30ea\u30bd\u30fc\u30b9\u3078\u306e\u64cd\u4f5c\u3092\u4f55\u3082\u884c\u3048\u306a\u3044\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
\n\u307e\u305f\u3001\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3082\u30b9\u30a4\u30c3\u30c1\u5148\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8ID\u3001\u30ed\u30fc\u30eb\u540d\u304c\u7279\u5b9a\u3067\u304d\u306a\u3044\u3068\u5b9f\u884c\u3067\u304d\u305a\u3001\u3055\u3089\u306b\u306f\u4eca\u56de\u306fIP\u30a2\u30c9\u30ec\u30b9\u3067\u3082\u5236\u9650\u3092\u3064\u3051\u305f\u306e\u3067\u3001\u81ea\u5206\u304c\u666e\u6bb5\u691c\u8a3c\u3092\u884c\u3046\u74b0\u5883\u306eIP\u30a2\u30c9\u30ec\u30b9\u3060\u3051\u3092\u6307\u5b9a\u3059\u308c\u3070\u3001\u30b9\u30a4\u30c3\u30c1\u5148\u3092\u7279\u5b9a\u3055\u308c\u3066\u3082\u30d6\u30ed\u30c3\u30af\u3055\u308c\u307e\u3059\u3002<\/p>\n