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

Feature: Add 'ip_version' to Public IP Address #2019

Merged
merged 6 commits into from
Oct 13, 2018

Conversation

Krueladin
Copy link
Contributor

@Krueladin Krueladin commented Oct 4, 2018

Fixes #412

@ghost ghost added the size/L label Oct 4, 2018
@Krueladin Krueladin force-pushed the feature-public-ip-version branch from be408f1 to b2fbe78 Compare October 4, 2018 03:22
@Krueladin Krueladin changed the title Feature: Add 'ip_version' to Public IPv6 Address Feature: Add 'ip_version' to Public IP Address Oct 4, 2018
@Krueladin
Copy link
Contributor Author

Krueladin commented Oct 4, 2018

Currently added the ip_version as an optional argument to avoid breaking changes. Could be changed to be required at a later time.

@metacpp metacpp requested a review from JunyiYi October 4, 2018 06:11
@metacpp metacpp modified the milestone: Soon Oct 4, 2018
katbyte
katbyte previously requested changes Oct 4, 2018
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.

Hi @Krueladin,

Thank you for the PR, the comprehensive tests are appreciated! Aside from one comment I've left inline my only concern is the documentation should be updated to reflect the new property

Also the datasource should be updated with the new property as well.

azurerm/resource_arm_public_ip.go Show resolved Hide resolved
@@ -209,6 +230,7 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}
d.Set("ip_version", strings.ToLower(string(resp.PublicIPAddressPropertiesFormat.PublicIPAddressVersion)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

it appears you are setting this twice, the one below is the way to go

azurerm/resource_arm_public_ip.go Show resolved Hide resolved
@katbyte katbyte added this to the 1.17.0 milestone Oct 4, 2018
@Krueladin Krueladin force-pushed the feature-public-ip-version branch 2 times, most recently from f798e98 to 50d5f79 Compare October 5, 2018 03:16
Copy link
Contributor

@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.

hey @Krueladin

Thanks for pushing those changes - I've taken a look through and left a couple of extra (minor) comments inline, if we can fix those up then this otherwise LGTM 👍

Thanks!

@@ -20,6 +20,11 @@ func dataSourceArmPublicIP() *schema.Resource {

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"ip_version": {
Type: schema.TypeString,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a Data Source this needs to be Computed rather than Optional (since the information is retrieved but not setable)

string(network.IPv6),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
StateFunc: ignoreCaseStateFunc,
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a new field, can we make this case-sensitive? (e.g. true -> false in the validate func, and remove the DiffSuppressFunc/StateFunc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you not think it should be accepted if someone decides to use "ipv4" instead of "IPv4"?

Copy link
Contributor

Choose a reason for hiding this comment

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

the issue's to do with casting the string value to an Enum - if the casing doesn't match, Go defaults to the last value in the Enum, meaning the wrong value could be selected; as such we need to ensure the correct casing is used here (e.g. IPv4 rather than ipv4)

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'm making the change, but I haven't seen this as an issue yet. wouldn't the only fear of this be in reading the data? And with the data object IPv6 is the last value, but the test still is able to read IPv4. And there were many purposefully strangely cased examples in my tests. Where in particular could you see this coming from?

Copy link
Contributor

Choose a reason for hiding this comment

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

indeed - it's possible for the casing to be different for example where resources are provisioned via an ARM Template/the CLI and then imported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. @tombuildsstuff I'll make those last changes then and that should be it. Thanks for helping with my first contribution to open source! :)

ipVersion := network.IPVersion(d.Get("ip_version").(string))

if strings.ToLower(string(ipVersion)) == "ipv6" {
if strings.ToLower(string(ipAllocationMethod)) == "static" {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor rather than lower-casing it we can use strings.EqualsFold(string(ipAllocationMethod), "static") here to use a case-invarient check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am making the change. But I am curious, is there a particular reason for this preference?

Copy link
Contributor

@tombuildsstuff tombuildsstuff Oct 5, 2018

Choose a reason for hiding this comment

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

heh sorry I missed out using the Enum here - in general we'd tend to do something like:

strings.EqualsFold(string(ipAllocationMethod), string(network.Static))

although in this specific case (if we remove the case sensitivity) - we should actually be able to do a strict equality comparison I guess? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Go would not complain in this case of comparing an enum and a string?

Copy link
Contributor

@tombuildsstuff tombuildsstuff Oct 8, 2018

Choose a reason for hiding this comment

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

@Krueladin sorry, that's a typo - it would - I've updated the example

@@ -107,4 +107,5 @@ output "public_ip_address" {
* `idle_timeout_in_minutes` - Specifies the timeout for the TCP idle connection.
* `fqdn` - Fully qualified domain name of the A DNS record associated with the public IP. This is the concatenation of the domainNameLabel and the regionalized DNS zone.
* `ip_address` - The IP address value that was allocated.
* `ip_version` - The IP Version to use, IPv6 or IPv4. Must be used with a 'dynamic' allocation type.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor since this is only retrieving information about the Public IP - can we update this to a slightly different tense (and remove the information about dynamic being required, since this is readonly):

* `ip_version` - The IP version being used, for example `IPv4` or `IPv6`

@Krueladin Krueladin force-pushed the feature-public-ip-version branch from 50d5f79 to 25adb97 Compare October 5, 2018 05:00
Copy link
Contributor

@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.

hey @Krueladin

Thanks for pushing those changes - I've taken a look through and this now LGTM 👍 so I'll kick off the tests shortly :)

Thanks!

@tombuildsstuff tombuildsstuff dismissed katbyte’s stale review October 10, 2018 05:57

dismissing since changes have been pushed

Copy link
Contributor

@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.

hey @Krueladin

Thanks for pushing those changes - this now LGTM 👍

Thanks!

@tombuildsstuff tombuildsstuff removed the request for review from JunyiYi October 12, 2018 22:33
```
$ acctests azurerm TestAccAzureRMPublicIpStatic_zones
=== RUN   TestAccAzureRMPublicIpStatic_zones
--- PASS: TestAccAzureRMPublicIpStatic_zones (111.60s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	113.048s
```
@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Oct 13, 2018

hey @Krueladin

I've run the tests and pushed a couple of commits (to revert my earlier change & to add back in a missing test, I hope you don't mind) - and this now LGTM:

acctests azurerm TestAccAzureRMPublicIpStatic_basic
=== RUN   TestAccAzureRMPublicIpStatic_basic
--- PASS: TestAccAzureRMPublicIpStatic_basic (119.63s)
=== RUN   TestAccAzureRMPublicIpStatic_basic_withDNSLabel
--- PASS: TestAccAzureRMPublicIpStatic_basic_withDNSLabel (110.90s)
=== RUN   TestAccAzureRMPublicIpStatic_basic_defaultsToIPv4
--- PASS: TestAccAzureRMPublicIpStatic_basic_defaultsToIPv4 (98.85s)
=== RUN   TestAccAzureRMPublicIpStatic_basic_withIPv4
--- PASS: TestAccAzureRMPublicIpStatic_basic_withIPv4 (111.90s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	442.395s

New Test:

$ acctests azurerm TestAccAzureRMPublicIpStatic_zones
=== RUN   TestAccAzureRMPublicIpStatic_zones
--- PASS: TestAccAzureRMPublicIpStatic_zones (111.60s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	113.048s

Since this LGTM I'll kick off the data source tests and merge this shortly - thanks again for this contribution 👍

Thanks!

@tombuildsstuff
Copy link
Contributor

Data Source tests pass:

$ acctests azurerm TestAccDataSourceAzureRMPublicIP
=== RUN   TestAccDataSourceAzureRMPublicIP_basic
--- PASS: TestAccDataSourceAzureRMPublicIP_basic (117.13s)
=== RUN   TestAccDataSourceAzureRMPublicIPs_namePrefix
--- PASS: TestAccDataSourceAzureRMPublicIPs_namePrefix (147.84s)
=== RUN   TestAccDataSourceAzureRMPublicIPs_assigned
--- PASS: TestAccDataSourceAzureRMPublicIPs_assigned (168.31s)
=== RUN   TestAccDataSourceAzureRMPublicIPs_allocationType
--- PASS: TestAccDataSourceAzureRMPublicIPs_allocationType (141.25s)
PASS

@tombuildsstuff tombuildsstuff merged commit 5862ac5 into hashicorp:master Oct 13, 2018
tombuildsstuff added a commit that referenced this pull request Oct 13, 2018
@ghost
Copy link

ghost commented Mar 6, 2019

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 6, 2019
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.

4 participants