Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

auth.tfvars
account.json
# Created by https://www.gitignore.io/api/terraform
# Edit at https://www.gitignore.io/?templates=terraform

Expand Down Expand Up @@ -39,4 +40,4 @@ override.tf.json
account.json

# Default vars
*.auto.tfvars
*.auto.tfvars
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# gcp-101
Basic usage of Terraform with GCP

Step 1: Sign up for Google Cloud Platform (GCP) at cloud.google.com, using your personal GMail account, and [create a "Project" in GCP.](https://cloud.google.com/resource-manager/docs/creating-managing-organization#creating-projects)

Do you know what a Project is? It's a way to organize various GCP resources or something. Doesn't matter that much for this.

Step 2: Hunt around for the project_name, project_id, billing_account, and org_id, according to this recursive documentation (which refers you to more documentation):

https://cloud.google.com/community/tutorials/managing-gcp-projects-with-terraform#set_up_the_environment

Step 3: Rename the Terraform Variables file, named terraform.auto.tfvars.example to terraform.auto.tfvars, and keep it in the same folder as main.tf.

Step 4: Edit the file named terraform.auto.tfvars, and replace the default values with the stuff you hunted down in your Google Cloud account.

Step 5: Run `terraform init`

Step 6: Run `terraform plan`

Step 7: Run `terraform apply`

Step 8: Run `terraform destroy` to destroy all the GCP stuff you created.
9 changes: 1 addition & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ variable "project_services" {
]
}

resource "google_project" "main" {
name = "${var.project_name}"
project_id = "${var.project_name}"
org_id = "${var.org_id}"
billing_account = "${var.billing_account}"
}

resource "google_project_services" "main" {
project = "${google_project.main.project_id}"
project = "${var.project_id}"
services = "${var.project_services}"
}

Expand Down
18 changes: 13 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
variable "console_num_instances" {}
variable "console_num_instances" { default = 1 }

variable "project_name" {}
variable "project_name" { default = 'myrandomprojectname' }

variable "billing_account" {}
variable "project_id" { }

variable "org_id" {}
variable "billing_account" { }

variable "region" {}
variable "org_id" { }

variable "region" { default = 'us-west2' }


## Note: These can also be defined as follows:
## export TF_VAR_my_variable_name="top-secret-value"
## For example, TF_VAR_account='{"type": "service_account", "project_id": "unique-highway-237219"...
## Would correspond to the account variable
6 changes: 3 additions & 3 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
provider "google" {
version = "2.3"
credentials = "${file("account.json")}"
project = "johnny-carlin"
region = "us-central1"
credentials = "${file("account.json")}"
project = "${var.project_id}"
region = "${var.region}"
}

provider "null" {
Expand Down