我在 Terraform main.tf 文件中使用以下定义创建了一个 api-gateway 资源
resource "aws_api_gateway_rest_api" "test-api" { }
现在我已将资源引用名称更改为“prod-api”,如下
resource "aws_api_gateway_rest_api" "prod-api" { }
为了避免由于名称从 test-api 更改为 prod-api 而删除现有的 api 网关,只是为了更新状态文件中的资源引用名称,我尝试使用移动块
moved {
from = aws_api_gateway_rest_api.test-api
to = aws_api_gateway_rest_api.prod-api
}
但是在上面移动的块中,来自行抛出错误说明
未解决的参考test-api
由于旧的资源引用名称“test-api”在当前配置中不存在,因为它已更改为“prod-api”,所以我不确定如何在行中提供“test-api”的引用。 我尝试定义一个变量并引用它,但这不起作用。 您能否告诉我如何为当前代码配置中不存在的名称提供资源引用?
我认为重命名资源应该有效,大致如下:
resource "aws_api_gateway_rest_api" "prod-api" {
# (resource-type-specific configuration)
}
moved {
from = aws_api_gateway_rest_api.test-api
to = aws_api_gateway_rest_api.prod-api
}