DR,最后。
我是一个完全陌生的土怪,我试图用它来利用干燥我的目录树如下所示,我计划将这个仓库用于aws,gcp和azure,在这个用例中,我只关注azure,一旦我理解了terragrunt的用法,我应该能够将逻辑应用于其他提供程序。我的树可能是问题之一,所以如果我做错了,请毫不犹豫地告诉我。
我想重复使用我的代码,而不是一遍又一遍地复制粘贴相同的东西。专注于azure,这里的最终目标是只创建一个资源组,其中有一个azure密钥库,以便能够理解terragrunt的使用情况。
据我所知,创建tenant.hcl、subscription.hcl和env.hcl使我不必在代码中更改此值。
根据我的错误消息,我可能忘记了一些依赖项......我将自己定位在IaC/deployments/subscription-test-1/dev/client-test/中,并运行“terragrunt计划”,但随后出现以下错误消息:
错误信息:
系统找不到指定的路径。time=2023-03- 30 T09:26:00+02:00 level=error msg=无法确定基础退出代码,因此Terragrunt将退出,并显示错误代码% 1
IaC/
├─ deployments/
│ ├─ azure/
│ │ ├─ subscription-test-1/
│ │ │ ├─ dev/
│ │ │ │ ├─ client-test/
│ │ │ │ │ ├─ terragrunt.hcl
│ │ │ │ ├─ env.hcl
│ │ │ ├─ ppd/
│ │ │ ├─ subscription.hcl
│ │ ├─ subscription-test-2/
│ │ │ ├─ dev/
│ │ │ ├─ ppd/
│ │ ├─ subscription-test-3/
│ │ │ ├─ prd/
│ │ │ ├─ sbx/
│ ├─ aws/
│ ├─ gcp/
│ ├─ tenant.hcl
├─ modules/
│ ├─ aws/
│ ├─ azuread/
│ │ ├─ security-groups/
│ │ ├─ spn/
│ ├─ azurerm/
│ │ ├─ akv/
│ │ │ ├─ main.tf
│ │ │ ├─ variables.tf
│ │ ├─ rg/
│ │ │ ├─ main.tf
│ │ │ ├─ variables.tf
│ ├─ databricks/
│ ├─ gcp/
├─ project-templates/
│ ├─ aws/
│ ├─ azure/
│ │ ├─ project-template-solution-1/
│ │ │ ├─ akv.tf
│ │ │ ├─ main.tf
│ │ │ ├─ rg.tf
│ │ │ ├─ variables.tf
│ │ │ ├─ terragrunt.hcl
│ │ ├─ project-template-solution-2/
│ │ ├─ project-template-solution-3/
│ ├─ gcp/
├─ terragrunt.hcl
下面是每个文件夹的terragrunt和terraform代码:
IaC/terragrunt.hcl
locals {
# Automatically load subscription variables
subscription_vars = read_terragrunt_config(find_in_parent_folders("subscription.hcl"))
# Automatically load tenant-level variables
tenant_var = read_terragrunt_config(find_in_parent_folders("tenant.hcl"))
# Automatically load environment-level variables
env_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
environment = local.env_vars.locals.environment
subscription_id = local.subscription_vars.locals.subscription_id
}
IaC/modules/azurerm/akv/main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.42.0"
}
}
}
#Configure the Azure Resource Management Provider
provider "azurerm" {
subscription_id = var.azure_subscription_id
tenant_id = var.azure_tenant_id
features {
key_vault {
purge_soft_delete_on_destroy = true
recover_soft_deleted_key_vaults = true
}
}
}
#create azure key vault
resource "azurerm_key_vault" "akv" {
name = lower("${var.azure_project_code}-${var.azure_env_code}-akv-01")
location = var.azure_resource_group_location
resource_group_name = var.azure_rg_name
enabled_for_disk_encryption = true
tenant_id = var.azure_tenant_id
soft_delete_retention_days = 7
purge_protection_enabled = false
sku_name = "standard"
}
IaC/modules/azurerm/akv/variables.tf
variable "azure_subscription_id" {
type = string
description = "Azure Subscription Id"
}
variable "azure_tenant_id" {
type = string
description = "Azure Tenant Id"
}
variable "azure_rg_name" {
type = string
description = "Azure Resource Group Name"
}
variable "azure_resource_group_location" {
default = "west europe"
description = "Location of the resource group."
}
variable "azure_env_code" {
type = string
description = "Azure Environment Code"
}
variable "azure_project_code" {
type = string
description = "Azure Project Code"
}
IaC/modules/azurerm/rg/main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.42.0"
}
}
}
provider "azurerm" {
subscription_id = var.azure_subscription_id
tenant_id = var.azure_tenant_id
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
#create azure resource group
resource "azurerm_resource_group" "rg" {
name = var.azure_rg_name
location = var.azure_resource_group_location
}
IaC/modules/azurerm/rg/variables.tf
variable "azure_subscription_id" {
type = string
description = "Azure Subscription Id"
}
variable "azure_tenant_id" {
type = string
description = "Azure Tenant Id"
}
variable "azure_rg_name" {
type = string
description = "Azure Resource Group Name"
}
variable "azure_resource_group_location" {
default = "west europe"
description = "Location of the resource group."
}
IaC/project-template-solution-1/terragrunt.hcl
include {
path = find_in_parent_folders()
}
IaC/project-template-solution-1/akv.tf
module "akv" {
source ="../..//modules/azurerm/akv/"
azure_subscription_id = var.azure_subscription_id
azure_tenant_id = var.azure_tenant_id
azure_rg_name = var.azure_rg_name
azure_resource_group_location = var.azure_resource_group_location
azure_project_code = var.azure_project_code
azure_env_code = var.azure_env_code
}
IaC/project-template-solution-1/rg.tf
module "rg" {
source ="../..//modules/azurerm/rg/"
azure_subscription_id = var.azure_subscription_id
azure_tenant_id = var.azure_tenant_id
azure_rg_name = var.azure_rg_name
azure_resource_group_location = var.azure_resource_group_location
}
IaC/project-template-solution-1/main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.42.0"
}
}
}
provider "azurerm" {
subscription_id = var.azure_subscription_id
tenant_id = var.azure_tenant_id
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
IaC/project-template-solution-1/variables.tf
variable "azure_subscription_id" {
type = string
description = "Azure Subscription Id"
}
variable "azure_tenant_id" {
type = string
description = "Azure Tenant Id"
}
variable "azure_rg_name" {
type = string
description = "Azure Resource Group Name"
}
variable "azure_resource_group_location" {
default = "west europe"
description = "Location of the resource group."
}
variable "azure_env_code" {
type = string
description = "Azure Environment Code"
}
variable "azure_project_code" {
type = string
description = "Azure Project Code"
}
IaC/deployments/azure/tenant.hcl
locals {
tenant_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
}
IaC/deployments/azure/subscription-test-1/subscription.hcl
locals {
subscription_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
}
IaC/deployments/azure/subscription-test-1/dev/env.hcl
locals {
environment = "dev"
}
TL;DR:我正在尝试通过使用模块(modules文件夹)和“调用模块”(project-templates文件夹)来部署混合terraform和terragrunt的架构。首先使用azure部署一个资源组,其中包含一个azure密钥库。
我试着把我的代码上传到GitHub,但这是我第一次使用它,所以我可能犯了错误。如果你想下载它,编辑它,并把你的更新发给我,你可以在这里找到它。https://github.com/leanne-kami/IaC
感谢任何人谁会花时间来帮助我:)
1条答案
按热度按时间sr4lhrrt1#
一个朋友帮助我解决了这个问题,通过以下两个步骤:
1.删除IaC/deployments/azure/subscription-test-1/dev/client-test/terragrunt.hcl中的依赖块
1.编辑IaC/project-templates/azure/project-template-solution-1/ www.example.com和www.example.com中的路径akv.tfrg.tf,使目录了解模块文件夹的实际位置。
Azurevar.azure云服务器是一个由Azure云服务器和Azure云服务器组成的服务器,它提供了一个基于云计算的云服务器,可以在云服务器上运行。Azure云服务器可以在云服务器上运行,也可以在云服务器上运行。Azure云服务器可以在云服务器上运行,也可以在云服务器上运行。