-
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
New Data Source: azurerm_public_ips
#304
Conversation
Hey @hbuckle Thanks for opening this PR :) Taking a look at this, I think this Data Source might be more useful were it to return a list of Public IP's (and most of their properties) rather than just their ID's. We can apply the same filter logic to this so that it's possible to return only Public IP's which aren't attached to a VM/LB etc (and thus your workflow should still work 😄) - but the advantage here would be that the Data Source would work for multiple use-cases, here's an example of what I mean:
What do you think? :) Thanks! |
I have started looking at adding more properties, the only issue is that DNS settings are optional for public IPs, and for dynamic IPs they will only have an IP address if they are assigned. What's the right way to handle this, just add empty values to the results? |
Hey @hbuckle Sorry for the delayed response here - I'd missed we'd not replied to this!
So if there's no value we can either not set the object (in the case of a simple type like a String/Integer) - or set an empty value (in the case of a complex object). For instance, in the Hopefully that helps? :) Thanks! |
I've updated the data source so that it returns a list of public IPs. Each public IP is represented by a map with the IP's properties. |
Hi - does the updated version fit in with the suggested changes? Is it possible to merge? |
hey @hbuckle - sorry for the delayed review here - I'm taking another look at this now :) |
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 @hbuckle
Apologies for the delay in reviewing this PR - I've taken a look through and left some comments inline.
Thanks!
"public_ips": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeMap}, |
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.
Given this is a list - we need to specify each schema for the fields as in this example - could we update this to match?
if resp.StatusCode == http.StatusNotFound { | ||
d.SetId("") | ||
} | ||
return fmt.Errorf("Error making Read request on Azure resource group %s: %s", resGroup, err) |
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 make these formatting arguments%q
and %+v
?
attachedOnly := d.Get("attached").(bool) | ||
resp, err := publicIPClient.List(resGroup) | ||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { |
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.
can we update this to use the helper method utils.ResponseWasNotFound(resp)
- which also handles connection drops?
publicIPClient := meta.(*ArmClient).publicIPClient | ||
|
||
resGroup := d.Get("resource_group_name").(string) | ||
minimumCount, minimumCountOk := d.GetOk("minimum_count") |
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 think we can remove this field?
filteredIps = append(filteredIps, element) | ||
} | ||
} | ||
if minimumCountOk && len(filteredIps) < minimumCount.(int) { |
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 think now this is a more generic Data Source - that we can remove this?
m["fqdn"] = *element.PublicIPAddressPropertiesFormat.DNSSettings.Fqdn | ||
} else { | ||
m["fqdn"] = "" | ||
} |
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 think we can remove the else statement here - since it'll be set to an empty string automatically?
if element.PublicIPAddressPropertiesFormat.DNSSettings.DomainNameLabel != nil && *element.PublicIPAddressPropertiesFormat.DNSSettings.DomainNameLabel != "" { | ||
m["domain_name_label"] = *element.PublicIPAddressPropertiesFormat.DNSSettings.DomainNameLabel | ||
} else { | ||
m["domain_name_label"] = "" |
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 think we can remove the else statement here - since it'll be set to an empty string automatically?
for _, element := range filteredIps { | ||
m := make(map[string]string) | ||
m["public_ip_address_id"] = *element.ID | ||
m["name"] = *element.Name |
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.
can we add an if
check around this, in-case it's nil?
var results []map[string]string | ||
for _, element := range filteredIps { | ||
m := make(map[string]string) | ||
m["public_ip_address_id"] = *element.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.
can we add an if
check around this, in-case it's nil?
|
||
* `resource_group_name` - (Required) Specifies the name of the resource group. | ||
* `attached` - (Required) Whether to return public IPs that are attached or not. | ||
* `minimum_count` - (Optional) Specifies the minimum number of IP addresses that |
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.
(as above) can we remove this field?
Sorry for the delay, finally got around to updating this |
@tombuildsstuff any chance of going over this again? |
@hbuckle sorry, we're still trying to work through the backlog of pending PR reviews; I'll take a look into this shortly |
93953cd
to
056c6df
Compare
@hbuckle heads up that I've just rebased this on top of master so it merges cleanly, taking a look now :) |
``` $ acctests azurerm TestAccDataSourceAzureRMPublicIPs_ === RUN TestAccDataSourceAzureRMPublicIPs_basic --- PASS: TestAccDataSourceAzureRMPublicIPs_basic (85.74s) === RUN TestAccDataSourceAzureRMPublicIPs_mixed --- PASS: TestAccDataSourceAzureRMPublicIPs_mixed (82.73s) === RUN TestAccDataSourceAzureRMPublicIPs_count --- PASS: TestAccDataSourceAzureRMPublicIPs_count (79.26s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 247.767s ```
@hbuckle I hope you don't mind, but I've pushed some commits to add support for also filtering by the prefix of the |
Tests pass: ``` $ acctests azurerm TestAccDataSourceAzureRMPublicIPs_ === RUN TestAccDataSourceAzureRMPublicIPs_namePrefix --- PASS: TestAccDataSourceAzureRMPublicIPs_namePrefix (86.67s) === RUN TestAccDataSourceAzureRMPublicIPs_assigned --- PASS: TestAccDataSourceAzureRMPublicIPs_assigned (90.43s) === RUN TestAccDataSourceAzureRMPublicIPs_allocationType --- PASS: TestAccDataSourceAzureRMPublicIPs_allocationType (82.07s) ```
azurerm_public_ips
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.
LGTM minus the one comment and if the tests pass
## Argument Reference | ||
|
||
* `resource_group_name` - (Required) Specifies the name of the resource group. | ||
* `attached` - (Optional) Should we only return IP Addresses which are attached to a device (VM/LB) etc? |
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 wouldn't frame this as a question and instead have it read like Returns IP Address that are attached to a device or not attached to a device
or something to that effect.
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 👉 hashibot-feedback@hashicorp.com. Thanks! |
Adds a new data source to retrieve the IDs of unassigned public IP addresses from a resource group. We have a pool of public IP addresses that have been pre-whitelisted by third parties so this will allow us to pick them up dynamically instead of needing to hardcode the IDs into our configuration.
This is my first time working with go and terraform so any feedback is appreciated!