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 Source: azurerm_route_table: Added support for: disable_bgp_route_propagation #21940

Merged
merged 5 commits into from
Jul 17, 2023

Conversation

mfr-6
Copy link
Contributor

@mfr-6 mfr-6 commented May 25, 2023

The purpose of this PR is to add support for missing 'disable_bgp_route_propagation' field in the data source 'azurerm_route_table'

Details:
I'm parsing TF statefile using my code to extract resources that are already deployed to Azure in my environment.

I've noticed a situation where 'disable_bgp_route_propagation' is missing in terraform statefile when particular RouteTable is defined as data source even though this field is supported in regular tf resource.

I investigated this and it turned out that this field is not supported for data source route_table so I've added this into provider code.

I also noticed that we're missing Unittests for Data Source RouteTable (TestAccDataSourceRouteTable_basic) where other fields are not tested at all but documentation claims that when extending DataSource - unittest should be developed, so I've decided to add missing unittest to have whole Resource fields tested.

After adding support for a missing field - under "attributes" in statefile we can see 'disable_bgp_route_propagation' with boolean value.

That's my first time contributing to this project so please feel free to leave any comments on this if needed.

Tests:

make acctests SERVICE='network' TESTARGS='-run=TestAccDataSourceRouteTable_' TESTTIMEOUT='10m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/network -run=TestAccDataSourceRouteTable_ -timeout 10m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN TestAccDataSourceRouteTable_basic
=== PAUSE TestAccDataSourceRouteTable_basic
=== RUN TestAccDataSourceRouteTable_singleRoute
=== PAUSE TestAccDataSourceRouteTable_singleRoute
=== RUN TestAccDataSourceRouteTable_multipleRoutes
=== PAUSE TestAccDataSourceRouteTable_multipleRoutes
=== CONT TestAccDataSourceRouteTable_basic
=== CONT TestAccDataSourceRouteTable_multipleRoutes
=== CONT TestAccDataSourceRouteTable_singleRoute
--- PASS: TestAccDataSourceRouteTable_multipleRoutes (35.30s)
--- PASS: TestAccDataSourceRouteTable_singleRoute (39.15s)
--- PASS: TestAccDataSourceRouteTable_basic (43.33s)
PASS
ok github.com/hashicorp/terraform-provider-azurerm/internal/services/network 44.714s

@@ -25,6 +25,11 @@ func dataSourceRouteTable() *pluginsdk.Resource {
},

Schema: map[string]*pluginsdk.Schema{
"disable_bgp_route_propagation": {
Copy link
Member

Choose a reason for hiding this comment

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

We have a convention for the names of boolean properties so can we rename this to

Suggested change
"disable_bgp_route_propagation": {
"bgp_route_propagation_enabled": {

and also move this property down in the schema, since it's computed it should be defined after the required arguments.

Copy link
Contributor Author

@mfr-6 mfr-6 Jun 5, 2023

Choose a reason for hiding this comment

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

I wanted to reflect this property to be the same as it is in resource: https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/services/network/route_table_resource.go

Here we have "disable_bgp_route_propagation". I don't think we should change it to "bgp_route_propagation_enabled" - let's keep things consistent. Please let me know is that ok with you, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Apologies for taking a while to circle back to this.

It looks like the property in the resource was added quite a while ago, before the naming standard for booleans across the provider was introduced and began being enforced. These should be phased out and renamed - could you please add a comment above the property in the resource to the effect of
//TODO rename to bgp_route_propagation_enabled in 4.0
And rename this property to bgp_route_propagation_enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've applied fixes based on your feedback, thanks.

website/docs/d/route_table.html.markdown Outdated Show resolved Hide resolved
@@ -106,6 +111,10 @@ func dataSourceRouteTableRead(d *pluginsdk.ResourceData, meta interface{}) error
if err := d.Set("subnets", flattenRouteTableDataSourceSubnets(props.Subnets)); err != nil {
return err
}

if err := d.Set("disable_bgp_route_propagation", props.DisableBgpRoutePropagation); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if err := d.Set("disable_bgp_route_propagation", props.DisableBgpRoutePropagation); err != nil {
if err := d.Set("bgp_route_propagation_enabled", !props.DisableBgpRoutePropagation); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, let me check if I can apply this.

@stephybun stephybun force-pushed the dis_bgp_route_prop_in_data_rt branch from 5a2707f to e115d68 Compare July 17, 2023 08:34
@stephybun stephybun force-pushed the dis_bgp_route_prop_in_data_rt branch from 9d50541 to ebd6436 Compare July 17, 2023 08:42
@stephybun stephybun force-pushed the dis_bgp_route_prop_in_data_rt branch from ebd6436 to 04fb809 Compare July 17, 2023 08:44
Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

I hope you don't mind I rebased to fix a merge conflict as well as pushed a commit to nil-check the pointer so that we can get this into the next release.

This is looking good now and tests are passing so LGTM 🍉 Thanks @mfr-6!

@stephybun stephybun merged commit cd9c153 into hashicorp:main Jul 17, 2023
@github-actions github-actions bot added this to the v3.66.0 milestone Jul 17, 2023
stephybun added a commit that referenced this pull request Jul 17, 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 22, 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.

2 participants