diff --git a/.gitignore b/.gitignore index eb7ad58..c41eb61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ - +auth.tfvars +account.json # Created by https://www.gitignore.io/api/terraform # Edit at https://www.gitignore.io/?templates=terraform @@ -39,4 +40,4 @@ override.tf.json account.json # Default vars -*.auto.tfvars \ No newline at end of file +*.auto.tfvars diff --git a/README.md b/README.md new file mode 100644 index 0000000..51a8942 --- /dev/null +++ b/README.md @@ -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. diff --git a/main.tf b/main.tf index 5c2928b..dbfe1bc 100644 --- a/main.tf +++ b/main.tf @@ -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}" } diff --git a/variables.tf b/variables.tf index 3744c70..525e8dc 100644 --- a/variables.tf +++ b/variables.tf @@ -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 diff --git a/versions.tf b/versions.tf index d57db3e..f45b4be 100644 --- a/versions.tf +++ b/versions.tf @@ -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" {