我正在尝试使用 terraform 创建一个 AWS lambda 函数。我的 terraform 目录看起来像
我的 lambda 函数存储在/terraform/lambda/files/lambda_function.py 中。
每当我应用 terraform 时,我都有一个“null_resource”,它会在本地机器上执行一些命令来压缩 python 文件
variable "pythonfile" {
description = "lambda function python filename"
type = "string"
}
resource "null_resource" "lambda_preconditions" {
triggers {
always_run = "${uuid()}"
}
provisioner "local-exec" {
command = "rm -rf ${path.module}/files/zips"
}
provisioner "local-exec" {
command = "mkdir -p ${path.module}/files/zips"
}
provisioner "local-exec" {
command = "cp -R ${path.module}/files/${var.pythonfile} ${path.module}/files/zips/lambda_function.py"
}
provisioner "local-exec" { …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda terraform terraform-provider-aws
我RDS为我的开发团队编写了一个自定义模块,用于部署RDS实例。我正在使用BitBucket源代码控制,并且我正在尝试集成一个BitBucket管道以terraform validate在我的.tf文件上运行以验证语法,然后再将其提供给开发人员使用。terraform init运行良好,但是当我运行时terraform validate出现以下错误:Error: Missing required argument. The argument "region" is required, but was not set.查看文档后,我很困惑,如果该命令实际上没有部署任何内容,为什么会检查已声明的提供程序?诚然,我是编写模块的新手。也许这不是我想要完成的正确命令?
Terraform version: v0.12.7
AWS Provider version: 2.24
bitbucket-pipelines.yml:
image: hashicorp/terraform:full
pipelines:
branches:
master:
- step:
script:
- terraform version
- terraform init
- terraform validate
Run Code Online (Sandbox Code Playgroud)
Module tree:
??? CHANGELOG.md
??? README.md
??? bitbucket-pipelines.yml
??? main.tf
??? modules
? ??? db_instance
? ? ??? README.md
? ? …Run Code Online (Sandbox Code Playgroud) bitbucket continuous-deployment terraform terraform-provider-aws
我们将最新批准的 AMI 存储在 AWS 参数存储中。使用 Terraform 创建新实例时,我想以编程方式获取此 AMI ID。我有一个命令来提取 AMI ID,但我不确定如何将它与 Terraform 一起使用。
这是我用来提取 AMI ID 的命令:
$(aws ssm get-parameter --name /path/to/ami --query 'Parameter.Value' --output text)
Run Code Online (Sandbox Code Playgroud)
这是我的 Terraform 脚本:
resource "aws_instance" "nginx" {
ami = "ami-c58c1dd3" # pull value from parameter store
instance_type = "t2.micro"
#key_name = "${var.key_name}"
provisioner "remote-exec" {
inline = [
"sudo yum install nginx -y",
"sudo service nginx start"
]
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用命令在 Terraform 脚本中提取 AMI ID?
我正在使用 Terraform 来启动我的云环境。
似乎即使是很小的配置更改也会影响幕后的许多资源。
例如,在我创建 AWS 实例的情况下 - 一个小的更改将导致所有实例的自动生成:
-/+ aws_instance.DC (new resource required)
id: "i-075deb0aaa57c2d" => <computed> (forces new resource) <----- How can we avoid that?
ami: "ami-01e306baaaa0a6f65" => "ami-01e306baaaa0a6f65"
arn: "arn:aws:ec2:ap-southeast-2:857671114786:instance/i-075deb0aaa57c2d" => <computed>
associate_public_ip_address: "false" => <computed>
availability_zone: "ap-southeast-2a" => <computed>
.
.
Run Code Online (Sandbox Code Playgroud)
我的问题特别与作为提供者的 AWS 相关:
我们如何避免每次破坏/创建资源?
也许是 Terraform 中的相关标志?
相关主题:
Terraform > ipv6_address_count: "" => "0"(强制新资源)
编辑:
深入了解计划输出,其中一项资源似乎发生了变化:
security_groups.#: "0" => "1" (forces new resource)
security_groups.837544107: "" => "sg-0892062659392afa9" (forces new resource) …Run Code Online (Sandbox Code Playgroud) 我使用在 Docker Compose 上运行的开源服务器应用程序。它有一些服务,包括 PostgreSQL DB 和 Redis。
如何使用 Terraform 在完整的 IaC 中最好地将此应用程序部署到 AWS?
ecs-cliecs-cli现在支持docker compose在 Amazon ECS 中发送配置。
但是,我不认为它可以与 Terraform 工作流程集成(这可能不是什么大惊小怪)。我知道肯定是,ecs-cli是不是在CloudFormation支持,按照这一问题在这个时候,仍然打开。所以我认为它也不能轻易添加到 Terraform。
docker-compose.yml文件,将其转换为kubectlYAML。但这还不是完全的 IaC。每次 docker-compose 在源存储库中更改时,您都必须重新翻译您的配置。这听起来像很多工作。
helm 提供程序运行 Terraform 以在集群上安装带有 Helm …docker-compose kubernetes-helm apache-superset terraform-provider-aws amazon-eks
我的简单 terraform 文件是:
provider "aws" {
region = "region"
access_key = "key"
secret_key = "secret_key"
}
terraform {
backend "s3" {
# Replace this with your bucket name!
bucket = "great-name-terraform-state-2"
key = "global/s3/terraform.tfstate"
region = "eu-central-1"
# Replace this with your DynamoDB table name!
dynamodb_table = "great-name-locks-2"
encrypt = true
}
}
resource "aws_s3_bucket" "terraform_state" {
bucket = "great-name-terraform-state-2"
# Enable versioning so we can see the full revision history of our
# state files
versioning {
enabled = …Run Code Online (Sandbox Code Playgroud) 我想将 EFS 与 fargate 一起使用,但在任务开始时出现此错误:
ResourceInitializationError: failed to invoke EFS utils commands to set up EFS volumes: stderr: Failed to resolve "fs-xxxxx.efs.eu-west-1.amazonaws.com" - check that your file system ID is correct
Run Code Online (Sandbox Code Playgroud)
我已经检查了文件系统 ID,它是正确的...我如何获得有关此错误的更多信息?它可能与安全组有关吗?
这是我与 terraform 一起使用的代码,我为两个可用区使用了两个挂载点:
resource "aws_efs_file_system" "efs_apache" {
}
resource "aws_efs_mount_target" "efs-mount" {
count = 2
file_system_id = aws_efs_file_system.efs_apache.id
subnet_id = sort(var.subnet_ids)[count.index]
security_groups = [aws_security_group.efs.id]
}
resource "aws_efs_access_point" "efs-access-point" {
file_system_id = aws_efs_file_system.efs_apache.id
}
resource "aws_security_group" "efs" {
name = "${var.name}-efs-sg"
description = "Allow traffic from self"
vpc_id …Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform amazon-efs aws-fargate terraform-provider-aws
有谁知道是否有可能用代码片段来表示我是否可以在 terraform 变量的地图变量中创建地图变量?
variable "var" {
type = map
default = {
firstchoice = {
firstAChoice ="foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人对这是否可行或任何详细说明的文档有任何见解,那就太好了。
我想知道我们如何停止和重新启动使用 terraform 创建的 AWS ec2 实例。有没有办法做到这一点?
使用 terraform v0.12.21 和 AWS provider v2.51.0,我试图从头开始创建一些基础设施(没有以前的 terraform 状态)。
目标是在单个 VPC 中拥有一些可公开访问的 EC2 实例,我认为这些是我需要完成的资源:
使用这个 terraform 配置:
locals {
office_cidr = ["x.x.x.x/32", "x.x.x.x/32"]
}
provider "aws" {
region = var.region
version = "~> 2.51"
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.main.id
}
resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
}
resource "aws_route_table" …Run Code Online (Sandbox Code Playgroud) terraform ×9
amazon-ec2 ×1
amazon-efs ×1
amazon-eks ×1
aws-fargate ×1
aws-lambda ×1
bitbucket ×1
routing ×1
variables ×1
vpc ×1