-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Feature: Add 'ip_version' to Public IP Address #2019
Conversation
be408f1
to
b2fbe78
Compare
Currently added the ip_version as an optional argument to avoid breaking changes. Could be changed to be required at a later time. |
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.
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
Outdated
@@ -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))) |
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.
it appears you are setting this twice, the one below is the way to go
f798e98
to
50d5f79
Compare
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.
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!
azurerm/data_source_public_ip.go
Outdated
@@ -20,6 +20,11 @@ func dataSourceArmPublicIP() *schema.Resource { | |||
|
|||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | |||
|
|||
"ip_version": { | |||
Type: schema.TypeString, | |||
Optional: true, |
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.
since this is a Data Source this needs to be Computed
rather than Optional
(since the information is retrieved but not setable)
azurerm/resource_arm_public_ip.go
Outdated
string(network.IPv6), | ||
}, true), | ||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
StateFunc: ignoreCaseStateFunc, |
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.
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)
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 you not think it should be accepted if someone decides to use "ipv4" instead of "IPv4"?
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 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
)
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.
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?
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.
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
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.
Cool. @tombuildsstuff I'll make those last changes then and that should be it. Thanks for helping with my first contribution to open source! :)
azurerm/resource_arm_public_ip.go
Outdated
ipVersion := network.IPVersion(d.Get("ip_version").(string)) | ||
|
||
if strings.ToLower(string(ipVersion)) == "ipv6" { | ||
if strings.ToLower(string(ipAllocationMethod)) == "static" { |
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.
minor rather than lower-casing it we can use strings.EqualsFold(string(ipAllocationMethod), "static")
here to use a case-invarient check
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.
Am making the change. But I am curious, is there a particular reason for this preference?
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.
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? 🤔
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.
Go would not complain in this case of comparing an enum and a 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.
@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. |
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.
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`
Update to include 'ip_version' for data and resource documentation.
50d5f79
to
25adb97
Compare
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.
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!
dismissing since changes have been pushed
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.
``` $ acctests azurerm TestAccAzureRMPublicIpStatic_zones === RUN TestAccAzureRMPublicIpStatic_zones --- PASS: TestAccAzureRMPublicIpStatic_zones (111.60s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 113.048s ```
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:
New Test:
Since this LGTM I'll kick off the data source tests and merge this shortly - thanks again for this contribution 👍 Thanks! |
Data Source tests pass:
|
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! |
Fixes #412