使Terraform远程状态在我的一个项目中工作时遇到问题。状态文件在S3中是远程的。我这样输入:
data "terraform_remote_state" "management" {
backend = "s3"
config {
bucket = "testbucket"
key = "subfolder/terraform.tfstate"
region = "us-west-2"
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在上述状态文件的根目录级别看到输出:
"outputs": {
"cidr": {
"sensitive": false,
"type": "string",
"value": "10.90.0.0/16"
},
Run Code Online (Sandbox Code Playgroud)
我正在像这样使用远程状态:
module "dev-alpha-application" {
source = "../../modules/application"
envname = "test-app"
baseami = "ami-a042f4d8"
key_name = "pb-smarsh-test"
clui_baseami = "ami-xxxxxxxx"
adui_baseami = "ami-xxxxxxxx"
cidr = "10.80.0.0/16"
management_cidr = "${data.terraform_remote_state.management.cidr}"
vpn_gateway_id = "cgw-xxxxxxxx"
cidrs = "${list("${data.terraform_remote_state.management.cidr}", "${module.dev-alpha-application.cidr}")}"
Run Code Online (Sandbox Code Playgroud)
除非我忽略了一些愚蠢的东西,否则这应该起作用,但是当我运行Terraform Apply时,会出现以下错误:
* module.dev-alpha-application.var.management_cidr: Resource 'data.terraform_remote_state.management' does not have attribute 'cidr' for …Run Code Online (Sandbox Code Playgroud) 假设我一定在这里做错了什么,但我似乎无法让 VSCode 使用我非常简单的 devcontainer.json 文件将任何内容安装到容器中。
目前看起来如下:
{
"name": "Terraform",
"dockerFile": "Dockerfile",
"mounts": ["source=/home/paul,target=/host,type=bind,consistency=cached"]
}
Run Code Online (Sandbox Code Playgroud)
我还尝试过文档中给出的示例:
["source=${localEnv:HOME}${localEnv:USERPROFILE},target=/host-home-folder,type=bind,consistency=cached"]
Run Code Online (Sandbox Code Playgroud)
两者似乎都没有在容器内安装任何东西,并且查看“Dev Containers”控制台输出的输出,它甚至看起来不像 VSCode 尝试安装它。我需要打开某些东西才能使其工作吗?
在 Linux Mint 上运行 VSCode 1.36.1。Docker CE 19.03。
使用“模式”中的任何内容在 Terraform 中创建 aws_cognito_user_pool 会导致每次运行 Terraform 时重新创建用户池。我们想使用自定义属性,因此需要在架构中设置选项。
根据文档
“在定义 String 或 Number 的 attribute_data_type 时,需要相应的属性约束配置块(例如 string_attribute_constraints 或 number_attribute_contraints)以防止重新创建 Terraform 资源。此要求对于标准(例如名称、电子邮件)和自定义架构属性均适用。 ”
如果我理解正确,我还需要列出模式中的所有标准属性,以便我可以添加 string_attribute_contraints。
resource "aws_cognito_user_pool" "pool" {
count = "${var.user_pool_count}"
name = "${lookup(var.user_pool[count.index], "name")}"
username_attributes = ["email"]
auto_verified_attributes = ["email"]
schema = [
{
name = "address"
attribute_data_type = "String"
string_attribute_constraints = {
min_length = 1
}
},
{
name = "birthdate"
attribute_data_type = "String"
string_attribute_constraints = {
min_length = 1
}
},
{
name = "email"
attribute_data_type = "String" …Run Code Online (Sandbox Code Playgroud)