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

Add new resource google_compute_network_peering #259

Merged
merged 5 commits into from
Jul 28, 2017

Conversation

rosbo
Copy link
Contributor

@rosbo rosbo commented Jul 27, 2017

Fixes #178

cc @rileykarson @danawillow

Add the vpc peering functionality using its own resource.
I opened another PR yesterday with an implementation embedded into the google_compute_network.

The main advantage of having a separate resource for network peering is to go around the circlular dependency issue since both network needs to point at each other. See #242 for more details about the issue.

The main drawback of having a separate resource is that one can create peering manually (outside of Terraform) and Terraform will never now about it.

@rosbo rosbo requested review from danawillow and rileykarson July 27, 2017 21:16
@rosbo rosbo force-pushed the resource_vpc_peering branch from 164ede4 to c9e054a Compare July 27, 2017 21:18
Copy link
Collaborator

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Generally looks good, I mostly just have nits about style.

auto_create_subnetworks = "false"
}

// Both network must create a peering with each other for the peering
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move these comments to the resource description above; that way users will read them as they read what the resource is and not just in the example.

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


# google\_compute\_network\_peering

Manages a network peering within GCE.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a link to the API reference and to a relevant set of GCP docs so that users can quickly learn more about the resource if they'd like.

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


// Both network must create a peering with each other for the peering
// to be functional.
resource "google_compute_network_peering" "peering1" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Let's make the resource this page is about live at the top of the example config.

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

* `peer_network` - (Required) Resource link of the peer network.

* `auto_create_routes` - (Optional) If set to true, the routes between the two networks will
be created and managed automatically. Defaults to true.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: s/true/`true`

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

In addition to the arguments listed above, the following computed attributes are
exported:

* `state` - (Computed) State for the peering.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: No need to include that they are (Computed)

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

return nil
}

// No need to set the `name` and `network` fields. We use both of them to find the peering.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment can probably be removed.

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

return m[2]
}

func peerNetworkLinkDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would compareSelfLinkRelativePaths() from self_link_helpers.go work here instead? It compares self links by just the projects/ onwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works. Removed my method. Thanks for the pointer


var testAccComputeNetworkPeering_basic = fmt.Sprintf(`
resource "google_compute_network" "network1" {
name = "network-test-1-%s"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Let's use tabs instead of spaces to be consistent with other test configs.

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

@@ -6,6 +6,8 @@ import (
"regexp"
)

const ProjectRegex = "(?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?))"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Project IDs generated through Terraform will follow this form, but I'm not sure if those rules have been followed for the entire lifetime of project ids in general.

We should be able to match against [^/]* and capture anything inside the projects/ part of a self link without overmatching past a /.

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 got the regex for the project description in the google cloud compute generated client:

	//     "project": {
	//       "description": "Project ID for this request.",
	//       "location": "path",
	//       "pattern": "(?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?))",
	//       "required": true,
	//       "type": "string"
	//     }

My goal with a specific regex is to try to fail at plan instead of apply. I think we should start moving towards this when format for names are clearly defined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh cool, I hadn't noticed that regex. Do you mind adding a comment of where you got it from? 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@@ -0,0 +1,229 @@
package google

import (
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: standard imports should all live at the top of the import block.

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Super minor: looks like sort snuck in afterwards.

@rosbo rosbo force-pushed the resource_vpc_peering branch from 9e95795 to 78f20a6 Compare July 28, 2017 01:00
Copy link
Collaborator

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Just a couple small nits; feel free to merge at will with a good test run.

return err
}

name := d.Get("name").(string)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: name, peerNetworkLink, and autoCreateRoutes can be inlined.

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

@@ -0,0 +1,229 @@
package google

import (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super minor: looks like sort snuck in afterwards.

@rosbo rosbo merged commit 3eaf475 into hashicorp:master Jul 28, 2017
@rosbo rosbo deleted the resource_vpc_peering branch July 28, 2017 16:51
aadidenko pushed a commit to aadidenko/terraform-provider-google that referenced this pull request Jul 28, 2017
z1nkum pushed a commit to z1nkum/terraform-provider-google that referenced this pull request Aug 15, 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
@ghost
Copy link

ghost commented Mar 31, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

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

Feature: google_compute_vpc_network_peer
2 participants