如何基于变量列表创建API资源

时间:2019-04-11 12:38:44

标签: aws-api-gateway terraform-provider-aws

我正在编写一些Terraform代码以在AWS API Gateway中置备资源。

到目前为止,我已经设法做到这一点……

resource "aws_api_gateway_rest_api" "skel" {
  name        = "${var.api_name}"
  description = "This is a very basic request method"
}

################### Attachments
resource "aws_api_gateway_resource" "attachments" {
  rest_api_id = "${aws_api_gateway_rest_api.skel.id}"
  parent_id   = "${aws_api_gateway_rest_api.skel.root_resource_id}"
  path_part   = "attachments"
}

resource "aws_api_gateway_method" "AttachMethod" {
  rest_api_id   = "${aws_api_gateway_rest_api.skel.id}"
  resource_id   = "${aws_api_gateway_resource.attachments.id}"
  http_method   = "GET"
  authorization = "NONE"
}

resource "aws_api_gateway_method" "AttachOptionsMethod" {
  rest_api_id   = "${aws_api_gateway_rest_api.skel.id}"
  resource_id   = "${aws_api_gateway_resource.attachments.id}"
  http_method   = "OPTIONS"
  authorization = "NONE"
}

但这占用了600多行,我想使其灵活一些,以便我可以在其他项目中使用它。

是否有某种方法可以遍历变量以创建资源和方法,或者我有点乐观。

非常感谢。

尼尔

0 个答案:

没有答案