我正在尝试在 Terraform (v 0.13.0) 中设置我当前的基础设施。我只是从迁移现有的 lambda 函数开始。我已使用以下代码尝试将 .net core 3.1 中的现有 lambda 函数上传到 AWS(provider v.3.0)。我手动部署没有问题,但这显然不是目标。
这是 IAM 角色:
resource "aws_iam_role" "role_lambda" {
name = "roleLambda"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
Run Code Online (Sandbox Code Playgroud)
在函数下方(注意我混淆了一些值):
resource "aws_lambda_function" "lambda_tf" {
function_name = "LambdaTFTest"
role = aws_iam_role.role_lambda.arn
handler = "Lambda::Lambda.Function::FunctionHandler"
runtime = "dotnetcore3.1"
s3_bucket = "arn:aws:s3:::xxxx-xxxxxx"
s3_key = "Lambda.zip"
s3_object_version = "XxXxXxXxXxXxXxXxXxXxXxXxXxXx"
}
Run Code Online (Sandbox Code Playgroud)
但是,我不断收到此错误作为输出,但没有更多详细信息:
Error: Error …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda terraform terraform-provider-aws
在 terraform 中有一个在 aws 中创建 EC2 机器的示例。
# Create a new instance of the latest Ubuntu 20.04 on an
# t3.micro node with an AWS Tag naming it "HelloWorld"
provider "aws" {
region = "us-west-2"
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = { …Run Code Online (Sandbox Code Playgroud) 我有以下文件夹结构:
\ninfrastructure\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80security-groups\n\xe2\x94\x82 \xe2\x94\x82 main.tf\n\xe2\x94\x82 \xe2\x94\x82 config.tf\n\xe2\x94\x82 \xe2\x94\x82. security_groups.tf\n\xe2\x94\x82 \n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80instances\n \xe2\x94\x82 main.tf\n \xe2\x94\x82 config.tf\n \xe2\x94\x82 instances.tf\nRun Code Online (Sandbox Code Playgroud)\n我想通过引用来引用 security-groups 文件夹中实例化的安全组 ID。\n我尝试使用以下命令在 security_groups.tf 文件中输出所需的 ID
\noutput "sg_id" {\n value = "${aws_security_group.server_sg.id}"\n}\nRun Code Online (Sandbox Code Playgroud)\n然后在实例文件中将其添加为模块:
\nmodule "res" {\n source = "../security-groups"\n}\nRun Code Online (Sandbox Code Playgroud)\n这种方法的问题是,当我在实例文件夹中执行 terraform apply 时,它也会尝试创建安全组(我已经通过在安全组文件夹中执行 terraform apply 创建了安全组),但它失败了,因为 SG 是现存的。
\n在不更改代码结构的情况下引用在不同文件夹中创建的资源的最简单方法是什么?
\n谢谢。
\n通过以下内容,我可以循环遍历资源块,轻松地将路由表关联添加到“所有”子网。但是,我只需要为我的公共子网创建关联。
我怎样才能使这个“if”语句起作用?或者任何其他方式来过滤each.value.class == "pub"此事。
resource "aws_route_table_association" "rtb-pub" {
for_each = local.subnets_map
if each.value.class == "pub" ## <---- how?
route_table_id = aws_route_table.rtb-pub.id
subnet_id = aws_subnet.map["${each.value.subnet}"].id
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在使用 terraform 创建一个安全组,当我运行 terraform 计划时。它给我一个错误,比如某些字段是必需的,而所有这些字段都是可选的。
\n地形版本:v1.0.5
\nAWS 提供商版本:v3.57.0
\n\n\n主.tf
\n
resource "aws_security_group" "sg_oregon" {\n name = "tf-sg"\n description = "Allow web traffics"\n vpc_id = aws_vpc.vpc_terraform.id\n\n ingress = [\n {\n description = "HTTP"\n from_port = 80\n to_port = 80\n protocol = "tcp"\n cidr_blocks = ["0.0.0.0/0"] \n },\n {\n description = "HTTPS"\n from_port = 443\n to_port = 443\n protocol = "tcp"\n cidr_blocks = ["0.0.0.0/0"] \n },\n\n {\n description = "SSH"\n from_port = 22\n to_port = 22\n protocol …Run Code Online (Sandbox Code Playgroud) 我正在设置一个 terraform 模块来创建一个 Aurora 集群。
我需要有一个跨区域复制的选项,所以我需要决定与源区域相关的副本区域。
有没有办法在 terraform 中做一个有条件的多选项?
您好,我想知道我们是否可以通过电子邮件订阅从 Terraform 添加 SNS 主题。
\n因此,使用一个 \xe2\x80\x9cTerraform apply\xe2\x80\x9d 命令可以轻松设置警报并创建 SNS 主题以将警报发送到电子邮件。
\n谢谢
\nThe plugin logs may contain more details
我正在尝试在 terraform 中的 aws 上的 eu-central-1 区域中部署 EKS 集群。\n我在这里做错了什么?\n这是我的提供商:
\nprovider "aws" {\n region = "eu-central-1"\n}\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x9d\xaf terraform validate\n\xe2\x95\xb7\n\xe2\x94\x82 Error: Plugin did not respond\n\xe2\x94\x82\n\xe2\x94\x82 with provider["registry.terraform.io/hashicorp/aws"],\n\xe2\x94\x82 on provider.tf line 1, in provider "aws":\n\xe2\x94\x82 1: provider "aws" {\n\xe2\x94\x82\n\xe2\x94\x82 The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ValidateProviderConfig call. The plugin logs may contain more details.\nRun Code Online (Sandbox Code Playgroud)\n 我有要在AWS中使用Terraform部署的基础架构。该基础架构可以部署到我正在使用工作空间的不同环境中。
应该为每个工作区分别创建部署中的大多数组件,但是我希望在它们之间共享几个关键组件,主要是:
例如:
resource "aws_iam_role" "lambda_iam_role" {
name = "LambdaGeneralRole"
policy = <...>
}
resource "aws_lambda_function" "my_lambda" {
function_name = "lambda-${terraform.workspace}"
role = "${aws_iam_role.lambda_iam_role.arn}"
}
Run Code Online (Sandbox Code Playgroud)
第一个资源是IAM角色,应在该Lambda的所有实例之间共享,并且不应重复创建一次。
第二个资源是Lambda函数,其名称取决于当前工作空间,因此每个工作空间都将部署并跟踪不同Lambda的状态。
如何在不同的Terraform工作空间之间共享资源及其状态?
我想将多个文件从本地设备中的特定文件夹上传到 AWS S3。我遇到了以下错误。

这是我的 terraform 代码。
resource "aws_s3_bucket" "testbucket" {
bucket = "test-terraform-pawan-1"
acl = "private"
tags = {
Name = "test-terraform"
Environment = "test"
}
}
resource "aws_s3_bucket_object" "uploadfile" {
bucket = "test-terraform-pawan-1"
key = "index.html"
source = "/home/pawan/Documents/Projects/"
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?