我升级到 Terraform v0.12.16,现在我收到很多类似这样的消息:
Warning: Interpolation-only expressions are deprecated
on ../modules/test-notifier/test_notifier.tf line 27, in resource "aws_sns_topic_policy" "default":
27: arn = "${aws_sns_topic.default.arn}"
Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.
Template interpolation syntax is still used to construct strings from
expressions when the template …Run Code Online (Sandbox Code Playgroud) 当我有一个托管区域时,我可以轻松创建该区域,然后通过按名称引用托管区域,在委托账户中为该区域创建 NS 记录。
现在我需要创建多个托管区域并将名称服务器记录传递回父帐户,我不确定是否可以(或者如何)引用多个资源。阅读本文可能没有多大意义,因此下面的代码是我所掌握的。
我现在有一个for_each循环,它将循环遍历字符串列表并为每个字符串创建一个托管区域,然后我想在另一个帐户中创建相应的 NS 记录,请注意,我正在使用单独的提供程序连接到provider = aws.management_account管理帐户,并且这对于单个托管区域来说效果很好。
我不知道如何引用托管区域,是否有一些语法或者我的方法错误?
resource "aws_route53_zone" "public_hosted_zone" {
for_each = local.aws_zones
name = "${each.value}.${var.domain}"
}
resource "aws_route53_record" "ns_records" {
for_each = local.aws_zones
provider = aws.management_account
allow_overwrite = true
name = "${each.value}.${var.domain}"
ttl = 30
type = "NS"
zone_id = data.aws_ssm_parameter.public_hosted_zone_id.value
records = [
aws_route53_zone.public_hosted_zone.name_servers[0], # Here is my old code which works for a single hosted zone but I cannot work out how to reference multiples …Run Code Online (Sandbox Code Playgroud) 我有一个通过 Terraform 部署的 GCP 基础设施:存储桶、服务帐户、计算引擎、VPC、云 SQL、BigTable、BigQuery、Composer 等。
Terraform v0.11.10 提供程序“google”(2.15.0)
最近客户要求我将我们仅有的一个 terraform 文件(例如 main.tf)拆分为多个文件。例如:一个文件用于存储桶,另一个用于服务帐户,另一个用于数据库服务等。
我只有一个 terraform 状态文件位于 GCP 存储桶中。
我怎样才能以最小的影响做到这一点?地形状态怎么样?(是否还会有多个状态文件?或者是只保留一个 TF 文件的想法,即使我们将代码拆分出来?)
注意:这与 Terraform 模块无关,它只是将单个 terraform 文件 (.tf) 分成多个文件 (.tf)
提前致谢!
我如何能够执行以下命令:
terraform apply
#=>
. . .
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value:
Run Code Online (Sandbox Code Playgroud)
没有随后的交互式提示?
我对在 terraform 文档中读到的内容有点困惑。以下是关于模块的说明:
https://www.terraform.io/docs/language/modules/index.html
模块是一起使用的多种资源的容器。模块由保存在一个目录中的 .tf 和/或 .tf.json 文件的集合组成。
以下是关于提供商的说明: https ://www.terraform.io/docs/language/providers/requirements.html
要求提供者
每个 Terraform 模块必须声明它需要哪些提供程序,以便 Terraform 可以安装和使用它们。提供者要求在 required_providers 块中声明。
提供程序要求由本地名称、源位置和版本约束组成:
Run Code Online (Sandbox Code Playgroud)terraform { required_providers { mycloud = { source = "mycorp/mycloud" version = "~> 1.0" } } }
我对此感到困惑,因为我从未required_providers在任何模块中指定过,即使我正在使用提供程序并且它说我必须这样做。直到今天我什至不知道文档这么说。
那么我是否误解了文档,或者文档是错误的?我的每个模块required_providers是否需要?我的 terraform 配置在没有它们的情况下肯定可以工作,那么它们是否默认为某些内容?如果是,如何以及在哪里?
我运行此命令来更新 ubuntu VM 中的软件包。
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)
它最后给了我以下错误。
Err:5 https://apt.releases.hashicorp.com bionic InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXXXXXX
Fetched 12.0 kB in 1s (10.4 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://apt.releases.hashicorp.com bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXXXXXX
W: …Run Code Online (Sandbox Code Playgroud) 在AWS API Gateway中,我将端点定义为/users/{userId}/someAction,并且我尝试使用terraform重新创建此端点
我会开始像某样链接的gateway_resource链......
resource "aws_api_gateway_resource" "Users" {
rest_api_id = "${var.rest_api_id}"
parent_id = "${var.parent_id}"
path_part = "users"
}
//{userId} here?
resource "aws_api_gateway_resource" "SomeAction" {
rest_api_id = "${var.rest_api_id}"
parent_id = "${aws_api_gateway_resource.UserIdReference.id}"
path_part = "someAction"
}
Run Code Online (Sandbox Code Playgroud)
然后我在其中定义了aws_api_gateway_method其他所有内容.
如何在terraform中定义此端点?terraform文档和示例不包括此用例.
我正在使用 Terraform 0.12 版。如果已存在具有相同名称的资源,我需要跳过资源创建。
我为此做了以下工作:
阅读自定义图像列表,
data "ibm_is_images" "custom_images" {
}
Run Code Online (Sandbox Code Playgroud)
检查图像是否已经存在,
locals {
custom_vsi_image = contains([for x in data.ibm_is_images.custom_images.images: "true" if x.visibility == "private" && x.name == var.vnf_vpc_image_name], "true")
}
output "abc" {
value="${local.custom_vsi_image}"
}
Run Code Online (Sandbox Code Playgroud)
仅当图像存在时创建为假。
resource "ibm_is_image" "custom_image" {
count = "${local.custom_vsi_image == true ? 0 : 1}"
depends_on = ["data.ibm_is_images.custom_images"]
href = "${local.image_url}"
name = "${var.vnf_vpc_image_name}"
operating_system = "centos-7-amd64"
timeouts {
create = "30m"
delete = "10m"
}
}
Run Code Online (Sandbox Code Playgroud)
这在第一次使用“terraform apply”时效果很好。它发现图像不存在,因此创建图像。
当我第二次运行“terraform apply”时。它正在删除上面创建的资源“custom_image”。知道为什么要在第二次运行时删除资源吗?
另外,如何根据某些条件创建资源(例如仅当它不存在时)?
我正在尝试使用 AWS 秘密管理器来声明 RDS 管理员凭据。
variable "RdsAminCred" {
default = {
username = "dbadmin"
password = "dbadmin#02avia"
}
type = map(string)
}
resource "aws_secretsmanager_secret" "RdsAminCred" {
name = "RdsAminCred"
}
resource "aws_secretsmanager_secret_version" "RdsAminCred" {
secret_id = aws_secretsmanager_secret.RdsAminCred.id
secret_string = jsonencode(var.RdsAminCred)
}
Run Code Online (Sandbox Code Playgroud)
resource "aws_db_instance" "default" {
identifier = "testdb"
allocated_storage = 20
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t2.medium"
name = "mydb"
username = "dbadmin"
password = …Run Code Online (Sandbox Code Playgroud) 我有一个 terraform 列表,看起来像:
array = ["a","b","c"]
Run Code Online (Sandbox Code Playgroud)
在这个 terraform 文件中,有两个变量,称为年龄和性别,如果年龄等于 12 并且性别等于男性(即,如果 var. age == 12 && var.gender == 'male' 则数组应为 ["a","b","c","d"],否则数组应为 ["a","b","c “])。以下内容是否会沿着正确的道路进行,或者我是否需要使用其他方法?
array = ["a","b","c", var.age == 12 && var.gender == 'male' ? "d" : null]
Run Code Online (Sandbox Code Playgroud)