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

data/resource: azurerm_management_group - now exports tenant_scoped_id #25555

Conversation

BrendanThompson
Copy link
Contributor

@BrendanThompson BrendanThompson commented Apr 10, 2024

Community Note

  • Please vote on this PR by adding a πŸ‘ reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave "+1" or "me too" comments, they generate extra noise for PR followers and do not help prioritize for review

Description

Currently when trying to create a System Topic on a Management Group using the described and validated Management Group ID as per below an error is received:

resource "azurerm_eventgrid_system_topic" "this" {
  name                   = "policy-insights"
  resource_group_name    = "resource-group"
  location               = "Global"
  source_arm_resource_id = "/providers/Microsoft.Management/managementGroups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  topic_type             = "Microsoft.PolicyInsights.PolicyStates"
}

This yields the following error:

β•·
β”‚ Error: creating/updating System Topic (Subscription: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
β”‚ Resource Group Name: "resource-group"
β”‚ System Topic Name: "policy-insights"): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: InvalidRequest: ResourceID is not in the expected format: /providers/Microsoft.Management/managementGroups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (Parameter 'GetSourceScope')
β”‚ 
β”‚   with azurerm_eventgrid_system_topic.this,
β”‚   on main.tf line 14, in resource "azurerm_eventgrid_system_topic" "this":
β”‚   14: resource "azurerm_eventgrid_system_topic" "this" {
β”‚ 
β•΅

This error looks to be coming from the Azure API, which means the current validate.ManagementGroupID function from the github.com/hashicorp/terraform-provider-azurerm/internal/services/managementgroup/validate package is only checking for valid format on the above and not what is expected by the API.

As shown in the following documentation the resource ID format changes specifically for Management Group IDs when creating a System Topic.

https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/governance/policy/tutorials/route-state-change-events.md#create-an-event-grid-system-topic

The resolution to this is to create a validator and parser for Management Group IDs based on that format.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #24548

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
@BrendanThompson
Copy link
Contributor Author

@katbyte – is there anything further you would like to see on this PR to help progress it?

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @BrendanThompson, this change looks good and I was able to get it working locally with a /tenants/ id. We should add a test though to make sure that we get this coverage in our acceptance test suite. And I'm wondering if we should add a /tenants/ id to the azurerm_management_group resource so people don't have to build that id out themselves.

What're your thoughts there?

@BrendanThompson
Copy link
Contributor Author

@mbfrahry β€” thanks for reviewing, appreciate it! I actually love your idea with having the ID in the data source, would we want it in both the data source and the resource? I think so personally.

When it comes to testing, roger that let me look into it and get back to you ASAP.

Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
Signed-off-by: Brendan Thompson <github@blt.is>
- Made regex for tenantID more generic (and non-adherent to standard) to allow for simpler test cases

Signed-off-by: Brendan Thompson <github@blt.is>
@BrendanThompson
Copy link
Contributor Author

@mbfrahry β€” added in the tests and everything else. Hopefully they should pass this time.

@BrendanThompson
Copy link
Contributor Author

I was thinking perhaps tenant_management_group_id might be a better attribute name, what are your thoughts?

Copy link
Member

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments inline but otherwise πŸ‘

Signed-off-by: Brendan Thompson <github@blt.is>
@BrendanThompson
Copy link
Contributor Author

@tombuildsstuff – awesome thanks so much mate. Agree with everything that you've said and have made the required changes.

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BrendanThompson - LGTM 🚜

@katbyte katbyte changed the title Fix Management Group ID validation when used for System Topics data/resource: azurerm_management_group - now exports tenant_scoped_id Apr 18, 2024
@katbyte katbyte merged commit 1f996cc into hashicorp:main Apr 18, 2024
33 checks passed
@github-actions github-actions bot added this to the v3.100.0 milestone Apr 18, 2024
katbyte added a commit that referenced this pull request Apr 18, 2024
@BrendanThompson BrendanThompson deleted the fix/management-group-validation-for-system-topic branch April 18, 2024 22:56
@BrendanThompson
Copy link
Contributor Author

Thanks so much @mbfrahry , @tombuildsstuff , & @katbyte !

dduportal pushed a commit to jenkins-infra/azure that referenced this pull request Apr 19, 2024
<Actions>
<action
id="f410411e63aff4bb73a81c2aec1d373cf8a903e63b30dee2006b0030d8a94cc8">
        <h3>Bump Terraform `azurerm` provider version</h3>
<details
id="1d9343c012f5434ac9fe8a98135bae3667b399259be16d9b14302ea3bd424a24">
            <summary>Update Terraform lock file</summary>
<p>changes detected:&#xA;&#x9;&#34;hashicorp/azurerm&#34; updated from
&#34;3.99.0&#34; to &#34;3.100.0&#34; in file
&#34;.terraform.lock.hcl&#34;</p>
            <details>
                <summary>3.100.0</summary>
<pre>Changelog retrieved
from:&#xA;&#x9;https://github.com/hashicorp/terraform-provider-azurerm/releases/tag/v3.100.0&#xA;ENHANCEMENTS:&#xA;&#xA;*
dependencies: updating `hashicorp/go-azure-sdk` to `v0.20240417.1084633`
([#25659](https://github.com/hashicorp/terraform-provider-azurerm/issues/25659))&#xA;*
`compute` - update Virtual Machine and Virtual Machine Scale Set
resources and data sources to use `hashicorp/go-azure-sdk`
([#25533](https://github.com/hashicorp/terraform-provider-azurerm/issues/25533))&#xA;*
`machine_learning` - Add new `machine_learning` block that supports
`purge_soft_deleted_workspace_on_destroy`
([#25624](https://github.com/hashicorp/terraform-provider-azurerm/issues/25624))&#xA;*
`loganalytics` - update cluster resource to use `hashicorp/go-azure-sdk`
([#23373](https://github.com/hashicorp/terraform-provider-azurerm/issues/23373))&#xA;*
Data Source: `azurerm_management_group` - now exports the
`tenant_scoped_id` attribute
([#25555](https://github.com/hashicorp/terraform-provider-azurerm/issues/25555))&#xA;*
`azurerm_container_app` - the
`ingress.ip_security_restriction.ip_address_range` property will now
accept an IP address as valid input
([#25609](https://github.com/hashicorp/terraform-provider-azurerm/issues/25609))&#xA;*
`azurerm_container_group` - the `identity` block can now be updated
([#25543](https://github.com/hashicorp/terraform-provider-azurerm/issues/25543))&#xA;*
`azurerm_express_route_connection` - support for the
`private_link_fast_path_enabled` property
([#25596](https://github.com/hashicorp/terraform-provider-azurerm/issues/25596))&#xA;*
`azurerm_hdinsight_hadoop_cluster` - support for the
`private_link_configuration` block
([#25629](https://github.com/hashicorp/terraform-provider-azurerm/issues/25629))&#xA;*
`azurerm_hdinsight_hbase_cluster` - support for the
`private_link_configuration` block
([#25629](https://github.com/hashicorp/terraform-provider-azurerm/issues/25629))&#xA;*
`azurerm_hdinsight_interactive_query_cluster` - support for the
`private_link_configuration` block
([#25629](https://github.com/hashicorp/terraform-provider-azurerm/issues/25629))&#xA;*
`azurerm_hdinsight_kafka_cluster` - support for the
`private_link_configuration` block
([#25629](https://github.com/hashicorp/terraform-provider-azurerm/issues/25629))&#xA;*
`azurerm_hdinsight_spark_cluster` - support for the
`private_link_configuration` block
([#25629](https://github.com/hashicorp/terraform-provider-azurerm/issues/25629))&#xA;*
`azurerm_management_group` - now exports the `tenant_scoped_id`
attribute
([#25555](https://github.com/hashicorp/terraform-provider-azurerm/issues/25555))&#xA;*
`azurerm_monitor_activity_log_alert` - support for the `location`
property
([#25389](https://github.com/hashicorp/terraform-provider-azurerm/issues/25389))&#xA;*
`azurerm_mysql_flexible_server` - update validating regex for `sku_name`
([#25642](https://github.com/hashicorp/terraform-provider-azurerm/issues/25642))&#xA;*
`azurerm_postgresql_flexible_server` - support for the `GeoRestore`
`create_mode`
([#25664](https://github.com/hashicorp/terraform-provider-azurerm/issues/25664))&#xA;*
`azurerm_virtual_network_gateway_connection` - support for the
`private_link_fast_path_enabled` property
([#25650](https://github.com/hashicorp/terraform-provider-azurerm/issues/25650))&#xA;*
`azurerm_windows_web_app` - support for the `handler_mapping` block
([#25631](https://github.com/hashicorp/terraform-provider-azurerm/issues/25631))&#xA;*
`azurerm_windows_web_app_slot` - support for the `handler_mapping` block
([#25631](https://github.com/hashicorp/terraform-provider-azurerm/issues/25631))&#xA;&#xA;BUG
FIXES:&#xA;&#xA;* storage: prevent a bug causing the second storage
account key to be used for authentication instead of the first
([#25652](https://github.com/hashicorp/terraform-provider-azurerm/issues/25652))&#xA;*
`azurerm_active_directory_domain_service` - prevent an issue where
`filtered_sync_enabled` was not being updated
([#25594](https://github.com/hashicorp/terraform-provider-azurerm/issues/25594))&#xA;*
`azurerm_application_insights` - add a state migration to fix the
resource ID casing of Application Insights resources
([#25628](https://github.com/hashicorp/terraform-provider-azurerm/issues/25628))&#xA;*
`azurerm_function_app_hybrid_connection` - can now use relay resources
created in a different resource group
([#25541](https://github.com/hashicorp/terraform-provider-azurerm/issues/25541))&#xA;*
`azurerm_kubernetes_cluster_node_pool` - prevent plan diff when the
`windows_profile.outbound_nat_enabled` property is unset
([#25644](https://github.com/hashicorp/terraform-provider-azurerm/issues/25644))&#xA;*
`azurerm_machine_learning_compute_cluster` - fix location to point to
parent resource for computes
([#25643](https://github.com/hashicorp/terraform-provider-azurerm/issues/25643))&#xA;*
`azurerm_machine_learning_compute_instance` - fix location to point to
parent resource for computes
([#25643](https://github.com/hashicorp/terraform-provider-azurerm/issues/25643))&#xA;*
`azurerm_storage_account` - check replication type when evaluating
support level for shares and queues for V1 storage accounts
([#25581](https://github.com/hashicorp/terraform-provider-azurerm/issues/25581))&#xA;*
`azurerm_storage_account` - added a sanity check for `dns_endpoint_type`
and `blob_properties.restore_policy`
([#25450](https://github.com/hashicorp/terraform-provider-azurerm/issues/25450))&#xA;*
`azurerm_web_app_hybrid_connection` - can now use relay resources
created in a different resource group
([#25541](https://github.com/hashicorp/terraform-provider-azurerm/issues/25541))&#xA;*
`azurerm_windows_web_app` - prevent removal of
`site_config.application_stack.node_version` when `app_settings` are
updated
([#25488](https://github.com/hashicorp/terraform-provider-azurerm/issues/25488))&#xA;*
`azurerm_windows_web_app_slot` - prevent removal of
`site_config.application_stack.node_version` when `app_settings` are
updated
([#25489](https://github.com/hashicorp/terraform-provider-azurerm/issues/25489))&#xA;&#xA;DEPRECATIONS:&#xA;&#xA;*
`logz` - the Logz resources are deprecated and will be removed in v4.0
of the AzureRM Provider since the API no longer allows new instances to
be created
([#25405](https://github.com/hashicorp/terraform-provider-azurerm/issues/25405))&#xA;*
`azurerm_machine_learning_compute_instance` - marked the `location`
field as deprecated in v4.0 of the provider
([#25643](https://github.com/hashicorp/terraform-provider-azurerm/issues/25643))&#xA;*
`azurerm_kubernetes_cluster` - the following properties have been
deprecated since the API no longer supports cluster creation with legacy
Azure Entra integration: `client_app_id`, `server_app_id`,
`server_app_secret` and `managed`
([#25200](https://github.com/hashicorp/terraform-provider-azurerm/issues/25200))&#xA;&#xA;&#xA;</pre>
            </details>
        </details>
<a
href="https://infra.ci.jenkins.io/job/updatecli/job/azure/job/main/117/">Jenkins
pipeline link</a>
    </action>
</Actions>

---

<table>
  <tr>
    <td width="77">
<img src="https://www.updatecli.io/images/updatecli.png" alt="Updatecli
logo" width="50" height="50">
    </td>
    <td>
      <p>
Created automatically by <a
href="https://www.updatecli.io/">Updatecli</a>
      </p>
      <details><summary>Options:</summary>
        <br />
<p>Most of Updatecli configuration is done via <a
href="https://www.updatecli.io/docs/prologue/quick-start/">its
manifest(s)</a>.</p>
        <ul>
<li>If you close this pull request, Updatecli will automatically reopen
it, the next time it runs.</li>
<li>If you close this pull request and delete the base branch, Updatecli
will automatically recreate it, erasing all previous commits made.</li>
        </ul>
        <p>
Feel free to report any issues at <a
href="https://github.com/updatecli/updatecli/issues">github.com/updatecli/updatecli</a>.<br
/>
If you find this tool useful, do not hesitate to star <a
href="https://github.com/updatecli/updatecli/stargazers">our GitHub
repository</a> as a sign of appreciation, and/or to tell us directly on
our <a
href="https://matrix.to/#/#Updatecli_community:gitter.im">chat</a>!
        </p>
      </details>
    </td>
  </tr>
</table>

Co-authored-by: Jenkins Infra Bot (updatecli) <60776566+jenkins-infra-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants