是否可以创建 EBS 卷的快照,获取该快照并将其转换回 EBS 卷,然后通过 Terraform 将其附加到 EC2?
我目前正在考虑在 AWS 中自动化我们的生产和测试环境,因此它们是相同的,我发现使用 Terraform 非常有用,但我找不到任何有关如何实现这一目标的文档。
我目前在 test.tfvars 文件中有这张地图:
ssm = {
names = ["Terraform-1","Terraform-2","Terraform-3"]
values = ["tf-1","tf-2","tf-3"]
}
Run Code Online (Sandbox Code Playgroud)
我想做的是:
resource "aws_ssm_parameter" "parameter_store" {
count = 3
name = "$${element(var.ssm[names],count.index)}"
type = "String"
value = "$${element(var.ssm[values],count.index)}"
}
Run Code Online (Sandbox Code Playgroud)
但我希望计数基于我的 ssm 地图中的名称列表的长度,而不是 count=3。我试过这个:
"${length(var.ssm[names])}"
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
Error: aws_ssm_parameter.parameter_store: resource count can't reference variable: names
Run Code Online (Sandbox Code Playgroud)
谁能指出我解决此错误的正确方向?我不太确定我做错了什么。
有没有办法使用 terraform 创建默认 AWS VPC?
aws_vpc资源没有任何属性将 VPC 标记为默认。
我知道我可以使用 aws-cli aws ec2 create-default-vpc,但那超出了 terraform 的范围。
我想创建 x 个实例并运行相同的配置程序。
resource "aws_instance" "workers" {
ami = "ami-08d658f84a6d84a80"
count = 3
...
Run Code Online (Sandbox Code Playgroud)
provisioner "remote-exec" {
scripts = ["setup-base.sh", "./setup-docker.sh"]
connection {
type = "ssh"
host = "${element(aws_instance.workers.*.public_ip, count.index)}"
user = "ubuntu"
private_key = file("${var.provisionKeyPath}")
agent = false
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这条host线混淆了 Terraform。得到Error: Cycle: aws_instance.workers[2], aws_instance.workers[1], aws_instance.workers[0]
这是我用于创建 Fargate ECS 服务的 terraform 文件。
variable "aws_region" { }
variable "flavor" { } # test or prod
variable "task_worker_service_name" { }
variable "task_cpu" {}
variable "task_memory" {}
variable "az_count" {}
terraform {
required_version = "= 0.12.6"
}
provider "aws" {
version = "~> 2.21.1"
region = "${var.aws_region}"
}
data "aws_availability_zones" "available" {}
data "aws_iam_policy_document" "ecs_service_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [ "ecs.amazonaws.com" ]
}
}
}
data "aws_iam_policy_document" "task_worker_iam_role_policy" {
statement …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-ecs aws-security-group terraform-provider-aws
在我的 lambda.tf 中,我有一个数据资源
data "template_file" "handler" {
template = "${file("${path.module}/templates/handler.js")}"
vars = {
ENDPOINT = "${var.domain}"
PASSWORD = "${var.password}"
}
}
Run Code Online (Sandbox Code Playgroud)
但是 - 我遇到语法错误:
Error: failed to render : <template_file>:280,49-50: Extra characters after interpolation expression; Expected a closing brace to end the interpolation expression, but found extra characters.
on ../docs/lambda.tf line 1, in data "template_file" "handler":
1: data "template_file" "handler" {
Run Code Online (Sandbox Code Playgroud)
Terraform 是否允许在插值内进行插值?如果是这样 - 任何有关指出错误所在的建议将不胜感激。
地形v0.12.9。提供商“aws”版本"~> 2.7"
以下是更多详细信息:
工作空间-A(基础堆栈):此工作空间包含将创建 AWS 的代码:VPC、SG、路由表、子网和相关关联等。
工作区-B(Service-1 堆栈):此工作区包含用于创建 AWS 的代码:ALB、一些使用 Fargate 的 ECS 容器以及与此服务相关的一些其他组件。
现在,在上述情况下,任何服务(Service-1、2、3 等)都将使用 Workspace-A 创建的 VPC/基础堆栈,我们如何使用 Workspace A(VPC、SG、子网等)的输出作为变量工作区 B 以便工作区 B 可以使用这些 VPC 和其余组件。
我在本地运行 Terraform 0.12.24
我正在尝试部署与 Lambda 的 API 网关集成
我正在尝试使用 Terraform 启用 AWS API GW CORS。
对于 OPTIONS 方法响应,我有以下资源:
resource "aws_api_gateway_method_response" "options_200" {
rest_api_id = aws_api_gateway_rest_api.scout-approve-api-gateway.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = aws_api_gateway_method.options_method.http_method
status_code = "200"
response_models {
"application/json" = "Empty"
}
response_parameters {
"method.response.header.Access-Control-Allow-Headers" = true,
"method.response.header.Access-Control-Allow-Methods" = true,
"method.response.header.Access-Control-Allow-Origin" = true
}
depends_on = [aws_api_gateway_method.options_method]
}
Run Code Online (Sandbox Code Playgroud)
我得到:
Error: Invalid argument name
on main.tf line 48, in resource "aws_api_gateway_method_response" "options_200":
48: "application/json" = "Empty"
Argument names must not be quoted.
Run Code Online (Sandbox Code Playgroud)
是什么赋予了?
amazon-web-services terraform aws-api-gateway terraform-provider-aws terraform0.12+
有没有办法在请求实例之前获取实例类型(例如 t3.medium)可用的可用区?我正在尝试运行以下代码,但对于某些区域,它会因以下错误而失败:
Error: Error launching source instance: Unsupported: Your requested instance type (t3.micro) is not supported in your requested Availability Zone (us-east-1e). Please retry your request by not specifying an Availability Zone or choosing us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1f.
Run Code Online (Sandbox Code Playgroud)
显然,我可以手动将可用区域指定为受支持的区域之一,但我想最小化硬编码可用区域。
amazon-ec2 amazon-web-services terraform terraform-provider-aws
网络上的每个 Terraform 指南都提供了部分解决方案,几乎总是不是真实的图片。
我明白了,并不是每个人都有相同的基础设施需求,但是让我担心的是常见的场景:
没有在真实示例项目中的任何地方出现。
我正在寻找那个,同时,我已经研究并得出结论,除了这些需求之外,我还想要:
我当前的结构,不使用模块 - 只有根模块:
infra/ ------------------------------ 'terraform init', 'terraform apply' inside here*
main.tf ------------------------ Sets up aws provider, backend, backend bucket, dynamodb table
terraform.tfvars
variables.tf ----------------- Holds few variables such as aws_region, project_name...
Run Code Online (Sandbox Code Playgroud)
我想要的结构文件夹树(用于单个存储桶资源的简单开发和暂存模拟)是我认为的事情:
infra/
dev/
s3/
modules.tf ------ References s3 module from local/remote folder with dev inputs
stage/
s3/
modules.tf ------ References s3 module from local/remote folder with stage inputs
Run Code Online (Sandbox Code Playgroud)
但是我以前的根模块中的文件呢?我仍然想像以前一样拥有一个远程后端 …