有没有针对 terraform 的静态代码分析工具?我试过 tflint。但它不支持模块或资源属性的输出。请提出任何其他建议
是否有任何脚本可以自动格式化永久性磁盘并将其附加到 Google Cloud VM 实例,而不是执行格式化和安装步骤?
永久性磁盘是使用 Terraform 创建的,它还会创建一个 VM 并使用attached_disk命令将磁盘附加到它。
我希望在 VM 实例启动时运行一个简单的脚本:
google-compute-engine google-cloud-platform terraform terraform-provider-gcp
variable "cidr" {
type = map(string)
default = {
development = "x.1.0.0/16"
qa = "x.1.0.0/16"
default = "x.1.0.0/16"
}
}
Run Code Online (Sandbox Code Playgroud)
variable "network_address_space" {
default = lookup(var.cidr, var.environment_name,"default")
}
Run Code Online (Sandbox Code Playgroud)
我收到错误“错误:不允许函数调用”
variable "subnet_address_space": cidr_subnet2_address_space = cidrsubnet(var.network_address_space,8,1)
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)
请告诉我,提前谢谢!
我的目录结构
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ec2\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ec2.tf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 outputs.tf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vars.tf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.tf\nRun Code Online (Sandbox Code Playgroud)\n\n主.tf
\n\nprovider "aws" {\n region = "us-east-1"\n}\n\nmodule "ec2" {\n source = "./ec2"\n}\nRun Code Online (Sandbox Code Playgroud)\n\nec2/ec2.tf
\n\ndata "aws_ami" "example" {\n most_recent = true\n owners = [\n "amazon"]\n\n filter {\n name = "image-id"\n values = [\n "ami-0323c3dd2da7fb37d"]\n }\n\n filter {\n name = "root-device-type"\n values = [\n "ebs"]\n }\n\n filter {\n name = "virtualization-type"\n values = [\n "hvm"]\n }\n}\n\nresource "aws_instance" "web" {\n ami = data.aws_ami.example.id\n instance_type = "t2.micro"\n subnet_id …Run Code Online (Sandbox Code Playgroud) 我编写了一个带有变量定义的 terraform 配置,例如:
variable "GOOGLE_CLOUD_REGION" {
type = string
}
Run Code Online (Sandbox Code Playgroud)
当我运行时,terraform plan系统会要求我填写此变量,即使此变量是在我的环境中设置的。
有没有办法告诉 terraform 使用当前的环境变量?或者我是否必须导出它们并以某种方式手动将它们一一传递?
您好,我正在使用 terraform 创建 Route53 记录,我已经有一个托管域(公共),让我们说一下example.com如何获取其 zone_id 并附加到记录。如何获取现有 Route53 托管区域的 zone_id。我已经编写了一个文件,但它的作用是创建另一个托管区域,example.com而不是获取现有的example.com
resource "aws_route53_zone" "main" {
name = "example.com"
}
resource "aws_route53_record" "www" {
zone_id = data.aws_route53_zone.selected.zone_id
name = "dev.${data.aws_route53_zone.selected.name}"
type = "A"
alias {
name = var.alb_dns
zone_id = var.zone_id
evaluate_target_health = false
}
}
Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-elb amazon-route53 terraform terraform-provider-aws
我想将 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 模块上使用循环地图。
我没有找到任何解决方案,请帮忙,谢谢。
我正在创建一个 kubernetes 集群来托管服务,并添加一个内部负载均衡器来在我的 VM 实例和 kubernetes 集群之间路由流量。我想向负载均衡器前端添加服务标签,以便我可以使用 dns 名称而不是 IP 地址。但我不知道用于添加服务标签的注释?我的 terraform 配置如下所示
知道在哪里可以找到支持的注释列表
resource "kubernetes_manifest" "service_ilb" {
provider = kubernetes-alpha
manifest = {
"apiVersion" = "v1"
"kind" = "Service"
"metadata" = {
"name" = "ilb-service"
"namespace" = var.namespace
"annotations" = {
"cloud.google.com/load-balancer-type" = "Internal"
"networking.gke.io/internal-load-balancer-allow-global-access" = "true"
"networking.gke.io/internal-load-balancer-subnet" = var.subnetwork
# Does not work
"networking.gke.io/internal-load-balancer-service-label" = "my-dns-name"
}
"labels" = {
"app.kubernetes.io/component" = "rabbitmq-server"
"app.kubernetes.io/name" = "rabbitmq-instance"
}
}
"spec" = {
"type" = "LoadBalancer"
"ports" = [
{ …Run Code Online (Sandbox Code Playgroud) kubernetes google-kubernetes-engine terraform terraform-provider-kubernetes
背景:
我使用 AWS CodeBuild buildspec.yml 迭代 GitHub 存储库中的目录,以使用 Terraform 应用 IaC。为了访问 Terraform AWS 提供商所需的凭证,我使用 AWS 系统管理器参数存储来检索 buildspec.yml 中的访问权限和密钥。
问题:
系统管理器参数存储屏蔽了访问权限和密钥环境值,因此当 Terraform AWS 提供程序继承它们时,提供程序会输出凭证无效:
Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: InvalidClientTokenId: The security token included in the request is invalid.
status code: 403, request id: xxxx
Run Code Online (Sandbox Code Playgroud)
要重现该问题:
创建系统管理器参数存储变量(TF_VAR_AWS_ACCESS_KEY_ID=访问权限,TF_AWS_SECRET_ACCESS_KEY=秘密)
使用以下命令创建 AWS CodeBuild 项目:
"source": {
"type": "NO_SOURCE",
}
"environment": {
"type": "LINUX_CONTAINER",
"image": "aws/codebuild/standard:4.0",
"computeType": "BUILD_GENERAL1_SMALL"
}
Run Code Online (Sandbox Code Playgroud)
buildspec.yml具有以下内容:(修改为创建 .tf 文件而不是从 github 采购)
version: 0.2 …Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform aws-codebuild aws-parameter-store
terraform ×10
hcl ×2
amazon-ec2 ×1
amazon-elb ×1
kubernetes ×1