是否有任何脚本可以自动格式化永久性磁盘并将其附加到 Google Cloud VM 实例,而不是执行格式化和安装步骤?
永久性磁盘是使用 Terraform 创建的,它还会创建一个 VM 并使用attached_disk命令将磁盘附加到它。
我希望在 VM 实例启动时运行一个简单的脚本:
google-compute-engine google-cloud-platform terraform terraform-provider-gcp
我正在尝试使用 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?
我正在编写用于为 AWS StepFunctions 创建 IAM 角色的 terraform。应该是什么价值主要 在assume_role_policy
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "stepfunctions.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
Run Code Online (Sandbox Code Playgroud)
我收到错误
错误:创建 IAM 角色 my_utility_sfn 时出错:MalformedPolicyDocument:策略中的委托人无效:“SERVICE”:“stepfunctions.amazonaws.com”
我的简单 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) 有没有办法有条件地添加statement块aws_iam_policy_document?我正在寻找类似的东西:
data "aws_iam_policy_document" "policy" {
statement {
sid = "PolicyAlways"
...
}
if (var.enable_optional_policy) {
statement {
sid = "PolicySometimes"
...
}
}
}
Run Code Online (Sandbox Code Playgroud) 我们有 cronjob 和 shell 脚本,我们希望在使用 terraform 创建实例时将它们复制或上传到 aws ec2 实例。
我们尝试了
provisioner "file" {
source = "abc.sh"
destination = "/home/ec2-user/basic2.sh"
}
Run Code Online (Sandbox Code Playgroud)
data "template_file" "userdata_line" {
template = <<EOF
#!/bin/bash
mkdir /home/ec2-user/files2
cd /home/ec2-user/files2
sudo touch basic2.sh
sudo chmod 777 basic2.sh
base64 basic.sh |base64 -d >basic2.sh
EOF
}
Run Code Online (Sandbox Code Playgroud)
尝试了所有选项,但没有一个工作。
你能帮忙或建议吗?
我是 terraform 的新手,长期以来一直在这方面苦苦挣扎。
我想将 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 0.12 升级到 0.13。
当我运行时,它似乎没有任何特定的语法问题terraform 0.13upgrade。
只version.tf添加了一个文件
+terraform {
+ required_providers {
+ aws = {
+ source = "hashicorp/aws"
+ }
+ }
+ required_version = ">= 0.13"
+}
Run Code Online (Sandbox Code Playgroud)
当我跑步时,terraform plan我得到了
Error: Could not load plugin
Plugin reinitialization required. Please run "terraform init".
Plugins are external binaries that Terraform uses to access and manipulate
resources. The configuration provided requires plugins which can't be located,
don't satisfy the version constraints, or are otherwise …Run Code Online (Sandbox Code Playgroud)