我正在与 Terraform V11 和 AWS 提供商合作;我正在寻找一种方法来防止在销毁阶段销毁少量资源。所以我使用了以下方法。
lifecycle {
prevent_destroy = true
}
Run Code Online (Sandbox Code Playgroud)
当我运行“terraform plan”时,出现以下错误。
the plan would destroy this resource, but it currently has
lifecycle.preven_destroy set to true. to avoid this error and continue with the plan.
either disable or adjust the scope.
Run Code Online (Sandbox Code Playgroud)
我正在寻找的只是一种避免在 destroy 命令期间破坏其中一个资源及其依赖项的方法。
我看过几个链接,但我必须看一个例子。我有:
resource "aws_iam_role" "role" {
name = "role"
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1590217939125",
"Action": "s3:*",
"Effect": "Allow",
"Resource": "arn:aws:s3:::wwe"
},
{
"Sid": "Stmt1590217939125",
"Action": "s3:*",
"Effect": "Allow",
"Resource": "arn:aws:s3:::wwe/*"
},
{
"Sid": "Stmt1577967806846",
"Action": [
"secretsmanager:DescribeSecret",
"secretsmanager:GetRandomPassword",
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:ListSecretVersionIds",
"secretsmanager:ListSecrets"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
tags = {
Name = wwe
Environment = STAGE
}
}
Run Code Online (Sandbox Code Playgroud)
当我在制作时,
terraform apply
Run Code Online (Sandbox Code Playgroud)
我看到这个:
# aws_iam_role.role will be created
+ resource "aws_iam_role" "role" …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-iam terraform terraform-provider-aws
我试图找出每当有人执行操作时通知一个松弛通道
terraform apply
Run Code Online (Sandbox Code Playgroud)
我已经浏览过https://github.com/terraform-aws-modules/terraform-aws-notify-slack,但这专门讨论了云监视警报。我正在考虑一些简单的事情,我可以在成功的 terraform 应用结束时通过调用 webhook 向 slack 发送类似通知之类的内容。
有人可以给我指出某个方向吗,我可以开发一些东西来解决这个问题。只是指针也会有帮助。
deploy我正在尝试创建一个管道来部署在 Beanstalk 上,但我经常在管道部分遇到错误:
Insufficient permissions
The provided role does not have sufficient permissions to access
Elastic Beanstalk: Access Denied
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
/************************************************
* Code Build
***********************************************/
resource "aws_codebuild_project" "project-name-codebuild" {
name = "${var.project}-codebuild"
build_timeout = "15"
service_role = "${aws_iam_role.project-name-codebuild-role.arn}"
artifacts {
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
type = "LINUX_CONTAINER"
image = "aws/codebuild/java:openjdk-8"
}
source {
type = "CODEPIPELINE"
}
tags {
Name = "${var.project}"
Environment = "${var.environment}"
}
}
resource "aws_ecr_repository" "project-name-ecr-repository" {
name = "${var.project}-ecr-repository" …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-elastic-beanstalk terraform aws-codepipeline terraform-provider-aws
我正在尝试为开发和 QA 环境配置我的 terraform,每个环境都有自己的安全组,我用data:
data "aws_security_group" "ssh" {
name = "SG-SSH"
}
data "aws_security_group" "postgres" {
name = "SG-Postgres"
}
Run Code Online (Sandbox Code Playgroud)
有没有办法根据目标环境指定拉入哪些安全组?我试过这个:
locals {
sgs = {
dev = ["${data.aws_security_group.postgres.id}", "${data.aws_security_group.ssh.id}"]
qa = ["${data.aws_security_group.postgres.id}"]
}
}
Run Code Online (Sandbox Code Playgroud)
然后我用 来引用"${local.sgs[var.env]}"。但是,ssh安全组仅存在于开发环境中,因此当我针对 QA 环境时,我仍然得到:
data.aws_security_group.ssh: data.aws_security_group.ssh: no matching SecurityGroup found
Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform aws-security-group terraform-provider-aws
terraform 是否提供此类功能来覆盖变量值?假设我声明了下面给出的两个变量。
variable "foo" {}
variable "bar" { default = "false"}
Run Code Online (Sandbox Code Playgroud)
foo是强制性的,并bar分配有默认值false。terraform 中是否有resoruce可用的值可以重新分配或覆盖该bar值?我是从resource角度来问这个问题的。我知道我可以使用terraform-modules.
我尝试过这种用法null_resource,但没有得到预期的结果。它仍然返回默认值。
resource "null_resource" "this" {
provisioner "local-exec" {
command = "echo ${var.env} > ${var.newvar}"
}
}
Run Code Online (Sandbox Code Playgroud)
我还想curl在命令属性中运行。我需要使用“口译员吗?” 如果是这样,那么它的价值是什么?
interpreter = ["shell","?"]我应该传递哪些值来curl在配置程序中执行命令local-exec。
bash脚本
function check_efs() {
curl -ls https://elasticfilesystem.us-east-1.amazonsaws.com
if [ $? -eq 0 ]; then
output=1
else:
output=0
}
function produce_output() {
value=$(output) …Run Code Online (Sandbox Code Playgroud) 有人可以指出使用实例参数之间的区别吗:
并使用资源:
aws_ebs_volume + aws_volume_attachment
从 terraform 文档来看,似乎达到了相同的结果。当我们谈论基础设施管理时,我想提前知道其中的细微差别,但找不到任何差异。
如果有人能指出每个问题的陷阱和用例,我将不胜感激。
在这个答案的后面,我试图创建一个aws_iam_role允许访问 ECR 的。但是,当我定义以下内容时:
resource "aws_iam_role" "jenkins_ecr_role" {
name = "JenkinsECRRole"
assume_role_policy = <<END_OF_POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecr.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
END_OF_POLICY
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Error: Error creating IAM Role JenkinsECRRole:
MalformedPolicyDocument: Invalid principal in policy: "SERVICE":"*"
Run Code Online (Sandbox Code Playgroud)
ecr.amazonaws.com根据 AWS 文档,它看起来是一个有效的委托人。我究竟做错了什么?
amazon-web-services amazon-iam terraform amazon-ecr terraform-provider-aws
使用一个 .tf 文件,其中包括创建 s3 存储桶、ec2 和安全组,我担心的是,如果我运行 terraform apply 并且它在中间中止后成功创建了 s3 存储桶。在上面的情况下,我想回滚 terraform apply 运行后发生的所有更改。
一旦 .tf 文件开始运行,我就中止该进程,但更改不会回滚。
provider "aws" { }
resource "aws_instance" "example" {
ami = "ami-2757f631"
instance_type = "t2.micro"
}
resource "aws_s3_bucket" "b" {
bucket = "my-tf-test-bucket"
acl = "private"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
resource "aws_security_group" "allow_rdp" {
name = "allow_rdp"
description = "Allow rdp traffic"
ingress {
from_port = 3389 # By default, the windows server listens on TCP …Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services terraform terraform-provider-aws
与其他几位发布到 StackOverflow 的用户一样,我遇到了文件配置程序的问题,Terraform 文档说我们不应该依赖它们。
解决文件配置程序(特别是本地配置文件和脚本)的最佳方法是什么?