如何将 api_gateway_base_path_mapping 与 terraform 一起使用?

Jon*_*itz 5 amazon-web-services terraform aws-api-gateway

我正在尝试为 aws 上的 api gateway 中的 api 设置自定义域名。我已经使用 terraform 设置了 api。但是,当我尝试设置自定义域时,它失败并出现以下错误。

应用计划时出错:

发生 1 个错误:

  • module.BillingMetrics.aws_api_gateway_base_path_mapping.billing:发生 1 个错误:

  • aws_api_gateway_base_path_mapping.billing:创建网关基本路径映射时出错:创建网关基本路径映射时出错:BadRequestException:指定的 REST API 标识符无效状态代码:400,请求 ID:b14bbd4c-5823-11e7-a4ea-93525a34b321

我可以在 terraform 日志中看到它确实获得了正确的 api_id。但我不明白为什么它说其余的 api 标识符无效。

下面是我的 terraform 文件的摘录,显示了我如何配置 api_gateway_base_path_mapping。

resource "aws_api_gateway_resource" "views_resource" {
  provider = "aws.regional"
  rest_api_id = "${aws_api_gateway_rest_api.billing_api.id}"
  parent_id   = "${aws_api_gateway_rest_api.billing_api.root_resource_id}"
  path_part   = "views"
}

resource "aws_api_gateway_method" "views-get" {
  provider = "aws.regional"
  rest_api_id   = "${aws_api_gateway_rest_api.billing_api.id}"
  resource_id   = "${aws_api_gateway_resource.views_resource.id}"
  http_method   = "GET"
  authorization = "NONE"
}

resource "aws_api_gateway_method_response" "views_200" {
  provider = "aws.regional"
  rest_api_id = "${aws_api_gateway_rest_api.billing_api.id}"
  resource_id = "${aws_api_gateway_resource.views_resource.id}"
  http_method = "${aws_api_gateway_method.views-get.http_method}"
  status_code = "200"
}

resource "aws_api_gateway_integration" "views-integration" {
  provider = "aws.regional"
  rest_api_id             = "${aws_api_gateway_rest_api.billing_api.id}"
  resource_id             = "${aws_api_gateway_resource.views_resource.id}"
  http_method             = "${aws_api_gateway_method.views-get.http_method}"
  type                    = "AWS"
  uri                     = "arn:aws:apigateway:${var.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${var.region}:${var.account_id}:function:${aws_lambda_function.get_views.function_name}/invocations"
  credentials             = "${var.metrics_role_arn}"
  http_method             = "${aws_api_gateway_method.views-get.http_method}"
  integration_http_method = "POST"
}

resource "aws_api_gateway_integration_response" "Views_Get_IntegrationResponse" {
  provider = "aws.regional"
  rest_api_id = "${aws_api_gateway_rest_api.billing_api.id}"
  resource_id = "${aws_api_gateway_resource.views_resource.id}"
  http_method = "${aws_api_gateway_method.views-get.http_method}"
  status_code = "${aws_api_gateway_method_response.views_200.status_code}"
 }

/* Deploy api */
resource "aws_api_gateway_deployment" "metric_deploy" {
  provider = "aws.regional"
  depends_on  = ["aws_api_gateway_integration.metrics-integration", "aws_api_gateway_integration.hours-integration"]
  stage_name  = "beta"
  rest_api_id = "${aws_api_gateway_rest_api.billing_api.id}"
}

resource "aws_api_gateway_domain_name" "billing" {
  domain_name       = "billing.example.com"
  certificate_arn   = "arn:aws:acm:us-east-1:6--:certificate/5--"
}

resource "aws_api_gateway_base_path_mapping" "billing" {
  api_id      = "${aws_api_gateway_rest_api.billing_api.id}"
  stage_name  = "${aws_api_gateway_deployment.metric_deploy.stage_name}"
  domain_name = "${aws_api_gateway_domain_name.billing.domain_name}"
}

resource "aws_route53_record" "billing" {
  zone_id = "Z-------"

  name = "${aws_api_gateway_domain_name.billing.domain_name}"
  type = "A"

  alias {
    name                   = "${aws_api_gateway_domain_name.billing.cloudfront_domain_name}"
    zone_id                = "${aws_api_gateway_domain_name.billing.cloudfront_zone_id}"
    evaluate_target_health = true
  }
}
Run Code Online (Sandbox Code Playgroud)

是否还需要配置其他元​​素才能正确应用 base_path_mapping?还有其他提示我可能做错了什么吗?

我还应该提到我正在使用 terraform 0.9.7。