Skip to content

Commit

Permalink
Merge pull request #3 from fjdev/feature/management-group-association-v2
Browse files Browse the repository at this point in the history
Add management group subscription association resource
  • Loading branch information
fjdev authored Jul 10, 2024
2 parents 3968a40 + ffe2990 commit 071650e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ No requirements.
| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | n/a |
| <a name="provider_management"></a> [management](#provider\_management) | n/a |

## Modules

Expand All @@ -23,14 +24,16 @@ No modules.
| [azurerm_billing_mca_account_scope.mca](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/billing_mca_account_scope) | data source |
| [azurerm_billing_mpa_account_scope.mpa](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/billing_mpa_account_scope) | data source |
| [azurerm_subscriptions.created](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscriptions) | data source |
| [management_group.mg](https://registry.terraform.io/providers/hashicorp/management/latest/docs/data-sources/group) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_alias"></a> [alias](#input\_alias) | (Optional) The Alias name for the subscription. Terraform will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created. | `string` | `null` | no |
| <a name="input_billing_scope_id"></a> [billing\_scope\_id](#input\_billing\_scope\_id) | (Optional) The Azure Billing Scope ID. Can be a Microsoft Customer Account Billing Scope ID, a Microsoft Partner Account Billing Scope ID or an Enrollment Billing Scope ID. | `string` | `null` | no |
| <a name="input_management_group_id"></a> [management\_group\_id](#input\_management\_group\_id) | (Required) The ID of the Management Group to associate the Subscription with. Changing this forces a new Management to be created. | `string` | `null` | no |
| <a name="input_management_group_display_name"></a> [management\_group\_display\_name](#input\_management\_group\_display\_name) | (Optional) Specifies the display name of this Management Group. | `string` | `null` | no |
| <a name="input_management_group_name"></a> [management\_group\_name](#input\_management\_group\_name) | (Optional) Specifies the name or UUID of this Management Group. | `string` | `null` | no |
| <a name="input_subscription_id"></a> [subscription\_id](#input\_subscription\_id) | (Optional) The ID of the Subscription. Changing this forces a new Subscription to be created. | `string` | `null` | no |
| <a name="input_subscription_name"></a> [subscription\_name](#input\_subscription\_name) | (Required) The Name of the Subscription. This is the Display Name in the portal. | `string` | `null` | no |
| <a name="input_subscription_type"></a> [subscription\_type](#input\_subscription\_type) | (Optional) The Subscription Type to use and the required parameters for that Subscription Type. Possible values are 'EA', 'MCA' and 'MPA'. | <pre>map(object({<br> billing_account_name = optional(string)<br> enrollment_account_name = optional(string)<br> billing_profile_name = optional(string)<br> invoice_section_name = optional(string)<br> customer_name = optional(string)<br> }))</pre> | `null` | no |
Expand Down
7 changes: 7 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ data "azurerm_subscriptions" "created" {

depends_on = [azurerm_subscription.subscription]
}

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

name = var.management_group_name
display_name = var.management_group_display_name
}
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ 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
}
5 changes: 2 additions & 3 deletions management_group_subscription_association.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
resource "azurerm_management_group_subscription_association" "mgsubassoc" {
count = var.management_group_id != null ? 1 : 0
count = local.management_group_subscription_association

management_group_id = var.management_group_id
management_group_id = data.management_group.mg[0].id
subscription_id = data.azurerm_subscriptions.created.subscriptions[0].subscription_id
}

10 changes: 8 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ variable "subscription_type" {
default = null
}

variable "management_group_id" {
variable "management_group_name" {
type = string
description = "(Required) The ID of the Management Group to associate the Subscription with. Changing this forces a new Management to be created."
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
}

0 comments on commit 071650e

Please sign in to comment.