在尝试创建$disconnect
为 API 网关命名的路由键时,我运行下面的代码片段,同时var.route_name
应该收到字符串“disconnect”:
resource "aws_apigatewayv2_route" "route" {
api_id = var.apigw_api.id
route_key = "$${var.route_name}"
# more stuff...
}
Run Code Online (Sandbox Code Playgroud)
但它并没有正确地转义它。我找不到正确的方法来发出 a $
,后跟var.route_name
s 的内容。
怎么做?
我一直在尝试有条件地使用根模块中的模块,以便在某些环境下不会创建该模块。许多人声称,通过count
使用条件将模块中的 设为 0 或 1 即可达到目的。
module "conditionally_used_module" {
source = "./modules/my_module"
count = (var.create == true) ? 1 : 0
}
Run Code Online (Sandbox Code Playgroud)
然而,这改变了 的类型conditionally_used_module
:我们将拥有一个包含单个对象的列表(或元组),而不是对象(或映射)。是否有另一种方法可以实现此目的,而不意味着更改模块的类型?
我在 Github 的几个terraform
代码中发现了一个模式。
resource "aws_vpc" "this"
Run Code Online (Sandbox Code Playgroud)
我想知道关键字如何this
提供相对于命名资源的特殊优势。我找不到有关关键字的Hashicorp文档this
。
https://github.com/cloudposse/terraform-aws-vpn-connection/blob/master/context.tf
我正在尝试在 Terraform 中构建 Web ACL 资源 https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl
该资源具有嵌套块规则->操作->块和规则->操作->计数
我想要一个变量,其类型允许我将操作设置为 或 ,count {}
以便block{}
可以进行以下两种配置:
带块:
resource "aws_wafv2_web_acl" "example" {
...
rule {
...
action {
block {}
}
...
}
Run Code Online (Sandbox Code Playgroud)
与计数:
resource "aws_wafv2_web_acl" "example" {
...
rule {
...
action {
count {}
}
...
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我可以通过布尔变量和动态块以非常非声明性的方式实现此结果。
我的问题是,变量的类型可以引用嵌套块的类型,从而可以将嵌套块的内容传递到变量中吗?
我想要实现的目标与此类似(非工作语法):
resource "aws_wafv2_web_acl" "example" {
...
rule {
...
action = var.action_block
...
}
}
Run Code Online (Sandbox Code Playgroud)
variable "action_block" {
description = "Action of the rule"
type = <whatever type is accepted …
Run Code Online (Sandbox Code Playgroud) 我正在实现一个安全组模块,以便它将通过获取和过滤 cidr 和 source_security_group_id 创建安全组规则来创建安全组规则。
当前模块配置。
resource "aws_security_group" "this" {
name = var.name
description = var.description
vpc_id = var.vpc_id
revoke_rules_on_delete = var.revoke_rules_on_delete
}
## CIDR Rule
resource "aws_security_group_rule" "cidr_rule" {
count = length(var.security_group_rules)
type = var.security_group_rules[count.index].type
from_port = var.security_group_rules[count.index].from_port
to_port = var.security_group_rules[count.index].to_port
protocol = var.security_group_rules[count.index].protocol
cidr_blocks = var.security_group_rules[count.index].cidr_block
description = var.security_group_rules[count.index].description
security_group_id = aws_security_group.this.id
}
## Source_security_group_id Rule
resource "aws_security_group_rule" "source_sg_id_rule" {
count = length(var.security_group_rules)
type = var.security_group_rules[count.index].type
from_port = var.security_group_rules[count.index].from_port
to_port = var.security_group_rules[count.index].to_port
protocol = var.security_group_rules[count.index].protocol
source_security_group_id = …
Run Code Online (Sandbox Code Playgroud) 这是否是 hashcorp 保管库策略,以便允许访问保管库内的任何资源和路径?出于明显的安全原因,我希望启用管理策略而不向任何人授予根令牌访问权限。
path "*" {
capabilities = ["create", "read", "update", "delete", "list", "sudo"]
}
Run Code Online (Sandbox Code Playgroud) Terraform 上的一些资源支持可选属性。我有兴趣仅在满足条件时才声明和设置可选属性的值。否则,根本不要声明它。
我发现的所有建议都是基于声明属性并将其值设置为null
如果条件不满足,而不是根本不声明属性。
我有办法做类似以下的事情吗?在伪代码中:
resource "some_resource" "this" {
name = var.name
if var.name == "some_name":
some_optional_attribute = "some_value"
else:
pass # do nothing, don't even declare the optional attribute
}
Run Code Online (Sandbox Code Playgroud)
请告诉我,提前谢谢!
我想将 terraform 中的简单字符串列表转换为以键作为索引的地图。
我想从这样的事情开始:
locals {
keycloak_secret = [
"account-console",
"admin-cli",
"broker",
"internal",
"realm-management",
"security-admin-console",
]
}
Run Code Online (Sandbox Code Playgroud)
对于类似的东西
map({0:"account-console", 1:"admin-cli"}, ...)
Run Code Online (Sandbox Code Playgroud)
我的目标是利用 terraform 0.13 的新功能在terraform 模块上使用循环地图。
我没有找到任何解决方案,请帮忙,谢谢。
我想简化这样的构造
variable "google" {
type = object({
project = string
region = string
zone = string
})
}
provider "google" {
project = var.google.project
region = var.google.region
zone = var.google.zone
}
Run Code Online (Sandbox Code Playgroud)
HCL 有类似展开运算符的东西吗?
terraform 最近实现了aws_cloudfront_cache_policy
资源和数据源(从 aws 提供商版本0.3.28
IIRC 开始)。
它最终启用了Brotli
压缩,这就是我需要使用它的原因,但我不确定如何将它集成到现有的 terraform 代码库中,也是因为我不太确定 和 之间的aws_cloudfront_cache_policy
关系ordered_cache_behavior
。
aws_cloudfront_cache_policy
- 我可以将其放入我的aws_cloudfront_distribution
资源中吗?ordered_cache_behavior
?amazon-web-services amazon-cloudfront terraform hcl terraform-provider-aws