1.我必须使用模块和带有对象Map的for_each循环在多个订阅上创建安全中心、服务协议和资源提供程序`
1.下面是变量文件和terraform.tfvars文件。
1.请让我知道我如何使用这个tfvars文件和模块在多个订阅上部署这些资源。
variable "subscriptions_configurations" {
type = map(object({
Defender = map(object({
contact = object({
name = string
email = string
phone = string
alert_notifications = bool
alerts_to_admins = bool
})
setting = object({
setting_name = string
enabled = bool
})
pricing = object({
tier = string
resource_type = string
subplan = optional(string)
})
auto_provisioning = object({
auto_provision = string
})
}))
marketplace_agreement = map(object({
publisher = string
offer = string
plan = string
}))
resource_provider_registration = map(object({
feature = object({
name = string
registered = bool
})
}))
}))
}
subscriptions_configurations = {
"subscription1" = {
Defender = {
contact = {
name = "contact"
email = "contact@xyz.com"
phone = "+1-341-676-1248"
alert_notifications = false
alerts_to_admins = false
}
setting = {
setting_name = "MCAS"
enabled = false
}
pricing = {
tier = "Free"
resource_type = "VirtualMachines"
}
auto_provisioning = {
auto_provision = "On"
}
}
marketplace_agreement = {
"agreement1" = {
publisher = "barracudanetworks"
offer = "waf"
plan = "hourly"
}
}
resource_provider_registration = {
"Microsoft.ContainerService" = {
feature = {
name = "AKS-DataPlaneAutoApprove"
registered = true
}
}
}
}
}
module "subscriptions_configurations" {
source = "./modules/security_center"
for_each = var.subscriptions_configurations
defender = each.value.defender
marketplace_agreement = each.value.marketplace_agreement
resource_provider_registration = each.value.resource_provider_registration
}
1条答案
按热度按时间kq0g1dla1#
我试着在我的www.example.com和variables.tfvars中使用下面的代码main.tf,代码适用于多个订阅,对于每个块:-
我参考了Charles Xu的SO thread answer代码,并使用for each和variables修改了它。tfvars
我的main.tf:-
我的变量.tfvars:-
输出:-
您不能将两个提供程序一起添加或通过字符串插值添加到Terraform中的特定资源,在这里,您可以通过引用Martin阿特金斯的Answer1和Michael Aicher的Answer2,在上面的代码中创建一个单独的模块和别名,一个用于azurerm,另一个用于azurrm.sub2
附加参考:-
Defining provider aliases with string interpolation not working in Terraform 0.12 - Terraform - HashiCorp Discuss By appartlymart