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

Firewall network field now supports self_link in addition of name #477

Merged
merged 2 commits into from
Sep 28, 2017

Conversation

rosbo
Copy link
Contributor

@rosbo rosbo commented Sep 27, 2017

Fixes #377.

network field for other resources will be able to reuse NetworkFieldValue. #431 is listing the other resources with a network field that is not properly supported.

@rosbo rosbo requested a review from selmanj September 27, 2017 21:49
@@ -299,7 +331,7 @@ func testAccComputeFirewall_update(network, firewall string) string {
resource "google_compute_firewall" "foobar" {
name = "firewall-test-%s"
description = "Resource created for Terraform acceptance testing"
network = "${google_compute_network.foobar.name}"
network = "${google_compute_network.foobar.self_link}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: Other tests are referencing the network by name.

// - projects/myproject/global/networks/my-network
// - global/networks/my-network (default project is used)
// - my-network (default project is used)
func ParseNetworkFieldValue(network string, config *Config) *NetworkFieldValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

Brainstorming outloud here; none of these are action items:

I wonder if there's a way we can eventually merge all the url parsing code; unfortunately it doesn't seem obvious how since each has their own path scheme. Right now the code is relatively short and simple so the cost of having it isn't much.

Maybe at some point we should combine them all into a single namespace? urltools or resourcetools or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I think once we have created a few of these FieldValue classes, we will see patterns emerging and we can create common utils to make it easy to create these FieldValue classes.


const networkLinkTemplate = "projects/%s/global/networks/%s"

var networkLinkRegex = regexp.MustCompile(fmt.Sprintf(networkLinkTemplate, "(.+)", "(.+)"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This made me quite uncomfortable; something about printing regex chunks into another regex made me squirm a bit

How do you feel about just inlining the regex here?

}
}

func (f *NetworkFieldValue) RelativeLink() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor quibble; if the struct is small it's nice to not use a ptr here for the receiving struct; that way its obvious that your method doesn't mutate the struct its called on (there's runtime benefits as well but I don't think we should be concerned with that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -405,12 +404,6 @@ func resourceComputeFirewallDelete(d *schema.ResourceData, meta interface{}) err

func resourceFirewall(d *schema.ResourceData, meta interface{}, computeApiVersion ComputeApiVersion) (*computeBeta.Firewall, error) {
config := meta.(*Config)
project, _ := getProject(d, config)

network, err := config.clientCompute.Networks.Get(project, d.Get("network").(string)).Do()
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, you eliminated an API call with this change :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. And the other good thing is that sometimes, this call was failing if the user didn't have the iam permission for reading the network! It was kind of unexpected since we are setting up a firewall.


const networkLinkTemplate = "projects/%s/global/networks/%s"

var networkLinkRegex = regexp.MustCompile(fmt.Sprintf(networkLinkTemplate, "(.+)", "(.+)"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done

// - projects/myproject/global/networks/my-network
// - global/networks/my-network (default project is used)
// - my-network (default project is used)
func ParseNetworkFieldValue(network string, config *Config) *NetworkFieldValue {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I think once we have created a few of these FieldValue classes, we will see patterns emerging and we can create common utils to make it easy to create these FieldValue classes.

@@ -405,12 +404,6 @@ func resourceComputeFirewallDelete(d *schema.ResourceData, meta interface{}) err

func resourceFirewall(d *schema.ResourceData, meta interface{}, computeApiVersion ComputeApiVersion) (*computeBeta.Firewall, error) {
config := meta.(*Config)
project, _ := getProject(d, config)

network, err := config.clientCompute.Networks.Get(project, d.Get("network").(string)).Do()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. And the other good thing is that sometimes, this call was failing if the user didn't have the iam permission for reading the network! It was kind of unexpected since we are setting up a firewall.

}
}

func (f *NetworkFieldValue) RelativeLink() string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rosbo rosbo merged commit bc25c02 into hashicorp:master Sep 28, 2017
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
Autogen for region read, cloud scheduler examples
@ghost
Copy link

ghost commented Mar 30, 2020

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 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google_compute_firewall should accept network self-link
2 participants