我有一个包含 Terraform Cloud 的供应管道,我们的领导层要求我们使用 Terragrunt 来提高 Terraform 代码质量。
Terragrunt 是一个很好的工具,但我没有看到任何证据表明有人在 Terraform Cloud 上成功使用过它。
任何人都可以解决这个问题吗?请只回答如果你
我想将 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
第一次设置 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) 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 …
我有一个包含多个单独配置的存储库,这些配置共享一些模块,并使用类似于../../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 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 脚本访问它?
根据Google Provider 文档,应该使用环境变量将服务帐户密钥提供给 Terraform GOOGLE_CLOUD_KEYFILE_JSON
。使用 Terraform Cloud 时,这对我来说是个问题,因为这意味着将服务帐户密钥存储在存储库中并使用环境变量设置密钥文件的路径。
我想使用 Terraform 变量或环境变量将服务帐户密钥内容传递给提供者,但我无法找到相关文档。我该怎么做?
我\xe2\x80\x99m 完成本教程并设法将一切设置正常。
\n\n在对计划进行排队时,我收到以下与变量相关的错误,但无法深入了解它。
\n有人对如何推进此事有任何想法吗?谢谢
\n希望这将是一个很容易启动和运行的过程!
\nConfiguring 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 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) 我们为不同的领域创建了一些 terraform 堆栈,例如用于 vpc 的网络堆栈、用于 rds 内容的 rds 堆栈等。
\n例如,rds 堆栈依赖于网络堆栈从输出中获取值:
\n网络堆栈的输出:
\noutput "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)\nrds 堆栈将点击输出
\ndata "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 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
文件都包含带有子文件夹的模块定义:
/main.tf
:
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
:
module …
Run Code Online (Sandbox Code Playgroud) terraform terraform-provider-openstack terraform0.12+ terraform-cloud
我在 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
terraform-cloud ×12
terraform ×11
assume-role ×1
kubernetes ×1
terraform-provider-openstack ×1
terragrunt ×1