我正在使用 Terraform 云。我希望将 AWS 标签与我的资源结合使用。我想用当前的 GIT 分支名称标记 Terraform 中定义的每个资源。这样我就可以将开发与生产分开。
Terraform 有一个环境变量列表,它们确实引用了 GIT 分支名称及其在云中的服务:
TFC_CONFIGURATION_VERSION_GIT_BRANCH - This is the name of the branch that the associated Terraform configuration version was ingressed from (e.g. master).
Run Code Online (Sandbox Code Playgroud)
如何在示例 VPC 的以下资源中引用TFC_CONFIGURATION_VERSION_GIT_BRANCH环境变量?
resource "aws_vpc" "example_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
product = var.product
stage = var.TFC_CONFIGURATION_VERSION_GIT_BRANCH
}
}
Run Code Online (Sandbox Code Playgroud)
参考:https://www.terraform.io/docs/language/values/variables.html#environment-variables
Terraform 通过记录良好的插件拥有远程堆栈,即 terraform.backend.s3 https://www.terraform.io/docs/language/settings/backends/s3.html
aws cdk 可以为堆栈提供远程状态吗?我在文档中找不到。 https://docs.aws.amazon.com/cdk/latest/guide/awscdk.pdfstack
我询问有关 aws cdk 的问题,因为我找到了有关 aws cdktf 的纯文档。发现cloudcloudfront生成了很多json文件并且使用了它。是否包含状态?

amazon-web-services aws-cloudformation terraform terraform-provider-aws aws-cdk
实际上 - 收到了更换的苹果 Mac 笔记本电脑(原来的笔记本电脑因存储不良而崩溃),我正在使用配置重新设置所有内容,我被这个“terraform init”步骤卡住了,
安装的 terraform 版本是 0.13.6 安装的 AWS CLI 是 2.1.32
当“terraform init”被触发时,我收到以下错误,感谢任何帮助,以便我可以解锁我的工作。
Initializing modules...
Initializing the backend...
Initializing provider plugins...
- Using previously-installed hashicorp/kubernetes v1.13.3
- Using previously-installed hashicorp/external v1.1.2
- Finding hashicorp/aws versions matching "~> 2.1.28"...
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints ~>
2.1.28
Run Code Online (Sandbox Code Playgroud) tf 文件中有以下数据库资源:
resource "aws_db_instance" "app_db" {
count = local.db_count
allocated_storage = 5
max_allocated_storage = 10
engine = "postgres"
instance_class = "db.t3.micro"
name = var.db_creds["db_name"]
port = 5432
username = var.db_creds["username"]
password = var.db_creds["password"]
db_subnet_group_name = aws_db_subnet_group.database_sg.name
vpc_security_group_ids = [aws_security_group.app.id]
final_snapshot_identifier = "${var.environment_deployment_tag}-app-db-snaphot"
}
Run Code Online (Sandbox Code Playgroud)
销毁数据库资源后,我收到此错误:
DBSnapshotAlreadyExists:无法创建快照,因为标识符为 app-db-snaphot 的快照已存在
我知道这是因为具有此类标识符的快照已经存在,但我想问是否有办法覆盖以前的快照?
如果不是并且所有快照都应该有唯一的名称,我想像这样的格式应该没问题:
final_snapshot_identifier = "${var.environment_deployment_tag}-app-db-snaphot-${timestamp()}"
我想知道如何清理以前的快照,这样RDS上就不会出现很多快照了?管理最终快照的最佳方法是什么?
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = "us-east-1"
access_key = "<my-key->"
secret_key = "<my-sec-key>"
}
resource "aws_instance" "terra-instance" {
ami = "ami-09e67e426f25ce0d7"
instance_type = "t2.micro"
}
Run Code Online (Sandbox Code Playgroud)
我是 terraform 的新手,也遇到过这个问题。我正在尝试使用 terraform 在 AWS 云中创建一个实例,当我发出“terraform plan”时,它显示“没有更改。基础设施是最新的。”
有人可以帮我解决这个问题吗?
adarshpatil@Adarshs-MacBook-Pro Project-1 % terraform apply 申请完成!资源:0 添加,0 更改,0 销毁。
Terraform 从版本0.11.14升级到0.13.7后出现错误:
错误:资源名称无效
在 .terraform/modules/tflib/alb/main.tf 第 53 行,资源“aws_alb_listener”“443”中:53:资源“aws_alb_listener”“443”{
名称必须以字母或下划线开头,并且只能包含字母、数字、下划线和破折号。
所以我将其重命名为resource "aws_alb_listener" "https",但引发了另一个错误:
错误:提供程序配置不存在
要使用 module.tflib.module.alb.aws_alb_listener.443,需要提供程序 ["registry.terraform.io/-/aws"] 处的原始提供程序配置,但它已被删除。当提供程序配置被删除而该提供程序创建的对象仍然存在于状态中时,就会发生这种情况。重新添加提供程序配置以销毁 module.tflib.module.alb.aws_alb_listener.443,之后您可以再次删除提供程序配置。
AWS 提供商配置:
provider "aws" {
region = var.region
}
terraform {
required_providers {
aws = {
version = "~> 3.15"
source = "hashicorp/aws"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何修复它?
谁能建议我如何自动挂载使用 Terraform 创建的 EBS 卷并使其可用/custom?
resource "aws_instance" "ec201" {\n...\n ebs_block_device {\n device_name = "/dev/sdd"\n volume_type = "gp2"\n volume_size = 10\n delete_on_termination = true\n encrypted = true\n }\n...\nRun Code Online (Sandbox Code Playgroud)\n可以自动挂载吗?
\n我已阅读这些页面:
\n当我做一个:
\n> lsblk\nNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\n...\nnvme1n1 259:0 0 10G 0 disk \nnvme0n1 259:1 0 250G 0 disk \n\xe2\x94\x94\xe2\x94\x80nvme0n1p1 259:2 0 250G 0 part /\nRun Code Online (Sandbox Code Playgroud)\n我有一个 10GB 分区未挂载。是否可以使用 terraform …
amazon-ec2 amazon-web-services terraform terraform-provider-aws
我在 WAF 后面的 AWS ECS 实例中获得了一个微服务,我想创建以下规则:
前两个 IP 集已创建,但我无法使最后一个 IP 集工作。我尝试使用 和其他组合创建 IP 集,0.0.0.0/0但没有成功。
这是我的代码,我删除了 ipset 1 和 2(正在工作),这是 ipset 3:
resource "aws_wafv2_ip_set" "ipset" {
name = "${var.app_name}-${var.environment_name}-whitelist-ips"
scope = "REGIONAL"
ip_address_version = "IPV4"
addresses = ["0.0.0.0/0"]
}
module "alb_wafv2" {
source = "trussworks/wafv2/aws"
version = "~> 2.0"
name = "${var.app_name}-${var.environment_name}"
scope = "REGIONAL"
alb_arn = aws_lb.app_lb.arn
associate_alb = true
ip_sets_rule = [
{
name = "${var.app_name}-${var.environment_name}-ip-blacklist"
action = "deny"
priority = 1 …Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform web-application-firewall terraform-provider-aws
在terraform中,有没有办法有条件地执行模板文件中的某些代码行?例如:
我有一个 test.sh.tpl 文件定义如下,从 main.tf 调用
#!/bin/bash echo ${test_key} > /opt/test_key.properties
在上面的值中,“test_key”是从变量分配的
现在我只想在 ${test_key} 值不为空时执行上面的代码。我尝试了这个,但即使该值存在也不起作用
{ 如果 ${test_key} != "" }
回声 ${test_key} > /opt/test_key.properties
{ 万一 }
我想订阅 aws 市场中的 influxdb 云 - https://aws.amazon.com/marketplace/pp/prodview-4e7raoxoxsl4y?href=_ptnr_web_docs_gettingstarted。有没有办法使用 terraform 来做到这一点?