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

new resource:azurerm_mobile_network_attached_data_network; new datasource: azurerm_mobile_network_attached_data_network #22168

Merged
merged 12 commits into from
Jul 21, 2023

Conversation

ziyeqf
Copy link
Contributor

@ziyeqf ziyeqf commented Jun 14, 2023

overall

this is the second to the last PR, we are almost there.

order | name 
0     | azurerm_mobile_network                              ✅
1     | azurerm_mobile_network_site                         ✅
1     | azurerm_mobile_network_data_network                 ✅
1     | azurerm_mobile_network_service                      ✅
1     | azurerm_mobile_network_slice                        ✅
1     | azurerm_mobile_network_sim_group                    ✅
2     | azurerm_mobile_network_packet_core_control_plane    ✅
2     | azurerm_mobile_network_sim_policy                   ✅
3     | azurerm_mobile_network_packet_core_data_plane       ✅
4     | azurerm_mobile_network_attached_data_network        <- this one
5     | azurerm_mobile_network_sim        

test

❯ tftest mobilenetwork TestAccMobileNetworkAttachedDataNetwork      
=== RUN   TestAccMobileNetworkAttachedDataNetworkDataSource_basic
=== PAUSE TestAccMobileNetworkAttachedDataNetworkDataSource_basic
=== RUN   TestAccMobileNetworkAttachedDataNetwork_basic
=== PAUSE TestAccMobileNetworkAttachedDataNetwork_basic
=== RUN   TestAccMobileNetworkAttachedDataNetwork_withDataAccess
=== PAUSE TestAccMobileNetworkAttachedDataNetwork_withDataAccess
=== RUN   TestAccMobileNetworkAttachedDataNetwork_requiresImport
=== PAUSE TestAccMobileNetworkAttachedDataNetwork_requiresImport
=== RUN   TestAccMobileNetworkAttachedDataNetwork_complete
=== PAUSE TestAccMobileNetworkAttachedDataNetwork_complete
=== RUN   TestAccMobileNetworkAttachedDataNetwork_update
=== PAUSE TestAccMobileNetworkAttachedDataNetwork_update
=== CONT  TestAccMobileNetworkAttachedDataNetworkDataSource_basic
=== CONT  TestAccMobileNetworkAttachedDataNetwork_requiresImport
=== CONT  TestAccMobileNetworkAttachedDataNetwork_update
=== CONT  TestAccMobileNetworkAttachedDataNetwork_complete
=== CONT  TestAccMobileNetworkAttachedDataNetwork_withDataAccess
=== CONT  TestAccMobileNetworkAttachedDataNetwork_basic
--- PASS: TestAccMobileNetworkAttachedDataNetwork_basic (962.32s)
--- PASS: TestAccMobileNetworkAttachedDataNetwork_withDataAccess (973.70s)
--- PASS: TestAccMobileNetworkAttachedDataNetwork_complete (1081.74s)
--- PASS: TestAccMobileNetworkAttachedDataNetwork_requiresImport (1129.70s)
--- PASS: TestAccMobileNetworkAttachedDataNetworkDataSource_basic (1135.11s)
--- PASS: TestAccMobileNetworkAttachedDataNetwork_update (1177.26s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/mobilenetwork 1177.339s

…source: `azurerm_mobile_network_attached_data_network`

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Copy link
Collaborator

@magodo magodo left a 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 👍

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>

func (r AttachedDataNetworkDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"mobile_network_data_network_name": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we rename this to name, or do we want to rename the corresponding field in the model from Name to MobileNetworkDataNetworkName to be consistent?

Copy link
Member

Choose a reason for hiding this comment

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

This was marked resolved but I don't see any discussion or explanation, can we have some context?

Copy link
Member

Choose a reason for hiding this comment

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

On reflection, given that this needs to be the same value as the corresponding Mobile Network Data Network's name value, we should in fact use the ID for that here and extract the name from it. This ensures the value is consistent, provides additional validation, and the value can be pulled from a reference allowing an explicit dependency between the resources.

Suggested change
"mobile_network_data_network_name": {
"mobile_network_data_network_id": {

Copy link
Contributor Author

@ziyeqf ziyeqf Jun 29, 2023

Choose a reason for hiding this comment

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

The reason to use name instead of id is the id format of azurerm_mobile_network_attached_data_network does not contain mobileNetworkName, the response/model does not contain it either... Then we cannot set the id in read func

attached_data_network_id:/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MobileNetwork/packetCoreControlPlanes/{packetCoreControlPlaneName}/packetCoreDataPlanes/{packetCoreDataPlaneName}/attachedDataNetworks/{attachedDataNetworkName}

data_network_id: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MobileNetwork/mobileNetworks/{mobileNetworkName}/dataNetworks/{dataNetworkName}

Copy link
Contributor Author

@ziyeqf ziyeqf Jun 29, 2023

Choose a reason for hiding this comment

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

Screenshot 2023-06-29 at 11 15 13

Here is the dependency between these resources, black arrow means dependency, yellow arrow means id path. As there is a N:1 relation between azurerm_mobile_network_site and azurerm_mobile_network_packet_core_control_plane, itt seems there is no way get the id of azurerm_mobile_network_data_network. WDYT?

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
@magodo
Copy link
Collaborator

magodo commented Jun 27, 2023

@ziyeqf Thanks! LGTM 👍

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Hi @ziyeqf, thanks for this new resource and data source.

Following on from the previous review, I've added some additional comments and a recommended slight design change that should improve the user experience and make things a little more reliable and structured in user configs. If you can take a look, we can continue review.

Thanks!

}

func (r AttachedDataNetworkDataSource) ModelObject() interface{} {
return &AttachedDataNetworkModel{}
Copy link
Member

Choose a reason for hiding this comment

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

The model for the data source should be separately defined to the resource model. Whilst they can be the same, they will often contain different properties so we should always start out with a discrete struct for the data source.

%s

resource "azurerm_mobile_network_attached_data_network" "import" {
mobile_network_data_network_name = azurerm_mobile_network_data_network.test.name
Copy link
Member

Choose a reason for hiding this comment

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

these values should all be taken as references from the test resource, for example:

Suggested change
mobile_network_data_network_name = azurerm_mobile_network_data_network.test.name
mobile_network_data_network_name = azurerm_mobile_network_attached_data_network.test.name

Comment on lines 180 to 181

depends_on = [azurerm_mobile_network_data_network.test]
Copy link
Member

Choose a reason for hiding this comment

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

The dependency is already established here by mobile_network_data_network_name .

Suggested change
depends_on = [azurerm_mobile_network_data_network.test]

Comment on lines 224 to 225

depends_on = [azurerm_mobile_network_data_network.test]
Copy link
Member

Choose a reason for hiding this comment

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

The dependency is already established here by mobile_network_data_network_name .

Suggested change
depends_on = [azurerm_mobile_network_data_network.test]

Comment on lines 95 to 98
* `create` - (Defaults to 180 minutes) Used when creating the Mobile Network Attached Data Network.
* `read` - (Defaults to 5 minutes) Used when retrieving the Mobile Network Attached Data Network.
* `update` - (Defaults to 180 minutes) Used when updating the Mobile Network Attached Data Network.
* `delete` - (Defaults to 180 minutes) Used when deleting the Mobile Network Attached Data Network.
Copy link
Member

Choose a reason for hiding this comment

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

This is a data source, only read timeouts apply here

Suggested change
* `create` - (Defaults to 180 minutes) Used when creating the Mobile Network Attached Data Network.
* `read` - (Defaults to 5 minutes) Used when retrieving the Mobile Network Attached Data Network.
* `update` - (Defaults to 180 minutes) Used when updating the Mobile Network Attached Data Network.
* `delete` - (Defaults to 180 minutes) Used when deleting the Mobile Network Attached Data Network.
* `read` - (Defaults to 5 minutes) Used when retrieving the Mobile Network Attached Data Network.

Comment on lines 99 to 102

## Import

Mobile Network Attached Data Network can be imported using the `resource id`, e.g.
Copy link
Member

Choose a reason for hiding this comment

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

Imports don't apply to data sources

Suggested change
## Import
Mobile Network Attached Data Network can be imported using the `resource id`, e.g.

key = "value"
}

depends_on = [azurerm_mobile_network_data_network.example]
Copy link
Member

Choose a reason for hiding this comment

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

again, this was marked as resolved with no explanation, can we have context here?


func (r AttachedDataNetworkDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"mobile_network_data_network_name": {
Copy link
Member

Choose a reason for hiding this comment

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

On reflection, given that this needs to be the same value as the corresponding Mobile Network Data Network's name value, we should in fact use the ID for that here and extract the name from it. This ensures the value is consistent, provides additional validation, and the value can be pulled from a reference allowing an explicit dependency between the resources.

Suggested change
"mobile_network_data_network_name": {
"mobile_network_data_network_id": {

Comment on lines +70 to +75
"mobile_network_data_network_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
Copy link
Member

Choose a reason for hiding this comment

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

As above, this should be the ID of the related resource:

Suggested change
"mobile_network_data_network_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"mobile_network_data_network_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: datanetwork.ValidateDataNetworkID,
},

From this we can extract the correct name

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
@ziyeqf
Copy link
Contributor Author

ziyeqf commented Jul 4, 2023

kindly ping for review

@ziyeqf ziyeqf requested a review from jackofallops July 10, 2023 02:39
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
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.

LGTM ☎️

@ziyeqf
Copy link
Contributor Author

ziyeqf commented Jul 20, 2023

just to confirm are we ready to merge or waiting for another look?

@katbyte katbyte merged commit 894f503 into hashicorp:main Jul 21, 2023
23 checks passed
@github-actions github-actions bot added this to the v3.66.0 milestone Jul 21, 2023
katbyte added a commit that referenced this pull request Jul 21, 2023
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants