Skip to content

Commit

Permalink
Update subscription_id and management group subscription association …
Browse files Browse the repository at this point in the history
…references
  • Loading branch information
fjdev committed Nov 28, 2024
1 parent 8579adb commit e058b12
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
11 changes: 2 additions & 9 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ data "azurerm_billing_mpa_account_scope" "mpa" {
customer_name = var.subscription_type["MPA"].customer_name
}

data "azurerm_subscriptions" "created" {
data "azurerm_subscriptions" "subscription" {
display_name_contains = var.subscription_name

depends_on = [azurerm_subscription.sub]
}

data "azurerm_management_group" "mg" {
count = local.management_group_subscription_association

name = var.management_group_name
display_name = var.management_group_display_name
depends_on = [azurerm_subscription.subscription]
}
1 change: 0 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ locals {
MCA = try(data.azurerm_billing_mca_account_scope.mca[0].id, null)
MPA = try(data.azurerm_billing_mpa_account_scope.mpa[0].id, null)
}
management_group_subscription_association = var.management_group_name != null || var.management_group_display_name != null ? 1 : 0
}
9 changes: 8 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
resource "azurerm_subscription" "sub" {
resource "azurerm_subscription" "subscription" {
subscription_name = var.subscription_name
alias = var.alias
billing_scope_id = var.subscription_id == null ? lookup(local.billing_scope_ids, keys(var.subscription_type)[0], var.billing_scope_id) : null
subscription_id = var.subscription_id
workload = var.workload
tags = var.tags
}

resource "azurerm_management_group_subscription_association" "management_group_subscription_association" {
count = var.management_group_id != null ? 1 : 0

management_group_id = var.management_group_id
subscription_id = data.azurerm_subscriptions.subscription.subscriptions[0].id
}
6 changes: 0 additions & 6 deletions management_group_subscription_association.tf

This file was deleted.

6 changes: 3 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
output "subscription_id" {
description = "The Resource ID of the Alias."
value = data.azurerm_subscriptions.created.subscriptions[0].subscription_id
value = data.azurerm_subscriptions.subscription.subscriptions[0].subscription_id
}

output "subscription_name" {
description = "The Name of the Alias."
value = azurerm_subscription.sub.subscription_name
value = azurerm_subscription.subscription.subscription_name
}

output "tenant_id" {
description = "The ID of the Tenant to which the subscription belongs."
value = azurerm_subscription.sub.tenant_id
value = azurerm_subscription.subscription.tenant_id
}
10 changes: 2 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ variable "subscription_type" {
default = null
}

variable "management_group_name" {
variable "management_group_id" {
type = string
description = "(Optional) Specifies the name or UUID of this Management Group."
default = null
}

variable "management_group_display_name" {
type = string
description = "(Optional) Specifies the display name of this Management Group."
default = null
description = "The ID of the Management Group to associate the Subscription with."
}

0 comments on commit e058b12

Please sign in to comment.