【发布时间】:2020-12-27 17:38:00
【问题描述】:
给定网址/customers/{customerId}/accounts 或/customers/{customerId}/accounts/{accountId}
是否可以动态创建资源?
我不想有重复的代码。我打算使用某种地图或列表来管理它。有没有可能?
示例(硬代码):
resource "aws_api_gateway_resource" "customers" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_rest_api.my-api.root_resource_id}"
path_part = "customers"
}
resource "aws_api_gateway_resource" "single-customer" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_resource.customers.id}"
path_part = "{customerId}"
}
resource "aws_api_gateway_resource" "customers-accounts" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_resource.single-customer.id}"
path_part = "accounts"
}
//----
// GET
//----
resource "aws_api_gateway_method" "get-customers-accounts" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
resource_id = "${aws_api_gateway_resource.customers-accounts.id}"
http_method = "GET"
authorization = "NONE"
}
类似这样的:
resource "aws_api_gateway_resource" "var.resource.name" {
rest_api_id = "${aws_api_gateway_rest_api.my-api.id}"
parent_id = "${aws_api_gateway_rest_api.<previous resource id or root id if is root>}"
path_part = "<current value>"
}
【问题讨论】:
-
您在那里使用 HCL1 语法。你能确认你需要一个 0.11 兼容的答案(并且还用
terraform0.11标记问题)还是用 HCL2 语法替换语法? -
@ydaetskcoR 我只是举个例子。我正在使用 0.12
标签: amazon-web-services terraform terraform0.12+