Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_management_group_subscription_association - could not read properties for Management Group #23323

Closed
1 task done
chammock opened this issue Sep 19, 2023 · 2 comments · Fixed by #23335
Closed
1 task done

Comments

@chammock
Copy link

chammock commented Sep 19, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.5.5

AzureRM Provider Version

3.73.0

Affected Resource(s)/Data Source(s)

azurerm_management_group_subscription_association

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.0"
    }
  }
}

provider "azurerm" {
  skip_provider_registration = true
  features {}
}

resource "azurerm_management_group" "example" {
  display_name = "example"
}

data "azurerm_billing_mca_account_scope" "example" {
  billing_account_name = "X"
  billing_profile_name = "X"
  invoice_section_name = "X"
}

resource "azurerm_subscription" "example" {
  subscription_name = "My Example MPA Subscription"
  billing_scope_id  = data.azurerm_billing_mca_account_scope.example.id
}

data "azurerm_subscription" "example" {
  subscription_id = azurerm_subscription.example.subscription_id
}

resource "azurerm_management_group_subscription_association" "example" {
  management_group_id = azurerm_management_group.example.id
  subscription_id     = data.azurerm_subscription.example.id
}

Debug Output/Panic Output

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: could not read properties for Management Group "X"
│
│   with azurerm_management_group_subscription_association.example,
│   on main.tf line 31, in resource "azurerm_management_group_subscription_association" "example":
│   31: resource "azurerm_management_group_subscription_association" "example" {

Expected Behaviour

During the provider read of azurerm_management_group_subscription_association , if the expected Management Group has no children, it should be treated as an empty list instead of an error. Then because the expected Subscription is not a child of the Management Group, the Subscription should be re-associated to the proper Management Group. Error is here where instead the provider errors out if the Management Group's children are empty, whereas instead of an error the children list should just be set to an empty list. Then later found would be considered false and the Management Group ID set to empty forcing the re-association.

Actual Behaviour

When a Terraform plan or apply is run after the Subscription is manually moved, outside of Terraform's control, and thus the Management Group has no other children Subscriptions, Terraform produces the following error message ``.

Steps to Reproduce

  1. Run above provided Terraform configuration terraform apply
  2. Manually move the Subscription to a different Management Group (IE through the Portal)
  3. Run terraform plan and error occures

Important Factoids

No response

References

https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/services/managementgroup/subscription_association_resource.go#L123

@rcskosir
Copy link
Contributor

@chammock Thank you for taking time to open this issue. Please subscribe to #23335 that @teowa has opened to fix this issue.

@github-actions github-actions bot added this to the v3.74.0 milestone Sep 21, 2023
Copy link

github-actions bot commented May 6, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants