[错误]:无法同时部署 (应用) `aws_api_gateway_rest_api` 和 `aws_api_gateway_rest_api_policy`
terraform { required_version = ">= 1.2" required_providers { AWS = { source = "hashicorp/AWS" version = "~> 4.0" } } }
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "api_access" { statement { effect = "Allow" actions = [ "sts:AssumeRole" ] principals { type = "AWS" identifiers = [ "arn:AWS:iam::${data.aws_caller_identity.current.account_id}:root", ] } } }
data "aws_iam_policy_document" "api_invocation_policy" { statement { effect = "Allow" actions = [ "execute-api:Invoke", ] resources = [ "arn:AWS:execute-api::${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.api_gateway.id}///" ] } }
resource "aws_iam_role" "api_gateway_access_role" { name = "api-gateway-access-role" path = "/" assume_role_policy = data.aws_iam_policy_document.api_access.json inline_policy { name = "api-invocation-policy" policy = data.aws_iam_policy_document.api_invocation_policy.json } }
--- API Gateway Resources ---
resource "aws_api_gateway_rest_api" "api_gateway" { name = "api-gateway" description = "Proxy to handle requests" endpoint_configuration { types = ["EDGE"] } }
resource "aws_api_gateway_rest_api_policy" "api_policy" { rest_api_id = aws_api_gateway_rest_api.api_gateway.id policy = <<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "${aws_iam_role.api_gateway_access_role.arn}" }, "Action": "execute-api:Invoke", "Resource": "execute-api:/*" } ] } EOF }
${aws_iam_role.api_gateway_access_role.arn}
output
内容来源: hashicorp/terraform-provider-aws