标签: terraform-cloud

我可以在 Terraform Cloud 上使用 Terragrunt 吗

我有一个包含 Terraform Cloud 的供应管道,我们的领导层要求我们使用 Terragrunt 来提高 Terraform 代码质量。

Terragrunt 是一个很好的工具,但我没有看到任何证据表明有人在 Terraform Cloud 上成功使用过它。

任何人都可以解决这个问题吗?请只回答如果你

  1. 自己做过这件事,或者
  2. 可以提供文件证明这是可行的,或
  3. 提供文件证明这不是一个好主意或
  4. Terraform Cloud 无法实现。

terraform terragrunt terraform-cloud

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

Terraform Cloud / Enterprise - 如何使用 AWS 承担角色

我想将 AWS Assume Roles 与 Terraform Cloud / Enterprise 一起使用

在 Terraform 开源中,您通常只需执行假设角色,利用 CLI 上的 .aws/Credential Profile(这是初始身份验证)并执行假设角色:

provider "aws" {
  assume_role {
    role_arn     = "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME"
    session_name = "SESSION_NAME"
    external_id  = "EXTERNAL_ID"
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是,使用 Terraform Enterprise 或 Cloud,您无法引用配置文件,因为不可变基础架构的目录中不会包含该文件。

Terraform Cloud/Enterprise 需要将访问密钥 ID 和秘密访问密钥设置为变量,以便其基础设施可以通过其管道执行 Terraform RUN,并对您想要在其中配置的任何 AWS 账户进行身份验证。

所以问题是:如何利用 AWS 账户的访问密钥 ID 和秘密访问密钥以及“Action”:“sts:AssumeRole”策略来执行 AWS 承担角色?

我认为,下面的方法可行,但是 Terraform 正在通过 AWS Credential Profile 凭证对具有 sts:AssumeRole 策略的帐户进行初始身份验证

当尝试承担角色时,Terraform 是否可以查看 access_key 和 Secret_key 来确定要使用的 AWS 账户,而不是使用 AWS 凭证配置文件?

provider "aws" {
  region                  = var.aws_region …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform-enterprise assume-role terraform-cloud

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

在 terraform 云中运行的 azure cli $Path 错误

第一次设置 terraform cloud 并收到此错误。不知道为什么在我的本地计算机上安装了 azure CLI 并设置了路径,但我认为与在 terraform 云平台中设置它有关。

Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.
with provider["registry.terraform.io/hashicorp/azurerm"]
on versions.tf line 21, in provider "azurerm":

provider "azurerm" {
Run Code Online (Sandbox Code Playgroud)

我当前的tf代码

版本.tf

terraform {

  cloud {
    organization = "myorg"

    workspaces {
      name = "dev"
    }
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-azure terraform-cloud

6
推荐指数
2
解决办法
9488
查看次数

Terraform cloud : Import existing resource

I am using terraform cloud to manage the state of the infrastructure provisioned in AWS.

I am trying to use terraform import to import an existing resource that is currently not managed by terraform.

I understand terraform import is a local only command. I have set up a workspace reference as follows:

terraform {
  required_version = "~> 0.12.0"

  backend "remote" {
    hostname = "app.terraform.io"
    organization = "foo"

    workspaces {
      name = "bar"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

The AWS credentials are configured …

terraform terraform-provider-aws terraform-cloud

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

使用相对本地路径引用模块时 Terraform 云失败

我有一个包含多个单独配置的存储库,这些配置共享一些模块,并使用类似于../../modules/rabbitmq. 目录设置如下:

tf/
  configs/
    thing-1/
    thing-2/
  modules/
    rabbitmq/
    cluster/
    ...
Run Code Online (Sandbox Code Playgroud)

使用远程后端设置配置以使用 TF Cloud 进行运行和状态:

terraform {
  backend "remote" {
    hostname     = "app.terraform.io"
    organization = "my-org"

    workspaces {
      prefix = "config-1-"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

跑步terraform init效果很好。当我尝试在terrform plan本地运行时,它给了我一个错误提示:

Initializing modules...
- rabbitmq in 

Error: Unreadable module directory

Unable to evaluate directory symlink: lstat ../../modules: no such file or
directory
Run Code Online (Sandbox Code Playgroud)

...好像模块目录没有上传到 TF Cloud 或其他东西。是什么赋予了?

terraform terraform-cloud

5
推荐指数
2
解决办法
1277
查看次数

如何将 GCP 服务帐户 JSON 存储在 terrafrom 变量中?

我的 terraform gcp provider 配置看起来像

provider "google" {
  project     = var.project
  region      = var.region
  credentials = file("account.json")
}
Run Code Online (Sandbox Code Playgroud)

我想在 terraform 云上运行我的 terraform 文件,但我不想将 account.json 文件放在源代码管理中。如何将 json GCP 服务帐户文件存储在 terraform cloud 中,然后从 terraform 脚本访问它?

terraform terraform-provider-gcp terraform-cloud

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

如何将 GCP 服务帐户 key.json 内容传递到 Terraform Cloud 而不在 VCS 中提交?

根据Google Provider 文档,应该使用环境变量将服务帐户密钥提供给 Terraform GOOGLE_CLOUD_KEYFILE_JSON。使用 Terraform Cloud 时,这对我来说是个问题,因为这意味着将服务帐户密钥存储在存储库中并使用环境变量设置密钥文件的路径。

我想使用 Terraform 变量或环境变量将服务帐户密钥内容传递给提供者,但我无法找到相关文档。我该怎么做?

google-cloud-platform terraform terraform-cloud

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

通过云教程使用变量的问题

我\xe2\x80\x99m 完成本教程并设法将一切设置正常。

\n

https://learn.hashicorp.com/tutorials/terraform/cloud-workspace-configure?in=terraform%2Fcloud-get-started

\n

在对计划进行排队时,我收到以下与变量相关的错误,但无法深入了解它。

\n

有人对如何推进此事有任何想法吗?谢谢

\n

希望这将是一个很容易启动和运行的过程!

\n
Configuring remote state backend...\nInitializing Terraform configuration...\n\nWarning: Value for undeclared variable\n\nThe root module does not declare a variable named "tag_user_name" but a value\nwas found in file "/terraform/terraform.tfvars". To use this value, add a\n"variable" block to the configuration.\n\nUsing a variables file to set an undeclared variable is deprecated and will\nbecome an error in a future release. If you wish to provide certain "global"\nsettings to all configurations in your organization, use TF_VAR_...\nenvironment …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-aws terraform-cloud

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

这里不希望使用“云”类型的块与 Terraform Cloud 集成

我正在按照此文档迁移本地状态以与 Terraform Cloud 集成。

https://learn.hashicorp.com/tutorials/terraform/cloud-migrate

这很简单,我只需要复制这段代码:

terraform {
  required_version = ">= 1.1.0"
  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.0.1"
    }
  }
  cloud {
    organization = "<ORG_NAME>"
    workspaces {
      name = "Example-Workspace"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是我下面的代码与上面的代码相同

terraform {
  required_version = ">= 0.14.9"
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "~> 3.27"
    }
  }
  cloud {
    organization = "ORG"

    workspaces {
      name = "ORG_WORKSPACE"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但它返回一个错误:

Blocks of type "cloud" are not expected …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform terraform-cloud

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

Terraform 输出被标记为敏感

我们为不同的领域创建了一些 terraform 堆栈,例如用于 vpc 的网络堆栈、用于 rds 内容的 rds 堆栈等。

\n

例如,rds 堆栈依赖于网络堆栈从输出中获取值:

\n

网络堆栈的输出:

\n
output "public_subnets" {\n  value = aws_subnet.public.*.id\n}\n\noutput "private_subnets" {\n  value = aws_subnet.private.*.id\n}\n\noutput "data_subnets" {\n  value = aws_subnet.data.*.id\n}\n\n... an so on\n
Run Code Online (Sandbox Code Playgroud)\n

rds 堆栈将点击输出

\n
data "tfe_outputs" "networking" {\n  organization = "my-tf-cloud-org"\n  workspace    = "network-production-eucentral1"\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我尝试使用输出时:

\n
\xe2\x94\x82\n\xe2\x94\x82   on main.tf line 20, in module "db":\n\xe2\x94\x82   20:   base_domain = data.tfe_outputs.dns.values.fqdn\n\xe2\x94\x82     \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\xe2\x94\x82     \xe2\x94\x82 data.tfe_outputs.dns.values has a sensitive value\n\xe2\x94\x82\n\xe2\x94\x82 This object does not have an attribute named "fqdn".\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-enterprise terraform-cloud

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

对 Terraform 中其他模块资源的引用

我的 Terraform Cloud git 项目中有这样的层次结构:

\n\n
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 aws\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 flavors\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 security-rules\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 sec-rule1\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0     \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vms\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vm1\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0     \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.tf\n
Run Code Online (Sandbox Code Playgroud)\n\n

所有主main.tf文件都包含带有子文件夹的模块定义:

\n\n

/main.tf:

\n\n
terraform {\n  required_version = "~> 0.12.0"\n\n  backend "remote" {\n    hostname = "app.terraform.io"    \n    organization = "foo"\n\n    workspaces {\n      name = "bar"\n    }\n  }\n  required_providers {\n    openstack = "~> 1.24.0"\n  }\n}\n\nmodule "aws" {\n  source = "./aws"\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

/aws/main.tf:

\n\n
module …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-openstack terraform0.12+ terraform-cloud

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

如何在销毁后从 Terraform 清理由 helm_release 资源留下并运行的 k8s 资源

我在 Terraform 中使用 helm_release 资源时遇到问题。

我基本上部署了一个kube-prometheus-stack包含许多k8s资源并且运行顺利的。

当我尝试销毁(或删除)这部分时,问题出现了,因为卸载图表时 Helm 不会删除所有资源(这可能与某些垃圾收集规则有关,这些规则使它们在删除后保持正常运行)。这意味着我最终得到:

  • 图表已卸载
  • 资源仍在运行
  • 必须手动去那里删除所有内容,否则如果我重新创建该内容,我会得到大量重复项

我之前问过一个问题(现在我要结束了),涉及了解这是否是 Helm 的问题(实际上不是,根据设计,它会尽可能删除所有内容,我不确定图表中是否可以做一些事情,但是无论如何,我假设现在不会很快完成)现在我想问是否有人知道如何直接从 Terraform 管理它。

例如,当资源被销毁时,我可以使用某些东西kubectl delete在标记的资源(或者可能是整个命名空间)上运行命令吗?helm_release

注意:我没有添加任何代码,因为这与代码无关,但更多的是寻找一些钩子或黑客仅在销毁后运行清理。

ps:我还尝试在应用后利用 Terraform 云挂钩,但我更愿意根据 Terraform Cloud 来解决这个问题,无论如何,我没有设法创建对是否已被helm_release销毁的依赖关系。

kubernetes terraform kubernetes-helm terraform-cloud terraform-provider-helm

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