gpt4 book ai didi

azure - Terraform 模块 rbac 分配

转载 作者:行者123 更新时间:2023-12-03 03:23:26 25 4
gpt4 key购买 nike

这可能是一个愚蠢的错误,但我没有看到它,所以我寻求帮助和澄清。我似乎无法从我的 RBAC 的outputs.tf 中调用我的值,该 RBAC 有 2 个“依赖项”,一个来 self 的 azurerm 文件夹,一个来 self 的 azuread 文件夹。我基本上是在尝试将 azure RBAC 升级到 azure 安全组。

具有以下结构:

IaC/
├─ deployments/
├─ modules/
│ ├─ aws/
│ ├─ azuread/
│ │ ├─ security-groups/
│ │ | ├─ cns/
| | | | ├─ main.tf
| | | | ├─ outputs.tf
| | | | ├─ variables.tf
│ ├─ azurerm/
│ │ ├─ akv/
│ │ │ ├─ main.tf
| | | ├─ outputs.tf
│ │ │ ├─ variables.tf
│ │ ├─ rbac/
│ │ | ├─ rbac-rg-operator/
│ │ │ | ├─ main.tf
| | | | ├─ outputs.tf
│ │ │ | ├─ variables.tf
│ │ ├─ rg/
│ │ │ ├─ main.tf
| | | ├─ outputs.tf
│ │ │ ├─ variables.tf
├─ project-templates/
│ ├─ azure/
│ │ ├─ project-template-solution-1/
│ │ │ ├─ akv.tf
│ │ │ ├─ main.tf
│ │ │ ├─ rg.tf
│ │ │ ├─ rbac-rg-operator.tf
│ │ │ ├─ sg-cns.tf
│ │ │ ├─ variables.tf
│ │ │ ├─ terragrunt.hcl
├─ terragrunt.hcl

运行 terragrunt plan 时收到以下错误消息。

error-msg

这是我关心的配置文件:

IaC/modules/azureread/security-groups/cns/

main.tf

terraform {

required_providers {
azuread = {
source = "hashicorp/azuread"
version = "2.31.0"
}
}
}
provider "azuread" {
tenant_id = var.azure_tenant_id
}

data "azuread_client_config" "current" {}

#create azure active directory group cns
resource "azuread_group" "azure_sg_cns" {
display_name = var.azure_sg_cns
owners = [data.azuread_client_config.current.object_id]
security_enabled = true
}

输出.tf

output "azure_sg_cns_object_id_out" {
value = azuread_group.azure_sg_cns.object_id
}

变量.tf

variable "azure_sg_cns" {
type = string
description = "Azure AD Security Group Name CNS"
}

variable "azure_tenant_id" {
type = string
description = "Azure Tenant Id"
}

IaC/modules/azurerm/rbac/rbac-rg-operator/

main.tf

terraform {

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.42.0"
}
azuread = {
source = "hashicorp/azuread"
version = "2.31.0"
}
}
}

resource "azurerm_role_assignment" "rbac-rg-operator" {
scope = var.azure_rg_name
role_definition_name = "RG Operator"
principal_id = var.azure_sg_cns.object_id
}

变量.tf

variable "azure_sg_cns" {
type = string
description = "Azure AD Security Group Name CNS"
}

variable "azure_rg_name" {
type = string
description = "Azure Resource Group Name"
}

variable "azure_tenant_id" {
type = string
description = "Azure Tenant Id"
}

IaC/modules/project-templates/azure/project-template-solution-1/

rbac-rg-operator.tf

module "rbac-rg-operator" {
source ="../../..//modules/azurerm/rbac/rbac-rg-operator/"
azure_sg_cns = module.azure_sg_cns.azure_sg_cns_object_id_out
azure_rg_name = module.rg.rg_id_out
azure_tenant_id = var.azure_tenant_id

}

最佳答案

更改了以下内容以使其正常工作:

rbac-rg-operator.tf

module "rbac-rg-operator" {
source ="../../..//modules/azurerm/rbac/rbac-rg-operator/"
azure_sg_cns = module.azure_sg_cns.azure_sg_cns_object_id_out
azure_rg_name = module.rg.rg_id_out
azure_tenant_id = var.azure_tenant_id

}

module "rbac-rg-operator" {
source ="../../..//modules/azurerm/rbac/rbac-rg-operator/"
azure_sg_cns = module.sg-cns.azure_sg_cns_object_id_out
azure_rg_name = module.rg.rg_id_out
azure_tenant_id = var.azure_tenant_id

}

第 3 行:azure_sg_cns = module.azure_sg_cns.azure_sg_cns_object_id_out 变为 azure_sg_cns = module.sg-cns.azure_sg_cns_object_id_out

apply

关于azure - Terraform 模块 rbac 分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76252876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com