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 an example of use of shared VPC networking. #810

Merged
merged 5 commits into from
Dec 6, 2017

Conversation

nat-henderson
Copy link
Contributor

The example brings up four projects:

  • one to host the VPC
  • two to use the VPC
  • one which is outside the VPC

This is based on the diagram in https://cloud.google.com/vpc/docs/shared-vpc and uses the names from there (where possible) for clarity.

It eventually outputs an IP address - on that page you can see a demonstration that one of the VMs on the VPC can ping another VM on the same VPC (but in a different project) using the internal IP.

The page looks like this:
terraform-cloud-page

This is my first contribution to this project, so please let me know if I'm missing something. I've run terraform fmt and I've tested this on my account, but that's about it. :)

Brings up four projects:
  - one to host the VPC
  - two to use the VPC
  - one which is outside the VPC

This is based on the diagram in https://cloud.google.com/vpc/docs/shared-vpc and uses the names there where possible for clarity.
- Add an output so that it's visible to the user.
- Add scripts to output which VM is being accessed on VM1 and Standalone.
- Add a script to generate the demonstration page on VM2.
@nat-henderson
Copy link
Contributor Author

@danawillow - looks like I can't set assignee.


It is based on the diagram in the overview at [https://cloud.google.com/vpc/docs/shared-vpc](https://cloud.google.com/vpc/docs/shared-vpc).

This example creates projects within an organization - to run it, you will need to have an Organization ID. To get started using Organizations, read the quickstart [here](https://cloud.google.com/resource-manager/docs/quickstart-organizations). Since it uses organizations, project-specific credentials won't work, and consequently this example is configured to use [application default credentials](https://developers.google.com/identity/protocols/application-default-credentials). Ensure that the application default credentials have permission to create and manage projects and Shared VPCs (sometimes called 'XPN').
Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible to grant organization-level permissions to project-specific credentials such as a service account.

In the UI, select your org in the top dropdown menu, visit Iam & Admin > Iam. Then click the +Add button at the top to add new members. In the members field, you can put a service account email.


Since projects require globally unique names, you will need to provide a `project_base_id` variable. Since project names can't be too long, make sure it's short - if it is too long, Terraform won't be able to create the project.

The example allows you to specify a billing account, if you want to ensure that the charges (which are minor) are grouped together.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think billing account is mandatory to be able to create a VM.

-var="region=us-central1" \
-var="region_zone=us-central1-f" \
-var="org_id=1234567" \
-var="project_base_id=unique_string"
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the random provider instead and support full destroy.

See: https://www.terraform.io/docs/providers/random/index.html

@danawillow
Copy link
Contributor

I agree with all of @rosbo's comments.

@nat-henderson
Copy link
Contributor Author

Great, I'll make those changes. Thanks for the pointer to the random provider, that makes this a lot nicer. :)

@nat-henderson
Copy link
Contributor Author

Made those changes, tested locally. The service account credentials were kind of a hassle to set up on the Console, but that's probably just my lack of familiarity with the credentials system in Cloud generally.

@rosbo
Copy link
Contributor

rosbo commented Dec 2, 2017

It is not only you :) They are a hassle. @paddycarver made a screencast to explain how because many people had issues with this.

An easier way to do it is to use Terraform instead of the console for that:
https://www.terraform.io/docs/providers/google/r/google_organization_iam_member.html

Copy link
Contributor

@rosbo rosbo left a comment

Choose a reason for hiding this comment

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

Great addition! Thanks Nathan

@nat-henderson
Copy link
Contributor Author

Thanks for the review! :)

@nat-henderson nat-henderson merged commit f7bdcde into hashicorp:master Dec 6, 2017
@nat-henderson nat-henderson deleted the shared_vpc_example branch December 6, 2017 22:52
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this pull request Sep 27, 2019
@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.

3 participants