-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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_iothub
- support for new property endpoint.subscription_id
#27524
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR!
I've taken a look through and left some comments inline, but this is mostly looking good to me 👍
if v := d.GetRawConfig().AsValueMap()["endpoint"].AsValueSlice()[k].AsValueMap()["subscription_id"]; v.IsNull() { | ||
subscriptionID = subscriptionId | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting the schema as O+C, can we make it Optional only by adding a restriction to this attribute (with documenting clearly): If the subscription id is the same as the provider id, simply set it as null or an empty string. This makes sense to me as users need to specify this attribute, only when it is different than the provider's subscription id.
With this, you only need to do a conditional set to state during the flattening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do it this way, it will result in the subscription_id
on the service side having a value, but the subscription_id
in the state file will be empty. This might confuse the user, so I still recommend using my method to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation has no issue in itself, but I'm more concerned about the complexity it brings, from the maintenance perspective. If we decide to go down this route, please remember to add comments to clearly describe the raw config handling is only deant for the case that the user has a eventhub whose endpoint's subscription is not the provider's one. Then the user wants to reset it to the provider's one by unset the subscription_id
. The current comment doesn't make sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I updated the descriptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to do this? and how reliable is it given the issues we have with GetOkExists etc not working in every situation?
i do worry about adding this as it will be technical debt for when the transition to framework is done
this is only to enable a user to unset the value and have it default to the current provider subscription?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Using "d.GetRawConfig()" is to align with the previous TF behavior to enabled a user to unset the value and have it default to the current provider subscription for unblocking the existing users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have seperate resources for this to in the form of azurerm_iothub_endpoint_* - we should probably fix this for those resources too?
@@ -376,6 +376,14 @@ func resourceIotHub() *pluginsdk.Resource { | |||
}, | |||
|
|||
"resource_group_name": commonschema.ResourceGroupNameOptional(), | |||
|
|||
// `Computed: true` is required since this property would always be set even if it isn't specified in the tf config, otherwise it would cause difference and block the existing users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we plase make this
// `Computed: true` is required since this property would always be set even if it isn't specified in the tf config, otherwise it would cause difference and block the existing users | |
// NOTE: O+C : required since this property would always be set even if it isn't specified in the tf config, otherwise it would cause a diff and break existing users |
to match other O+C properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
website/docs/r/iothub.html.markdown
Outdated
@@ -219,6 +219,10 @@ An `endpoint` block supports the following: | |||
|
|||
* `resource_group_name` - (Optional) The resource group in which the endpoint will be created. | |||
|
|||
* `subscription_id` - (Optional) The subscription ID for the endpoint. | |||
|
|||
~> **NOTE:** When `subscription_id` isn't specified in the tf config, it would be set with the provider's subscription ID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~> **NOTE:** When `subscription_id` isn't specified in the tf config, it would be set with the provider's subscription ID. | |
~> **NOTE:** When `subscription_id` isn't specified it will be set to the subscription ID used in the provider block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
if v := d.GetRawConfig().AsValueMap()["endpoint"].AsValueSlice()[k].AsValueMap()["subscription_id"]; v.IsNull() { | ||
subscriptionID = subscriptionId | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to do this? and how reliable is it given the issues we have with GetOkExists etc not working in every situation?
i do worry about adding this as it will be technical debt for when the transition to framework is done
this is only to enable a user to unset the value and have it default to the current provider subscription?
endpoint := endpointRaw.(map[string]interface{}) | ||
|
||
t := endpoint["type"] | ||
name := endpoint["name"].(string) | ||
resourceGroup := endpoint["resource_group_name"].(string) | ||
authenticationType := devices.AuthenticationType(endpoint["authentication_type"].(string)) | ||
subscriptionID := subscriptionId | ||
|
||
subscriptionID := endpoint["subscription_id"].(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
subscriptionID := endpoint["subscription_id"].(string) | |
if v, ok := config["subscription_id"]; ok && v.(string) != "" { | |
subscriptionID = v.(string) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@katbyte , thanks for the comments. Yes, we also need to fix "azurerm_iothub_endpoint_*". I think we can fix them in the separate PR. Actually, I suggested users to deploy IotHub and EventHub in the same subscription and they accept it and the issue is marked as resolved. So can we close this PR? |
@neil-yechenwei - no i think we should still support the new property as it is something the API supports and if one person has run into it, someone else likely has/will and might have a reason to do so |
@katbyte , thanks for double confirmation. |
@katbyte , please continue to review this PR. Thanks. |
@neil-yechenwei - please also fix the azurerm_iothub_endpoint_* resources too |
@katbyte , I updated PR to fix the azurerm_iothub_endpoint_* resources. Below is the latest test result I just now triggered. Below failed test cases are also failed with same error on Teamcity Daily Run. So they're not related with this PR. |
Community Note
Description
Recently we got a MS Internal support ticket created by customer. Customer said that "Event Hub Status" button on the "IoTHub" resource is not highlighted in blue on Azure Portal like below screenshot after the IoTHub resource is created. After I investigated, I found that this issue only happens when IoTHub and the related EventHub are in the different subscriptions. Then I checked TF code. I found currently TF always sets "endpoint.subscriptionId" with the subscription ID in the current TF context. So it's unexpected behavior since service team confirmed that service API allows IoTHub and EventHub are in the different subscriptions. So we need to expose "endpoint.subscription_id" to users.
After I applied this PR fix, now "Event Hub Status" button on the "IoTHub" resource is highlighted in blue on Azure Portal.
PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Below failed test case is also failed with same error on Teamcity Daily Run. So it's not related with this PR.
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_iothub
- support for new propertyendpoint.subscription_id
This is a (please select all that apply):
Note
If this PR changes meaningfully during the course of review please update the title and description as required.