标签: terraform

使用 Golang docker SDK - Interactive Container 接受用户输入 os.stdin 到容器

我最后的手段是在这里问。我是 Golang 的新手,我做过简单的程序。

我正在尝试执行以下操作:使用 golang:1 - 运行容器 2 - 接受输入标准输入到容器

我想使用的例子是hashicorp/terraform docker镜像,我想做一个简单的terraform apply 但是我需要等待用户输入

下面是我到目前为止工作的代码......任何尝试下面的确切代码的人都需要更新 AWS 环境变量或将 terraform 测试文件更改为另一个提供程序......或者只是使用不同的 docker 镜像 ;-)

package main

import (
    "fmt"
    "github.com/docker/docker/api/types"
    "github.com/docker/docker/api/types/container"
    "github.com/docker/docker/api/types/mount"
    "github.com/docker/docker/client"
    "github.com/docker/docker/pkg/stdcopy"
    "golang.org/x/net/context"
    "io"
    "os"
)

const workingDir = "/home"


func main() {
    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    if err != nil {
        panic(err)
    }

    reader, err := cli.ImagePull(ctx, "hashicorp/terraform", types.ImagePullOptions{})
    if err != nil {
        panic(err)
    }
    io.Copy(os.Stdout, reader)

    fmt.Println(os.Args)
    cwd, _ := os.Getwd()

    resp, …
Run Code Online (Sandbox Code Playgroud)

sdk stdin go docker terraform

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

gitlab-ci:Terraform 没有名为“sh”的命令。您指的是“展示”吗

我正在尝试在 Gitlab CI 上设置 Terrafom 验证。
但是,构建失败并显示错误:“Terraform 没有名为“sh”的命令。您的意思是“show”吗?”

为什么会发生这种情况?怎么解决呢?

我的.gitlab-ci.yml

image: hashicorp/terraform:light

before_script:
  - terraform init

validate:
  script:
    - terraform validate
Run Code Online (Sandbox Code Playgroud)

gitlab-ci terraform

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

aws_instance - 更改卷大小

我正在尝试增加我的 ami 的根卷的大小ami-0d013c5896434b38a- 我正在使用 Terraform 来配置它。

只是为了澄清 - 我只有一个例子。我想确保如果我需要增加磁盘空间,我不必先破坏机器。弹性(EC2)是我相信它可行的理由。

有谁知道这是否可行?是的,我可以简单地进行terraform plan一次预演,但只需仔细检查即可。

amazon-ec2 amazon-web-services terraform

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

为什么我无法将 dependent_on 块添加到具有提供程序配置的模块?

为我的 Terraform 模块编写示例时,出现错误:“模块包含提供程序配置”“无法使用 count、for_each 或 dependent_on 在模块内配置提供程序。”

当我尝试depends_on向模块声明添加一个块以避免在创建部署模块内资源所需的资源组之前尝试运行模块计划时,出现此错误。

如果我不添加该depends_on块,它也会中断,因为它找不到在模块运行以填充所需资源组数据源之前应创建的声明的资源组。

我发现要求删除块providers或删除所有数据源至少让人感到不舒服。

我找不到有关此错误或如何修复它的任何详细信息。

Terraform 代码中引发此错误的特定行。

azure terraform terraform-provider-azure terraform0.12+

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

Terraform 中的条件动态块

我有一个像这样的动态块:

 dynamic "origin" {
        for_each = var.ordered_cache_behaviors

        content {
            domain_name = "${origin.value.s3_target}.s3.amazonaws.com"
            origin_id   = "S3-${origin.value.s3_target}"    
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的列表定义如下:

  "ordered_cache_behaviors": [
    {
      "path_pattern": "/my-app*",
      "s3_target": "${local.default_s3_target}",
      "ingress": "external"
    }
  ]
Run Code Online (Sandbox Code Playgroud)

在我的动态块中,我只想在这个条件为真时渲染该块origin.value.s3_target !== var.default_s3_target

如何以及在何处将条件添加到动态块?请注意,块的渲染由当前迭代对象的值控制,而不是由完全排除 for 循环的某个变量控制。

我想迭代所有内容并有条件地排除某些项目。所以用 Javascript 写它看起来像这样:

for (origin in ordered_cache_behaviors) {
  if (origin.s3_target !== default_s3_target) {
     renderContent();
  } else {
     console.log('Content was skipped!');
  }
}
Run Code Online (Sandbox Code Playgroud)

terraform

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

本地状态无法被 terraform 上的另一个进程解锁

我的 terraform 远程状态和储物柜是在 aws 帐户下的 s3 和 dynamodb 上配置的,在 gitlab runner 上,某些计划任务已崩溃,在下一个执行计划中,会弹出以下错误:

Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException:
The conditional request failed

Lock Info:
  ID:        <some-hash>
  Path:      remote-terrform-states/app/terraform.tfstate
  Operation: OperationTypePlan
  Who:       root@runner-abc-project-123-concurrent-0
  Version:   0.14.10
  Created:   2022-01-01 00:00:00 +0000 UTC
  Info:  some really nice info
Run Code Online (Sandbox Code Playgroud)

在尝试解锁此储物柜以便再次执行额外的执行计划时 - 我收到以下错误:

  terraform force-unlock <some-hash-abc-123>

  #output:
  Local state cannot be unlocked by another process
Run Code Online (Sandbox Code Playgroud)

我们如何释放这个地形储物柜?

amazon-dynamodb terraform tfstate locker

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

为什么使用terraform创建API网关的方法响应不同?

我有以下 terraform 脚本,它创建一个 API 网关,将请求传递给 lambda 函数。

provider "aws" {

  access_key = "${var.access_key}"

  secret_key = "${var.secret_key}"
  # 
  region     = "${var.region}"

  version = "~> 2.6"
}

resource "aws_api_gateway_rest_api" "MyDemoAPI" {
  name        = "MyDemoAPI"
  description = "This is my API for demonstration purposes"
}

resource "aws_api_gateway_resource" "MyDemoResource" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  parent_id   = "${aws_api_gateway_rest_api.MyDemoAPI.root_resource_id}"
  path_part   = "mydemoresource"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id   = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  resource_id   = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method   = "POST"
  authorization = "NONE"
}

resource "aws_api_gateway_integration" "MyDemoIntegration" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}" …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform aws-api-gateway

9
推荐指数
2
解决办法
2629
查看次数

stepfunction 的 AWS Service Principal 值是多少?

我正在编写用于为 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”

amazon-web-services terraform aws-step-functions

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

Terraform 上的 AWS - 如何避免“强制使用新资源”

我正在使用 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"(强制新资源)

terraform > 在安全组上强制使用新资源


编辑:

深入了解计划输出,其中一项资源似乎发生了变化:

  security_groups.#: "0" => "1" (forces new resource)
  security_groups.837544107: "" => "sg-0892062659392afa9" (forces new resource) …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform terraform-provider-aws

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

如何解决错误加载状态:AccessDenied:Access Denied 状态代码:403 尝试将 s3 用于 terraform 后端时?

我的简单 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)

amazon-web-services terraform terraform-provider-aws

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