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

Adding new application_gateway data_source #10268

Merged

Conversation

petems
Copy link
Contributor

@petems petems commented Jan 21, 2021

Closes #5030

Draft for now, as I want to make sure I'm making the data_source correctly, after that I'll add the rest of the attributes

@ghost ghost added the size/M label Jan 21, 2021
@petems petems force-pushed the data_source_azurerm_application_gateway branch 4 times, most recently from fd74b6a to 6f57dbe Compare January 21, 2021 12:46
Copy link
Member

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

Thanks for opening this PR.

I've taken a look through and this is off to a good start - I've taken a look through and left some comments inline, as mentioned offline this'll need to be registered here to be usable in the provider: https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/azurerm/internal/services/network/registration.go#L24

Thanks!

@petems
Copy link
Contributor Author

petems commented Jan 22, 2021

I've pulled most of the logic from the resource, so there's a lot of duplicted code here, is there value in refactoring this into a shared librariy? If so, is there an example out there?

@ghost ghost removed the waiting-response label Jan 22, 2021
@petems petems force-pushed the data_source_azurerm_application_gateway branch from bcb5127 to b020e6a Compare January 22, 2021 03:07
@ghost ghost added size/XXL and removed size/M labels Jan 22, 2021
@katbyte
Copy link
Collaborator

katbyte commented Jan 23, 2021

@petems - we're going to need to flip all the properties to computed as this is a data source

@petems petems force-pushed the data_source_azurerm_application_gateway branch 2 times, most recently from 7fd3af2 to 6ca8c85 Compare February 5, 2021 10:45
@ghost ghost added size/L and removed size/XXL labels Feb 5, 2021
@petems
Copy link
Contributor Author

petems commented Feb 5, 2021

@katbyte done, everything's set as computed except name and Resource Group

@ghost ghost removed the waiting-response label Feb 5, 2021
@petems petems force-pushed the data_source_azurerm_application_gateway branch 2 times, most recently from 89e7c26 to 38418e1 Compare February 5, 2021 17:41
Copy link
Member

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

Thanks for pushing those changes - I've taken a look through and left some comments inline, if we can get those sorted (and subsequently add/generate some documentation, there's details on how to generate that in the readme) - then we should be able to run the tests here 👍

Thanks!

return err
}
resGroup := id.ResourceGroup
name := id.Path["applicationGateways"]
Copy link
Member

Choose a reason for hiding this comment

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

whilst this'd work for a Resource (since we have an ID) - it won't work for a Data Source, so this'd want to be:

Suggested change
name := id.Path["applicationGateways"]
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

if utils.ResponseWasNotFound(applicationGateway.Response) {
log.Printf("[DEBUG] Application Gateway %q was not found in Resource Group %q - removing from state", name, resGroup)
d.SetId("")
return nil
Copy link
Member

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 rather than a Resource, we should raise an error here when this doesn't exist:

Suggested change
return nil
return fmt.Errorf("Application Gateway %q was not found in Resource Group %q", name, resGroup)

if location := applicationGateway.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
d.Set("zones", applicationGateway.Zones)
Copy link
Member

Choose a reason for hiding this comment

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

this data source only defines name, location, resource_group_name, tags above, these other fields don't exist (so will raise an error) - can we remove them, or add the additional fields to the schema?

resource_group_name = azurerm_application_gateway.test.resource_group_name
name = azurerm_application_gateway.test.name
}
`, AppGatewayResource{}.basic(data))
Copy link
Member

Choose a reason for hiding this comment

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

sorry, my bad - the type name for this is

Suggested change
`, AppGatewayResource{}.basic(data))
`, ApplicationGatewayResource{}.basic(data))

@tombuildsstuff tombuildsstuff force-pushed the data_source_azurerm_application_gateway branch from 38418e1 to ea19600 Compare February 15, 2021 16:32
@ghost ghost added size/XL documentation and removed size/L labels Feb 15, 2021
@tombuildsstuff tombuildsstuff dismissed their stale review February 15, 2021 16:33

dismissing since I've pushed changes

@tombuildsstuff
Copy link
Member

Tests look good 👍

@tombuildsstuff tombuildsstuff merged commit 2db003c into hashicorp:master Feb 16, 2021
tombuildsstuff added a commit that referenced this pull request Feb 16, 2021
@ghost
Copy link

ghost commented Feb 18, 2021

This has been released in version 2.48.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.48.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Mar 18, 2021

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!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 18, 2021
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.

New Data Source: azurerm_application_gateway
3 participants