Having issues with provider definition when configuring Terraform for Azure in YAML

I’m working on an ambitious project to define Terraform configuration in YML for Azure but am having issues on handling the provider block. Here are the details.

Why YML? Two main reasons:

  1. I’d like to organize configuration templates across multiple directories
  2. I’d like to take away the ability for people to define terraform resources that are not processed by our custom terraform modules. A YAML configuration would prevent that.

I will have multiple YML files that look like this across multiple directory and subdirectories.

provider:
  name: "azurerm"
  features: {}
  skip_provider_registration: true
  alias: sub-test-01
  subscription_id: "d6025e9c-ce0b-4632-b9a8-8e04c49a1d6e"
codeowners_team: "test-team"
subscription_name: "sub-test-01"
parent_management_group_id: "/providers/Microsoft.Management/managementGroups/DEFAULT"
resource_provider_registrations:
  - "Microsoft.Cache"
  - "Microsoft.DBforMySQL"
default_subscription_access_entra_group_name: "group-test-sub-users"
access:
  subscription:
    - entra_group_name: "group-test-sub-users"
      role: "Contributor"
  resource_group:
    - resource_group_name: "rg-test-01"
      entra_group_name: "group-test-sub-users"
      role: "Owner"
  resource:
    - resource_id: "/resourceGroups/rg-test-01/providers/Microsoft.Storage/storageAccounts/storagetest01"
      spn: "spn-subs-test-temp"
      role: "Storage Account Contributor"

The HCL equivalent to this would look like:

provider "azurerm" {
    features {}
    skip_provider_registration = true
    alias = "sub-test-01"
    subscription_id = "d6025e9c-ce0b-4632-b9a8-8e04c49a1d6e"
}

module "sub-iam-test-01" {
    source = "../modules/subscription"
    subscription_name = "sub-test-01"
    codeowners_team = "test-team"
    parent_management_group_id = "/providers/Microsoft.Management/managementGroups/DEFAULT"
    resource_provider_registrations = ["Microsoft.Cache", "Microsoft.DBforMySQL"]
    default_subscription_access_entra_group_name = "group-test-sub-users"
    access = {
        subscription = [
            {
                entra_group_name = "group-test-sub-users"
                role = "Contributor"
            }
        ],
        resource_group = [
            {
                resource_group_name = "rg-test-01"
                entra_group_name = "group-test-sub-users"
                role = "Owner"
            }
        ],
        resource = [
            {
                resource_id = "/resourceGroups/rg-test-01/providers/Microsoft.Storage/storageAccounts/storagetest01"
                spn = "spn-subs-test-temp"
                role = "Storage Account Contributor"
            }
        ]
    }
    providers = {
        azurerm = azurerm.sub-test-01
    }
}

The ../modules/subscription custom module is handling the configuration in HCL for each property defined here.

Example folder structure:

- tf
   - subscriptions
      - project_alpha
         - alpha_subscription_01.yml
         - alpha_subscription_02.yml
      - project_beta
         - beta_subscription_01.yml
         - beta_subscription_02.yml
         - beta_subscription_03.yml
   - providers.tf
   - main.tf

Basically, I’m struggling with that main.tf

locals {
  subscription_yml_files = [for file in flatten(fileset(path.module,"subscriptions/**/*.yml")): yamldecode(file(file))]
}

module "subscriptions" {
  source = "../modules/subscription"
  for_each = local.subscription_yml_files

  subscription_name = each.value.name
  codeowners_github_team = each.value.codeowners_team
  parent_management_group_id = each.value.parent_management_group_id
  resource_provider_registrations = each.value.resource_provider_registrations
  default_subscription_access_entra_group_name = each.value.default_subscription_access_entra_group_name

  access = each.value.access

}

The idea was to have one main.tf file that processes all existing YML configurations

  • loop through each YML file
  • convert/decode YML into HCL
  • pass in the variables to the custom subscription module

Up until this point, everything is working OK. However, I cannot figure out how to handle the provider "azurerm" block in YML. As far as I understand, provider definition cannot live inside a module. And since each one of these YML files are targeting specific Azure subscriptions (with the subscription_id property), it is mandatory.

Is it possible to somehow configure the provider with Azure subscription info inside the custom module in ../modules/subscription? Are there any alternate solutions?

Please advise.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật