我想编写一个 terraform 模块来创建 dynamoDb 表。这些属性应该从.tfvars默认变量中读取,而不是像此处的.tf资源指南中那样已命名
为了进一步解释,假设使用属性列表来实现此伪代码:
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "GameScores"
... #Other required feilds
...
...
# attributes is a list of names
for(attribute_name:${length(var.attributes)}){
attribute {
name = "${var.attributes[i]}"
type = "N"
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在 terraform plan/apply 期间迭代属性列表并创建属性{ } ?属性块的数量不能像 terraform 文档中所示的那样是静态的,并且它们的名称必须从变量中读取。
我正在创建一个 EC2 实例并为其加载一些“启动时”脚本以及安装所需的软件。这将成为启动新实例时要使用的基础映像。
创建后,我将创建一个 AMI。此时,无需保留用于创建 AMI 的 EC2 映像。
所以,顺序是:
Create EC2
Install packages
Configure packages
Create AMI
Destroy EC2
Run Code Online (Sandbox Code Playgroud)
如何告诉 Terraform 在最后一步中删除 EC2?
amazon-ec2 amazon-web-services terraform terraform-provider-aws
我需要使用 Terraform 导入事件源映射,文档显示:
terraform 导入 aws_lambda_event_source_mapping.event_source_mapping 12345kxodurf3443
我在任何地方都找不到我的资源的 UUID,它在哪里?
谢谢
应用我的地形计划时遇到一些问题,无法查明其中的问题是什么。我尝试了我能想到的一切。这是我的 lambda.tf 文件:
data "archive_file" "projectLeo_listunsubscribe_lambda_code" {
type = "zip"
source_dir = "${path.module}/../src/ProjectLeo.ListUnsubscribe"
output_path = "${path.module}/../src/code-packaged/list-unsubscribe.zip"
}
resource "aws_lambda_function" "projectLeot_list_unsubscribe_lambda" {
filename = "${data.archive_file.projectLeo_listunsubscribe_lambda_code.output_path}"
function_name = "projectLeo-listunsubscribe-lambda"
role = "${aws_iam_role.projectLeo_list_hygiene_role.arn}"
handler = "${var.lambda_list_unsubscribe_function_handler}"
runtime = "dotnetcore2.1"
memory_size = "256"
timeout = 120
publish = true
reserved_concurrent_executions = 1
environment {
variables = {
optout-topic-arn = "${data.aws_sns_topic.projectLeo_optout_topic.arn}"
}
}
}
data "aws_sns_topic" "projectLeo_optout_topic" {
name = "${var.sns_optout_topic_name}"
}
Run Code Online (Sandbox Code Playgroud)
生成的计划看起来一切正常,但是当应用完成时会生成此错误:
Error: Error creating Lambda function: ValidationException:
status code: 400, request id: c16dc369-bccd-418d-a2b5-2d0383c66064 …Run Code Online (Sandbox Code Playgroud) 我使用 Terraform 建立了基础设施,包括批处理服务作业队列、计算环境和作业定义。
对 Terraform 进行更改后,我运行terraform apply并收到以下错误:
Error: error deleting Batch Compute Environment (data-load): : Cannot delete, found existing JobQueue relationship
status code: 400, request id: 25449415-9c36-4748-95e6-925647bd716a
Run Code Online (Sandbox Code Playgroud)
作业队列中没有作业。我假设它将与与批处理服务相关的其他资源一起被删除/替换,而不是在替换时暂停计算环境的显示。
在过去,我能克服这个问题的唯一方法是破坏我的状态文件并重新开始,但我认为一定有更好的方法。我怎样才能解决这个问题?
我使用安装程序预配置基础设施 (IPI) 在我的 AWS 集群上安装 openshift 4.4.9,但未能成功在 AWS 上启动我的 openshift 集群。由于以下错误。
INFO Creating infrastructure resources...
ERROR
ERROR Error: Error creating IAM instance profile ocp4-925gm-bootstrap-
profile: EntityAlreadyExists:
Instance Profile ocp4-925gm-bootstrap-profile already exists.
ERROR status code: 409, request id: b6918967-774c-44c1-8b92-02ac7388f87c
ERROR
ERROR on ../../../tmp/openshift-install-584826335/bootstrap/main.tf line 46, in resource
"aws_iam_instance_profile" "bootstrap":
ERROR 46: resource "aws_iam_instance_profile" "bootstrap" {
ERROR Error: Error creating IAM instance profile ocp4-925gm-worker-profile: EntityAlreadyExists:
Instance Profile ocp4-925gm-worker-profile already exists.
ERROR status code: 409, request id: 3b5d2b9c-28fe-4c95-b622-7a80af45dfb6
ERROR
ERROR on ../../../tmp/openshift-install-584826335/iam/main.tf line …Run Code Online (Sandbox Code Playgroud) amazon-web-services openshift aws-cli terraform terraform-provider-aws
鉴于我有 2 个由 terraform 创建的实例
resource "aws_instance" "web1" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = {
Name = "web1"
}
}
resource "aws_instance" "web2" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = {
Name = "web2"
}
}
Run Code Online (Sandbox Code Playgroud)
我如何使用 terraform 为他们创建备份计划?
要求:我有一堆 EC2。我根据标签对其进行分组。在此示例中,组总数 = 4,每个组有 7 个 EC2:1 个父级 - 6 个子级。在这里我分享一个命名很重要的孩子的代码。
工作代码:这里我分享子 EC2 代码,该代码与名为 :ws_to_Child_Node_name_map_count 的地图类型的输入变量完美配合。现在我希望它是可扩展的(父子数量),我希望使用“在本地动态创建的地图”而不是使用输入变量。主.tf
resource "aws_instance" "ec2_instance_child" {
count = var.ec2_instance_child_count
tags = {
NodeName = "${lookup(var.ws_to_Child_Node_name_map_count, count.index+1, 99)}"
}
}
Run Code Online (Sandbox Code Playgroud)
变量.tf
variable "ws_to_Child_Node_name_map_count" {
type = map
default = {
"1"="1"
"2"="2"
"3"="3"
"4"="4"
"5"="5"
"6"="6"
"7"="1"
"8"="2"
"9"="3"
"10"="4"
"11"="5"
"12"="6"
"13"="1"
"14"="2"
"15"="3"
"16"="4"
"17"="5"
"18"="6"
"19"="1"
"20"="2"
"21"="3"
"22"="4"
"23"="5"
"24"="6"
}
}
variable "ec2_instance_child_count" {
description = "Number of instances to run"
default …Run Code Online (Sandbox Code Playgroud) 在我的 terraform 脚本中,我有以下资源 -
resource "aws_api_gateway_account" "demo" {
cloudwatch_role_arn = var.apigw_cloudwatch_role_arn
}
Run Code Online (Sandbox Code Playgroud)
在应用阶段,我看到以下错误 -
2020/09/21 20:20:48 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: Updating API Gateway Account failed: AccessDeniedException:
status code: 403, request id: abb0662e-ead2-4d95-b987-7d889088a5ef
Run Code Online (Sandbox Code Playgroud)
是否需要向角色附加特定权限才能消除此错误?
开始时我使用的是默认工作区。由于复杂性增加,我想使用多个工作区。我想将默认工作区中的内容移动到其自己的工作区中或将默认工作区重命名为另一个工作区。我怎样才能做到这一点?