尝试将 AWS 提供商升级到版本 4,但在 RDS 模块中出现以下错误:
\nError: Conflicting configuration arguments\n\xe2\x94\x82\n\xe2\x94\x82 with module.my-instance-mysql-eu[0].module.rds.module.db_instance.aws_db_instance.this[0],\n\xe2\x94\x82 on .terraform/modules/my-instance-mysql-eu.rds/modules/db_instance/main.tf line 47, in resource "aws_db_instance" "this":\n\xe2\x94\x82 47: db_name = var.db_name\n\xe2\x94\x82\n\xe2\x94\x82 "db_name": conflicts with replicate_source_db\nRun Code Online (Sandbox Code Playgroud)\n 有没有一种方法可以在不运行的情况下验证文件的内容.tfvars(即适合传递给terraform plan -var-file foo.tfvars)terraform plan?
理想情况下验证变量名称,但即使只是基本语法也很好。
想要这样做的原因是我们有一些文件仅在某些环境中使用,并且最近提交了语法上不正确的更改 - 但只有在尝试部署到该环境时才会被捕获。我希望能够在运行该terraform plan步骤之前在管道中检测到该文件无效。
对于.tf文件本身,我们可以使用terraform validate,但这不会查看变量文件。
我目前有一段代码,我一直在安静地使用它,该代码调用自定义 S3 模块。今天,我尝试运行相同的代码,但开始收到有关提供程序的错误。
\n\n\n\xe2\x95\xb7 \xe2\x94\x82 错误: 无法查询可用的提供程序包 \xe2\x94\x82 \xe2\x94\x82 无法\n检索提供程序 hashicorp/s3 的可用版本列表:\n提供程序注册表registry.terraform.io 没有名为\n\xe2\x94\x82 的提供程序registry.terraform.io/hashicorp/s3 \xe2\x94\x82 \xe2\x94\x82 所有模块都应指定\n其 required_providers,以便外部消费者在使用模块时将获得\n正确的提供者。要查看 \xe2\x94\x82 当前依赖于 hashicorp/s3 的模块,请运行以下命令: \xe2\x94\x82
\n
\nterraformproviders
进行一些挖掘似乎 terraform 正在寻找模块registry.terraform.io/hashicorp/s3,该模块不存在。
\n到目前为止,我已经尝试了以下方法:
\n进一步阅读,它指的是 terraform 模块的缓存问题。我尝试运行terraformproviderslock并收到此错误。
\n\n错误:无法检索用于锁定 \xe2\x94\x82 \xe2\x94\x82 的提供程序 …
由于使用 M1 mac,我收到一个错误,导致 terraform 初始化无法成功(见下文);这是由于 terraform 在不需要时尝试安装 hasicorp/template 提供程序引起的。为什么当没有任何资源需要时,hashicorp/模板提供程序会尝试安装?
\n\n\n\xe2\x94\x82 错误:不兼容的提供程序版本 \xe2\x94\x82 \xe2\x94\x82 提供程序\nregistry.terraform.io/hashicorp/template v2.2.0 没有\n适用于您当前平台 darwin_arm64 的软件包。
\n
此处记录:https://discuss.hashicorp.com/t/template-v2-2-0-does-not-have-a-package-available-mac-m1/35099
\n具体来说,即使我没有使用 template_file 或来自该提供程序的任何其他实体,terraform 仍然尝试安装 hashcorp/template 提供程序;我尝试删除 .terraform 和我的锁定文件,但仍然遇到此问题:
\nInitializing provider plugins...\n- terraform.io/builtin/terraform is built in to Terraform\n- Finding latest version of hashicorp/template...\n- Finding hashicorp/aws versions matching "~> 3.0"...\n- Finding latest version of hashicorp/random...\nRun Code Online (Sandbox Code Playgroud)\n 我正在尝试使用 terraform 将以下策略添加到 iam 用户。如何在 upload_user_user 的策略中添加帐户 ID?
resource "aws_iam_user" "product_upload_user" {
name = "cc-${terraform.workspace}-product-upload-user"
}
resource "aws_iam_user_policy" "allow_upload" {
user = aws_iam_user.product_upload_user.name
policy = data.aws_iam_policy_document.allow_upload.json
}
data "aws_iam_policy_document" "allow_upload" {
statement {
sid = "STSToken"
effect = "Allow"
actions = ["sts:GetFederationToken"]
# resources = ["arn:aws:sts::${aws_iam_user.product_upload_user.<account_id>}:federated-user/S3UploadWebToken"]
}
}
Run Code Online (Sandbox Code Playgroud)
尝试实施本教程中的策略:https://next-s3-upload.codingvalue.com/setup
amazon-web-services amazon-iam terraform terraform-provider-aws
我有一个 aws_scheduler_schedule,计划每分钟向 Lambda 函数发送一条消息,如下所示:
resource "aws_scheduler_schedule" "event_scheduler" {
name = "${var.environment}-${var.account_name}-${var.service_name}-scheduler"
flexible_time_window {
mode = "OFF"
}
schedule_expression = "rate(1 minute)"
target {
arn = var.lambda_arn
role_arn = aws_iam_role.iam_for_eventbridge.arn
input = jsonencode({
MessageBody = "check_expired"
})
}
}
Run Code Online (Sandbox Code Playgroud)
我想限制 aws_scheduler_schedule 的 aws_iam_role,这样它只允许上述调度程序进行 sts:AssumeRole。这是我的 aws_iam_role 代码:
resource "aws_iam_role" "iam_for_eventbridge" {
name = "${var.environment}-${var.account_name}-${var.service_name}-eventbridge-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "scheduler.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "${aws_scheduler_schedule.event_scheduler.arn}"
}
}
]
} …Run Code Online (Sandbox Code Playgroud) 您好,我正在尝试使用 terraform 模块导入现有资源 terraform-aws-modules/vpc/aws
这是我的模块定义
\nmodule "vpc" {\n source = "terraform-aws-modules/vpc/aws"\n\n name = "eks-dev"\n cidr = "10.0.0.0/16"\n\n azs = ["us-east-1b", "us-east-1a"]\n public_subnets = ["10.0.2.0/24", "10.0.1.0/24"]\n\n enable_nat_gateway = false\n enable_vpn_gateway = false\n\n tags = {\n Terraform = "true"\n Environment = "dev"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n当我执行计划时
\n # module.vpc.module.vpc.aws_vpc.this[0] will be created\n + resource "aws_vpc" "this" {\n + arn = (known after apply)\n + cidr_block = "10.0.0.0/16"\n + default_network_acl_id = (known after apply)\n + default_route_table_id = (known after apply)\n + default_security_group_id …Run Code Online (Sandbox Code Playgroud) 我正在构建一个 Cloudwatch 触发器,以在工作周(周一至周五)的 9 点至 17 点(上午 9 点至下午 5 点)之间每小时触发一次
Terraform 向我抛出此错误:
ValidationException: Parameter ScheduleExpression is not valid.
Run Code Online (Sandbox Code Playgroud)
这是我的时间表表达式:schedule_expression = "cron(0 9-17 * * MON-FRI *)"
有谁知道为什么无效?
我们遵循 AWS DynamoDB 的单表架构,并使用单个表来存储所有实体。
我们有在我们这里注册车辆的用户,表结构如下:
| 用户身份 | 实体ID | 实体类型 |
|---|---|---|
| 1 | 1 | 车 |
| 1 | 2 | 自行车 |
和关键属性:
partition_key=user_idsort_key=entity_id现在,我们需要仅获取汽车、自行车或任何其他车辆,user_id我想为其添加本地二级索引,并使用现有分区键(以实体类型作为排序键)。
在应用此更改时,它正在尝试重新创建表。
由于现有表中已有数据,有什么方法可以避免重新创建表吗?
amazon-web-services amazon-dynamodb terraform amazon-dynamodb-index
我想根据 .tfvars 文件的条件创建 Spot 实例。否则我想要一个常规的 ec2 实例。我知道有一个三元条件,但不确定如何正确使用它。
spot = var.spot_instance ? instance_market_options {
market_type = "spot"
} :
Run Code Online (Sandbox Code Playgroud)
resource "aws_launch_template" "foo" {
name = "foo"
iam_instance_profile {
name = "test"
}
image_id = "ami-test"
instance_market_options {
market_type = "spot"
}
instance_type = "t2.micro"
}
Run Code Online (Sandbox Code Playgroud)
或者可能是这个?
instance_market_options = var.spot_instance ? {
market_type = "spot"
} :
Run Code Online (Sandbox Code Playgroud) amazon-ec2 amazon-web-services terraform terraform-provider-aws