标签: terraform

AWS 安装失败:IAM 实例配置文件已存在

我使用安装程序预配置基础设施 (IPI) 在我的 AWS 集群上安装 openshift 4.4.9,但未能成功在 AWS 上启动我的 openshift 集群。由于以下错误。

INFO Creating infrastructure resources...
ERROR
ERROR Error: Error creating IAM instance profile ocp4-925gm-bootstrap- 
 profile: EntityAlreadyExists: 
Instance Profile ocp4-925gm-bootstrap-profile already exists.
ERROR   status code: 409, request id: b6918967-774c-44c1-8b92-02ac7388f87c
ERROR
ERROR   on ../../../tmp/openshift-install-584826335/bootstrap/main.tf line 46, in resource 
"aws_iam_instance_profile" "bootstrap":
 ERROR   46: resource "aws_iam_instance_profile" "bootstrap" {

ERROR Error: Error creating IAM instance profile ocp4-925gm-worker-profile: EntityAlreadyExists: 
Instance Profile ocp4-925gm-worker-profile already exists.
ERROR   status code: 409, request id: 3b5d2b9c-28fe-4c95-b622-7a80af45dfb6
ERROR
ERROR   on ../../../tmp/openshift-install-584826335/iam/main.tf line …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services openshift aws-cli terraform terraform-provider-aws

1
推荐指数
1
解决办法
5050
查看次数

如何使用 terraform 自动为我的 ec2 实例创建备份计划

鉴于我有 2 个由 terraform 创建的实例

resource "aws_instance" "web1" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  tags = {
    Name = "web1"
  }
}

resource "aws_instance" "web2" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  tags = {
    Name = "web2"
  }
}
Run Code Online (Sandbox Code Playgroud)

我如何使用 terraform 为他们创建备份计划?

backup amazon-web-services terraform terraform-provider-aws

1
推荐指数
1
解决办法
3095
查看次数

terraform 可以复制 s3 存储桶的内容吗?

我正在使用 terraform 来管理我们应用程序的 aws 环境。环境有用于各种事物的 s3 存储桶。在设置新环境时,我只想从基本源存储桶或现有环境中复制存储桶。

但我找不到任何可以提供副本的内容。AWS 界面允许您在创建时复制设置(我不需要),但不能复制对象,因此 terraform 可能无法直接执行此操作。

如果是的话,间接的怎么样?

amazon-s3 amazon-web-services terraform

1
推荐指数
1
解决办法
3904
查看次数

使用 count 后在 terraform 中创建条件资源

我正在为字符串变量的给定值中的每个服务创建一个route53运行状况检查services

tfvars当我传递 services 变量的值时,我的文件如下所示

services = "servicea serviceb serviced"

我只需要进行这些健康检查,如果var.env == prod

有一种经过尝试和测试的方法可以使用,并且将会使用,count = var.env == prod ? 1:0但由于我已经使用 count 来计算和迭代服务字符串,我无法count在同一资源块中再次使用,因为 terraform 0.12 给了我以下错误如果我想这样做,请留言。

在同一资源块中使用多个计数时出错

Error: Attribute redefined

  on <stdin> line 514:   (source code not available)

The argument "count" was already set at <stdin>:513,2-7. Each argument may be set only once.
Run Code Online (Sandbox Code Playgroud)

地形配置


variable "services" {
  default = ""
}


resource aws_route53_health_check "app_healthcheck" {
  count             = length(split(",", replace(var.services, "/\\s/", ",")))
  fqdn              = …
Run Code Online (Sandbox Code Playgroud)

amazon-route53 terraform terraform0.12+

1
推荐指数
1
解决办法
1万
查看次数

AWS Golang S3 管理器上传:访问被拒绝

我正在使用 S3 上传管理器将大文件上传到 S3。

if _, err := uploader.UploadWithContext(ctx, &s3manager.UploadInput{
        Bucket:          aws.String(s.Config.GetS3ExportBucket()),
        Key:             aws.String(key),
        Body:            bytes.NewReader(buf.Bytes()),
        ContentEncoding: aws.String("gzip"),
        ContentType:     aws.String("application/json"),
    }); err != nil {
        return fmt.Errorf("failed to upload file, %w", err)
    }
Run Code Online (Sandbox Code Playgroud)

根据AWS 文档,我也向我的 lambda 提供了权限。

#Created Policy for IAM Role
resource "aws_iam_policy" "s3_write_policy" {
  name        = "${local.namespace}-s3-write-access"
  description = "Allow Lambda to access s3 where back will be written"
  policy      = data.aws_iam_policy_document.s3_write_policy.json
}

data "aws_iam_policy_document" "s3_write_policy" {
  statement {
    sid       = "WriteObjectActions"
    effect    = "Allow"
    actions …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 go amazon-web-services aws-lambda terraform

1
推荐指数
1
解决办法
1410
查看次数

Terraform 使用局部变量而不是输入变量动态创建地图

要求:我有一堆 EC2。我根据标签对其进行分组。在此示例中,组总数 = 4,每个组有 7 个 EC2:1 个父级 - 6 个子级。在这里我分享一个命名很重要的孩子的代码。

工作代码:这里我分享子 EC2 代码,该代码与名为 :ws_to_Child_Node_name_map_count 的地图类型的输入变量完美配合。现在我希望它是可扩展的(父子数量),我希望使用“在本地动态创建的地图”而不是使用输入变量。主.tf

resource "aws_instance" "ec2_instance_child" {
  count                   = var.ec2_instance_child_count
  tags = {
    NodeName       = "${lookup(var.ws_to_Child_Node_name_map_count, count.index+1, 99)}"
  }
}
Run Code Online (Sandbox Code Playgroud)

变量.tf

variable "ws_to_Child_Node_name_map_count"  {
  type = map
  default = {
      "1"="1"
      "2"="2"
      "3"="3"
      "4"="4"
      "5"="5"
      "6"="6"
      "7"="1"
      "8"="2"
      "9"="3"
      "10"="4"
      "11"="5"
      "12"="6"
      "13"="1"
      "14"="2"
      "15"="3"
      "16"="4"
      "17"="5"
      "18"="6"
      "19"="1"
      "20"="2"
      "21"="3"
      "22"="4"
      "23"="5"
      "24"="6"
    }
  }
variable "ec2_instance_child_count" {
  description = "Number of instances to run"
  default …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-aws terraform0.12+

1
推荐指数
1
解决办法
2万
查看次数

有terraform的测试环境吗?

想知道是否有一些 terraform 测试网站,这些网站并不是真正测试 terraform 资源的输出,而是测试一些变量,例如给定的:一些输入

x = [
    {
      name = first
      condition = {
        age = "1"
      }
      action = {
        type = "Delete"
      }
    },{
      name: second
      condition = {
        age = "2"
      }
      action = {
        type = "Delete"
      }
   }
]
Run Code Online (Sandbox Code Playgroud)

想要测试如何在在线实时运行时获取第二个变量

类似于 regex.101.com

terraform

1
推荐指数
1
解决办法
3638
查看次数

迭代字典列表以创建具有不同值的地形资源

目标使用 terraform 创建两个aws_athena_named_query资源。每个查询的配置在单独的字典中定义。所有查询字典都嵌套在一个列表中(请参阅query_dict变量)。

variable query_dict {
    default = [
        {
            name = "query1"
            workgroup = "bar"
            query = "SELECT * FROM foo"   
        },
        {
            name = "query2"
            workgroup = "bar"
            query = "SELECT * FROM baz"   
        }
    ]
}

resource "aws_athena_named_query" "olap" {
  for_each = toset([for query in var.query_dict: {
            name   = query.name
            workgroup = query.workgroup
            query = query.query}])
  name = each.value.name
  query = each.value.query
  database = "test"
  workgroup = each.value.workgroup
}
Run Code Online (Sandbox Code Playgroud)

这会导致错误:

The given …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform terraform0.12+

1
推荐指数
1
解决办法
1万
查看次数

如何在 terraform 中连接变量和字符串?

我是 terraform 的新手,尝试将变量添加到字符串中,假设 id = "abcde", host =~ ${id} + "id", 应该返回 abcdeid 在 terraform 中实现此目的的最佳方法是什么?

terraform

1
推荐指数
1
解决办法
9370
查看次数

Terraform if 语句为 true 或 false

我需要准备 if 语句。我想知道最好的解决方案是什么?

locals {
  prod_ingress_certyficate  = "${prod_ingress_certyficate == "true" ? var.prod_cert : var.test_cert}"
}
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?如果变量为 true,则使用 prod_cert,如果为 false,则使用 test_cert。

terraform

1
推荐指数
1
解决办法
6411
查看次数