我正在尝试在 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) 我正在使用 Terraform 为我们的应用程序创建应用程序注册和角色。但我不知道如何对二头肌做同样的事情。这是今天使用的:
步骤 1. 在 Active Directory 中注册应用程序,有效创建“应用程序注册”。
resource "azuread_application" "ad_app" {
name = local.full_app_name
type = "webapp/api"
owners = var.app_owners
}
Run Code Online (Sandbox Code Playgroud)
第 2 步:为我们的应用程序创建角色
resource "azuread_application_app_role" "person_read" {
application_object_id = azuread_application.ad_app.id
allowed_member_types = ["Application"]
description = "Person Reader can search and read persons"
display_name = "Person Reader"
value = "Persons.Read"
}
Run Code Online (Sandbox Code Playgroud)
问题是我不知道如何使用 Bicep(或 ARM 模板)执行这些步骤。我尝试过'Microsoft.Authorization/roleDefinitions',但似乎不对。我不知道如何进行应用程序注册。
azure-active-directory terraform azure-rm-template azure-bicep
google_project文档说project_id是可选的。
\n\n\nproject_id - (可选)项目 ID。如果未提供,则使用提供者项目。
\n
然而,Terraform 抱怨这是必需的。
\ngcp.tf
\ndata "google_project" "project" {\n}\n\noutput "project_number" {\n value = data.google_project.project.number\n}\nRun Code Online (Sandbox Code Playgroud)\n Error: project: required field is not set\n\xe2\x94\x82 \n\xe2\x94\x82 with data.google_project.project,\n\xe2\x94\x82 on gcp.tf line 1, in data "google_project" "project":\n\xe2\x94\x82 1: data "google_project" "project" {\nRun Code Online (Sandbox Code Playgroud)\n请帮助理解这是否是文档缺陷并且该参数实际上是强制性的。
\n设置 GOOGLE_PROJECT 环境变量。
\nexport GOOGLE_PROJECT=...\nterraform apply\nRun Code Online (Sandbox Code Playgroud)\n 将 terraform 升级到 后3.64.2,尽管我没有更改任何代码,但terraform plan提醒我它将替换tag为tag_all. tags和 和有什么不一样tags_all?
~ resource "aws_lb_listener" "frontend_http_tcp" {
id = "xxxxx"
~ tags = {
- "environment" = "production" -> null
- "purpose" = "onboarding-integration" -> null
- "terraform" = "true" -> null
}
~ tags_all = {
- "environment" = "production"
- "purpose" = "onboarding-integration"
- "terraform" = "true"
} -> (known after apply)
# (4 unchanged attributes hidden)
# (1 unchanged block hidden) …Run Code Online (Sandbox Code Playgroud) 我试图使用EC2容器服务.我正在使用terraform来创建它.我已经定义了ecs集群,自动缩放组,启动配置.一切似乎都有效.除了一件事.ec2实例正在创建,但它们没有在集群中注册,集群只是说没有实例可用.
在ecs agent登录创建的实例中,我发现日志充斥着一个错误:
注册时出错:NoCredentialProviders:链中没有有效的提供者
使用适当的角色ecs_role创建ec2实例.此角色有两个策略,其中一个是跟随的,如需要的文档:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:CreateCluster",
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:Submit*",
"ecs:StartTask"
],
"Resource": "*"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在使用ami ami-6ff4bd05.最新的terraform.
我已经看到很多关于如何使用Terraform启动AWS资源的示例.我也看到很多声称Terraform是云不可知的.
我没有看到的是我如何使用单个tf文件在AWS或Azure中使用某些子网,某些实例,某些ELB以及一些数据库启动VPC的示例.
有没有人有这样的例子?
Terraform可以配置自定义S3端点,似乎localstack可以为S3,SES,Cloudformation和其他少数服务创建本地堆栈.
问题是在Terraform配置中写什么来使用localstack的S3端点?
考虑一个terraform模块:
module "blah-asg" {
source = "asg"
asg_max_size = 1
asg_min_size = "${var.min_blah}"
...
}
Run Code Online (Sandbox Code Playgroud)
我怎么output变量呢?
output "blah-es-asg" {
value = "${asg.blah-asg.arn}"
}
Run Code Online (Sandbox Code Playgroud)
哪个失败了
获取插件时出错:模块root:发生1个错误:*输出'blah-asg':变量asg.blah-asg.arn中引用的未知资源'asg.blah'
如何在Terraform中输出模块字段?
我正在使用AWS VPC Terraform模块来创建VPC.此外,我想使用aws_internet_gateway资源创建Internet网关并将其连接到此VPC .
这是我的代码:
module "vpc" "vpc_default" {
source = "terraform-aws-modules/vpc/aws"
name = "${var.env_name}-vpc-default"
cidr = "10.0.0.0/16"
enable_dns_hostnames = true
}
resource "aws_internet_gateway" "vpc_default_igw" {
vpc_id = "${vpc.vpc_default.id}"
tags {
Name = "${var.env_name}-vpc-igw-vpcDefault"
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行时terraform init,我收到以下错误:
初始化模块... - module.vpc
错误:资源'aws_internet_gateway.vpc_default_igw'配置:变量vpc.vpc_default.id中引用的未知资源'vpc.vpc_default'
如何引用Terraform模块创建的资源?