From 58d1b6f31d85fdb39b8ef9a1249282b9cf7f3119 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Wed, 24 Jan 2018 14:08:24 -0800 Subject: [PATCH 01/35] Note about `after` and `after-byoaws` branches --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 77e6b7f..fc60521 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Terraform Intro Demo Before and after code for a _Terraform Introduction_ class. + +## Branches + +See the `after` branch for the completed code from the class. + +See the `after-byoaws` branch for the completed code that can be run on a student's own AWS account (instead of on the instructor-created AWS account). From 124054eeba2f9a5c65bfdfdbf59e257963025b24 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Thu, 25 Jan 2018 15:38:33 -0800 Subject: [PATCH 02/35] Ensure that webapp starts on reboot --- assets/setup-web.sh | 2 ++ assets/webapp.service | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/assets/setup-web.sh b/assets/setup-web.sh index 1a0ae95..edea516 100755 --- a/assets/setup-web.sh +++ b/assets/setup-web.sh @@ -4,3 +4,5 @@ cp /tmp/assets/webapp /usr/local/bin/ chmod +x /usr/local/bin/* cp /tmp/assets/webapp.service /lib/systemd/system/webapp.service service webapp start +systemctl enable webapp + diff --git a/assets/webapp.service b/assets/webapp.service index c28fb12..5455a0e 100644 --- a/assets/webapp.service +++ b/assets/webapp.service @@ -1,3 +1,6 @@ +[Install] +WantedBy=multi-user.target + [Unit] Description=Demo web app @@ -5,4 +8,5 @@ Description=Demo web app ExecStart=/usr/local/bin/webapp >> /var/log/webapp.log IgnoreSIGPIPE=false KillMode=process +Restart=on-failure From 96d00468e49162e8447031ff944a5a8431e85d08 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Thu, 18 Apr 2019 17:45:01 -0700 Subject: [PATCH 03/35] Code for GCP Getting Started track on learn.hashicorp.com --- getting-started/gcp/main.tf | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 getting-started/gcp/main.tf diff --git a/getting-started/gcp/main.tf b/getting-started/gcp/main.tf new file mode 100644 index 0000000..6ea7c25 --- /dev/null +++ b/getting-started/gcp/main.tf @@ -0,0 +1,36 @@ +provider "google" { + # project = "{{YOUR GCP PROJECT}}" + region = "us-central1" + zone = "us-central1-c" +} + +resource "google_compute_instance" "vm_instance" { + name = "terraform-instance" + machine_type = "f1-micro" + + labels { + billing_department = "education" + } + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + # A default network is created for all GCP projects + network = "${google_compute_network.vpc_network.self_link}" + access_config = { + } + } +} + +resource "google_compute_network" "vpc_network" { + name = "terraform-network" + auto_create_subnetworks = "true" +} + +output "network_ip" { + value = "${google_compute_instance.vm_instance.network_interface.0.network_ip}" +} From 1ca1422ace69701afac8e0f7287c30cd6f3497ae Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Fri, 14 Jun 2019 18:42:28 -0700 Subject: [PATCH 04/35] Basic GCP example --- getting-started/gcp/cloudshell_tutorial.md | 29 ++++++++++++++++++++++ getting-started/gcp/main.tf | 29 +++++++++++++++++----- getting-started/gcp/versions.tf | 4 +++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 getting-started/gcp/cloudshell_tutorial.md create mode 100644 getting-started/gcp/versions.tf diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md new file mode 100644 index 0000000..92a1bfe --- /dev/null +++ b/getting-started/gcp/cloudshell_tutorial.md @@ -0,0 +1,29 @@ +# First Tutorial + +## First step + +Hello World + +### Part 1 + +Part One Instructions. + +``` +terraform init +``` + +``` +terraform plan +``` + +``` +terraform apply +``` + +### Part 2 + +Part Two Instructions. + +## Conclusion + +Done! diff --git a/getting-started/gcp/main.tf b/getting-started/gcp/main.tf index 6ea7c25..5f830e4 100644 --- a/getting-started/gcp/main.tf +++ b/getting-started/gcp/main.tf @@ -1,5 +1,5 @@ provider "google" { - # project = "{{YOUR GCP PROJECT}}" + project = "my-google-cloud-project" region = "us-central1" zone = "us-central1-c" } @@ -8,7 +8,7 @@ resource "google_compute_instance" "vm_instance" { name = "terraform-instance" machine_type = "f1-micro" - labels { + labels = { billing_department = "education" } @@ -20,10 +20,12 @@ resource "google_compute_instance" "vm_instance" { network_interface { # A default network is created for all GCP projects - network = "${google_compute_network.vpc_network.self_link}" - access_config = { + network = google_compute_network.vpc_network.self_link + access_config { } } + + metadata_startup_script = "echo 'Hello Terraform on GCP!' > index.html; python -m SimpleHTTPServer 9000 &" } resource "google_compute_network" "vpc_network" { @@ -31,6 +33,21 @@ resource "google_compute_network" "vpc_network" { auto_create_subnetworks = "true" } -output "network_ip" { - value = "${google_compute_instance.vm_instance.network_interface.0.network_ip}" +resource "google_compute_firewall" "default" { + name = "terraform-firewall" + network = google_compute_network.vpc_network.self_link + + allow { + protocol = "tcp" + ports = ["9000"] + } +} + +output "private_ip" { + value = google_compute_instance.vm_instance.network_interface[0].network_ip +} + +output "website_url" { + value = "http://${google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip}:9000" } + diff --git a/getting-started/gcp/versions.tf b/getting-started/gcp/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/getting-started/gcp/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} From 26bbd54aea5a0b2080e139d03bcb98c0aff4fdb3 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Mon, 17 Jun 2019 17:35:27 -0700 Subject: [PATCH 05/35] Adds snippets for full tutorial --- getting-started/gcp/cloudshell_tutorial.md | 184 ++++++++++++++++++++- 1 file changed, 175 insertions(+), 9 deletions(-) diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md index 92a1bfe..2ccb488 100644 --- a/getting-started/gcp/cloudshell_tutorial.md +++ b/getting-started/gcp/cloudshell_tutorial.md @@ -1,29 +1,195 @@ # First Tutorial -## First step +## Install Terraform -Hello World +### Download -### Part 1 +[Download Terraform](https://www.terraform.io/downloads.html) -Part One Instructions. +``` +wget https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip +``` + +### Unzip + +``` +unzip terraform_* +``` + +### Verify Version + +``` +./terraform version +``` + +``` +Terraform v0.12.2 +``` + +NOTE: On any error, verify that you're using Terraform `0.12` or greater with `./terraform version` + +## Write a configuration + +### Set Project Name + +Set GCP project name from your account. + +https://console.cloud.google.com/home/dashboard + +For the purposes of this example, we will use `terraform-project` but you should use your actual project name. + +``` +provider "google" { + project = "terraform-project" + region = "us-central1" + zone = "us-central1-c" +} +``` + +### Define a network + +``` +resource "google_compute_network" "vpc_network" { + name = "terraform-network" +} +``` + +### Init + +``` +./terraform init +``` + +### Plan + +``` +./terraform plan +``` + +### Apply ``` -terraform init +./terraform apply ``` +You should see: + ``` -terraform plan +Terraform will perform the following actions: + +... + +Plan: 1 to add, 0 to change, 0 to destroy. + +Do you want to perform these actions? ``` +Answer **yes**. + ``` -terraform apply +Apply complete! Resources: 1 added, 0 changed, 0 destroyed. ``` -### Part 2 +## Change the configuration + +### Define a firewall -Part Two Instructions. +``` +resource "google_compute_firewall" "default" { + name = "terraform-firewall" + network = google_compute_network.vpc_network.self_link + + allow { + protocol = "tcp" + ports = ["9000"] + } +} +``` + +``` +./terraform apply +``` + +### Define a compute instance + +``` +resource "google_compute_instance" "vm_instance" { + name = "terraform-instance" + machine_type = "f1-micro" + + labels = { + billing_department = "education" + } + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = google_compute_network.vpc_network.self_link + access_config { + } + } + + metadata_startup_script = "echo 'Hello Terraform on GCP!' > index.html; python -m SimpleHTTPServer 9000 &" +} +``` + +### Show state + +``` +./terraform show +``` + +Scroll up to `network_interface` and `access_config` and `nat_ip`. You'll find an IP address something like `0.0.0.0`. + +Go to your web browser and type that IP address followed by port `9000`. It will look something like (but use the IP address you found earlier): + +``` +http://0.0.0.0:9000 +``` + +You should see the message "Hello Terraform on GCP!" + +## Define an output + +### Display the website URL + +``` +output "public_ip" { + value = google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip +} +``` + +``` +output "website_url" { + value = "http://${google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip}:9000" +} +``` + + +## Destroy + +``` +./terraform destroy +``` + +``` +Plan: 0 to add, 0 to change, 1 to destroy. + +Do you really want to destroy all resources? +``` + +It may take a few minutes to complete. + +``` +Destroy complete! Resources: 1 destroyed. +``` ## Conclusion Done! + +[Learn more about Terraform](https://learn.hashicorp.com/terraform/) From acd347f165293d63075a709a2d082c875f0a154b Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Mon, 17 Jun 2019 17:58:31 -0700 Subject: [PATCH 06/35] Notes for reseting demo code and checking out after --- getting-started/gcp/cloudshell_tutorial.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md index 2ccb488..783c005 100644 --- a/getting-started/gcp/cloudshell_tutorial.md +++ b/getting-started/gcp/cloudshell_tutorial.md @@ -169,6 +169,16 @@ output "website_url" { } ``` +### See final code + +``` +git reset --hard HEAD +``` + + +``` +git checkout -t origin/after +``` ## Destroy From 0455c12d35f348e05fcb66f63707d26bcf629372 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Mon, 17 Jun 2019 17:59:36 -0700 Subject: [PATCH 07/35] Reset GCP example to starting point --- getting-started/gcp/main.tf | 49 +------------------------------------ 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/getting-started/gcp/main.tf b/getting-started/gcp/main.tf index 5f830e4..c34222d 100644 --- a/getting-started/gcp/main.tf +++ b/getting-started/gcp/main.tf @@ -1,53 +1,6 @@ provider "google" { - project = "my-google-cloud-project" + project = "terraform-demo" region = "us-central1" zone = "us-central1-c" } -resource "google_compute_instance" "vm_instance" { - name = "terraform-instance" - machine_type = "f1-micro" - - labels = { - billing_department = "education" - } - - boot_disk { - initialize_params { - image = "debian-cloud/debian-9" - } - } - - network_interface { - # A default network is created for all GCP projects - network = google_compute_network.vpc_network.self_link - access_config { - } - } - - metadata_startup_script = "echo 'Hello Terraform on GCP!' > index.html; python -m SimpleHTTPServer 9000 &" -} - -resource "google_compute_network" "vpc_network" { - name = "terraform-network" - auto_create_subnetworks = "true" -} - -resource "google_compute_firewall" "default" { - name = "terraform-firewall" - network = google_compute_network.vpc_network.self_link - - allow { - protocol = "tcp" - ports = ["9000"] - } -} - -output "private_ip" { - value = google_compute_instance.vm_instance.network_interface[0].network_ip -} - -output "website_url" { - value = "http://${google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip}:9000" -} - From 4b3b0bec0092484622924d3bd2fcc9ff88818444 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Mon, 17 Jun 2019 18:08:49 -0700 Subject: [PATCH 08/35] Notes about switching to final GCP code branch --- getting-started/gcp/cloudshell_tutorial.md | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md index 783c005..4439c42 100644 --- a/getting-started/gcp/cloudshell_tutorial.md +++ b/getting-started/gcp/cloudshell_tutorial.md @@ -16,7 +16,7 @@ wget https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd6 unzip terraform_* ``` -### Verify Version +### Verify version ``` ./terraform version @@ -28,6 +28,28 @@ Terraform v0.12.2 NOTE: On any error, verify that you're using Terraform `0.12` or greater with `./terraform version` +### Optional: Skip to final code in `after` branch + +We think you'll learn the most if you go through this tutorial step-by-step. But if at any point you want to skip to the final Terraform configuration for the project, you can find it in the `after` branch in the Git repository we've cloned for you. + +Delete all your changes first with `git reset`: + +``` +git reset --hard HEAD +``` + +Then checkout the `after` branch with this command: + +``` +git checkout -t origin/after +``` + +You can provision the infrastructure defined in the final code with these commands: + +``` +./terraform init && ./terraform apply -auto-approve +``` + ## Write a configuration ### Set Project Name @@ -187,7 +209,7 @@ git checkout -t origin/after ``` ``` -Plan: 0 to add, 0 to change, 1 to destroy. +Plan: 0 to add, 0 to change, 3 to destroy. Do you really want to destroy all resources? ``` @@ -195,7 +217,7 @@ Do you really want to destroy all resources? It may take a few minutes to complete. ``` -Destroy complete! Resources: 1 destroyed. +Destroy complete! Resources: 3 destroyed. ``` ## Conclusion From b3a87d084d0f92a3c7cbd2f9cc3fc569eda273ba Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Mon, 17 Jun 2019 18:12:27 -0700 Subject: [PATCH 09/35] Changes title of GCP tutorial --- getting-started/gcp/cloudshell_tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md index 4439c42..542e1eb 100644 --- a/getting-started/gcp/cloudshell_tutorial.md +++ b/getting-started/gcp/cloudshell_tutorial.md @@ -1,4 +1,4 @@ -# First Tutorial +# Learn HashiCorp Terraform on GCP ## Install Terraform From 63a268864c27ce69cb3fd9f92627bf77bd3102b8 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Mon, 17 Jun 2019 18:13:55 -0700 Subject: [PATCH 10/35] Rename GCP demo to 'terraform-project' --- getting-started/gcp/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting-started/gcp/main.tf b/getting-started/gcp/main.tf index c34222d..d78addf 100644 --- a/getting-started/gcp/main.tf +++ b/getting-started/gcp/main.tf @@ -1,5 +1,5 @@ provider "google" { - project = "terraform-demo" + project = "terraform-project" region = "us-central1" zone = "us-central1-c" } From c754ec656d5ee0a956a44c7bd0b3abc6ee32b144 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach Date: Thu, 20 Jun 2019 18:29:53 -0700 Subject: [PATCH 11/35] Remove commands that use locally unzipped terraform executable An updated GCP disk image is being used that has Terraform 0.12 installed, so it is not necessary to download Terraform and run it from a local directory. --- getting-started/gcp/cloudshell_tutorial.md | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md index 542e1eb..24dd152 100644 --- a/getting-started/gcp/cloudshell_tutorial.md +++ b/getting-started/gcp/cloudshell_tutorial.md @@ -4,28 +4,40 @@ ### Download +Terraform v0.12 is installed in this disk image. If you need to download Terraform, it's available at this link: + [Download Terraform](https://www.terraform.io/downloads.html) +To download, use a command line tool like `wget` on Linux or Mac: + ``` wget https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip ``` ### Unzip +Unzip the Terraform executable: + ``` unzip terraform_* ``` ### Verify version +Verify that you are running Terraform 0.12 or greater. + ``` -./terraform version +terraform version ``` +You should see `v0.12.2` or greater in the output. + ``` Terraform v0.12.2 ``` +If you are using a locally downloaded version if Terraform in the current directory, use `./terraform` (leading dot slash) to run the command. + NOTE: On any error, verify that you're using Terraform `0.12` or greater with `./terraform version` ### Optional: Skip to final code in `after` branch @@ -79,19 +91,19 @@ resource "google_compute_network" "vpc_network" { ### Init ``` -./terraform init +terraform init ``` ### Plan ``` -./terraform plan +terraform plan ``` ### Apply ``` -./terraform apply +terraform apply ``` You should see: @@ -129,7 +141,7 @@ resource "google_compute_firewall" "default" { ``` ``` -./terraform apply +terraform apply ``` ### Define a compute instance @@ -162,7 +174,7 @@ resource "google_compute_instance" "vm_instance" { ### Show state ``` -./terraform show +terraform show ``` Scroll up to `network_interface` and `access_config` and `nat_ip`. You'll find an IP address something like `0.0.0.0`. @@ -205,7 +217,7 @@ git checkout -t origin/after ## Destroy ``` -./terraform destroy +terraform destroy ``` ``` From cd5e7c3074fca47fa0f7f7f56263a4452aafc30b Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach <26+topfunky@users.noreply.github.com> Date: Mon, 19 Aug 2019 13:49:58 -0700 Subject: [PATCH 12/35] Beginning code for Terraform on Azure --- getting-started/azure/README.md | 9 +++++++++ getting-started/azure/main.tf | 4 ++++ 2 files changed, 13 insertions(+) create mode 100644 getting-started/azure/README.md create mode 100644 getting-started/azure/main.tf diff --git a/getting-started/azure/README.md b/getting-started/azure/README.md new file mode 100644 index 0000000..c92f3f3 --- /dev/null +++ b/getting-started/azure/README.md @@ -0,0 +1,9 @@ +# Getting Started with Terraform on Azure + +This code accompanies the [Getting Started](https://learn.hashicorp.com/terraform/azure/intro_az) guide on [learn.hashicorp.com](https://learn.hashicorp.com/). + +Check out the `after` branch for the final code. + +``` +$ git checkout after +``` diff --git a/getting-started/azure/main.tf b/getting-started/azure/main.tf new file mode 100644 index 0000000..9e312c4 --- /dev/null +++ b/getting-started/azure/main.tf @@ -0,0 +1,4 @@ +# Configure the provider +provider "azurerm" { + version = "=1.20.0" +} \ No newline at end of file From 6c8ddacd1402ddbbef572b0df12191a46e11afdf Mon Sep 17 00:00:00 2001 From: Robin Norwood Date: Wed, 21 Aug 2019 12:21:29 -0500 Subject: [PATCH 13/35] Update initial GCP example code --- getting-started/gcp/README.md | 9 + getting-started/gcp/cloudshell_tutorial.md | 239 --------------------- getting-started/gcp/main.tf | 26 ++- 3 files changed, 34 insertions(+), 240 deletions(-) create mode 100644 getting-started/gcp/README.md delete mode 100644 getting-started/gcp/cloudshell_tutorial.md diff --git a/getting-started/gcp/README.md b/getting-started/gcp/README.md new file mode 100644 index 0000000..ab7d68d --- /dev/null +++ b/getting-started/gcp/README.md @@ -0,0 +1,9 @@ +# Getting Started with Terraform on Google Cloud Platform + +This code accompanies the [Getting Started](https://learn.hashicorp.com/terraform/gcp/intro) guide on [learn.hashicorp.com](https://learn.hashicorp.com/). + +Check out the `after` branch for the final code: + +```shell +git checkout after +``` diff --git a/getting-started/gcp/cloudshell_tutorial.md b/getting-started/gcp/cloudshell_tutorial.md deleted file mode 100644 index 24dd152..0000000 --- a/getting-started/gcp/cloudshell_tutorial.md +++ /dev/null @@ -1,239 +0,0 @@ -# Learn HashiCorp Terraform on GCP - -## Install Terraform - -### Download - -Terraform v0.12 is installed in this disk image. If you need to download Terraform, it's available at this link: - -[Download Terraform](https://www.terraform.io/downloads.html) - -To download, use a command line tool like `wget` on Linux or Mac: - -``` -wget https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip -``` - -### Unzip - -Unzip the Terraform executable: - -``` -unzip terraform_* -``` - -### Verify version - -Verify that you are running Terraform 0.12 or greater. - -``` -terraform version -``` - -You should see `v0.12.2` or greater in the output. - -``` -Terraform v0.12.2 -``` - -If you are using a locally downloaded version if Terraform in the current directory, use `./terraform` (leading dot slash) to run the command. - -NOTE: On any error, verify that you're using Terraform `0.12` or greater with `./terraform version` - -### Optional: Skip to final code in `after` branch - -We think you'll learn the most if you go through this tutorial step-by-step. But if at any point you want to skip to the final Terraform configuration for the project, you can find it in the `after` branch in the Git repository we've cloned for you. - -Delete all your changes first with `git reset`: - -``` -git reset --hard HEAD -``` - -Then checkout the `after` branch with this command: - -``` -git checkout -t origin/after -``` - -You can provision the infrastructure defined in the final code with these commands: - -``` -./terraform init && ./terraform apply -auto-approve -``` - -## Write a configuration - -### Set Project Name - -Set GCP project name from your account. - -https://console.cloud.google.com/home/dashboard - -For the purposes of this example, we will use `terraform-project` but you should use your actual project name. - -``` -provider "google" { - project = "terraform-project" - region = "us-central1" - zone = "us-central1-c" -} -``` - -### Define a network - -``` -resource "google_compute_network" "vpc_network" { - name = "terraform-network" -} -``` - -### Init - -``` -terraform init -``` - -### Plan - -``` -terraform plan -``` - -### Apply - -``` -terraform apply -``` - -You should see: - -``` -Terraform will perform the following actions: - -... - -Plan: 1 to add, 0 to change, 0 to destroy. - -Do you want to perform these actions? -``` - -Answer **yes**. - -``` -Apply complete! Resources: 1 added, 0 changed, 0 destroyed. -``` - -## Change the configuration - -### Define a firewall - -``` -resource "google_compute_firewall" "default" { - name = "terraform-firewall" - network = google_compute_network.vpc_network.self_link - - allow { - protocol = "tcp" - ports = ["9000"] - } -} -``` - -``` -terraform apply -``` - -### Define a compute instance - -``` -resource "google_compute_instance" "vm_instance" { - name = "terraform-instance" - machine_type = "f1-micro" - - labels = { - billing_department = "education" - } - - boot_disk { - initialize_params { - image = "debian-cloud/debian-9" - } - } - - network_interface { - network = google_compute_network.vpc_network.self_link - access_config { - } - } - - metadata_startup_script = "echo 'Hello Terraform on GCP!' > index.html; python -m SimpleHTTPServer 9000 &" -} -``` - -### Show state - -``` -terraform show -``` - -Scroll up to `network_interface` and `access_config` and `nat_ip`. You'll find an IP address something like `0.0.0.0`. - -Go to your web browser and type that IP address followed by port `9000`. It will look something like (but use the IP address you found earlier): - -``` -http://0.0.0.0:9000 -``` - -You should see the message "Hello Terraform on GCP!" - -## Define an output - -### Display the website URL - -``` -output "public_ip" { - value = google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip -} -``` - -``` -output "website_url" { - value = "http://${google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip}:9000" -} -``` - -### See final code - -``` -git reset --hard HEAD -``` - - -``` -git checkout -t origin/after -``` - -## Destroy - -``` -terraform destroy -``` - -``` -Plan: 0 to add, 0 to change, 3 to destroy. - -Do you really want to destroy all resources? -``` - -It may take a few minutes to complete. - -``` -Destroy complete! Resources: 3 destroyed. -``` - -## Conclusion - -Done! - -[Learn more about Terraform](https://learn.hashicorp.com/terraform/) diff --git a/getting-started/gcp/main.tf b/getting-started/gcp/main.tf index d78addf..165cfbc 100644 --- a/getting-started/gcp/main.tf +++ b/getting-started/gcp/main.tf @@ -1,6 +1,30 @@ provider "google" { - project = "terraform-project" + credentials = file("GCP Review-bad9ce4e27a7.json") + + project = "gcp-review-250516" region = "us-central1" zone = "us-central1-c" } +resource "google_compute_network" "vpc_network" { + name = "terraform-network" +} + +resource "google_compute_instance" "vm_instance" { + name = "terraform-instance" + machine_type = "f1-micro" + + tags = ["web", "dev"] + + boot_disk { + initialize_params { + image = "cos-cloud/cos-stable" + } + } + + network_interface { + network = google_compute_network.vpc_network.name + access_config { + } + } +} From b848753b361387eec00ad196786518063710b0c3 Mon Sep 17 00:00:00 2001 From: Robin Norwood Date: Wed, 21 Aug 2019 12:24:37 -0500 Subject: [PATCH 14/35] Correct version of main.tf --- getting-started/gcp/main.tf | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/getting-started/gcp/main.tf b/getting-started/gcp/main.tf index 165cfbc..a31d4ae 100644 --- a/getting-started/gcp/main.tf +++ b/getting-started/gcp/main.tf @@ -1,7 +1,7 @@ provider "google" { - credentials = file("GCP Review-bad9ce4e27a7.json") + credentials = file(".json") - project = "gcp-review-250516" + project = "" region = "us-central1" zone = "us-central1-c" } @@ -9,22 +9,3 @@ provider "google" { resource "google_compute_network" "vpc_network" { name = "terraform-network" } - -resource "google_compute_instance" "vm_instance" { - name = "terraform-instance" - machine_type = "f1-micro" - - tags = ["web", "dev"] - - boot_disk { - initialize_params { - image = "cos-cloud/cos-stable" - } - } - - network_interface { - network = google_compute_network.vpc_network.name - access_config { - } - } -} From 2276c7e7e64b4b7dc46cc51191bbff74427880f3 Mon Sep 17 00:00:00 2001 From: Robin Norwood Date: Wed, 21 Aug 2019 12:51:19 -0500 Subject: [PATCH 15/35] Add empty variables.tf --- getting-started/gcp/variables.tf | 1 + 1 file changed, 1 insertion(+) create mode 100644 getting-started/gcp/variables.tf diff --git a/getting-started/gcp/variables.tf b/getting-started/gcp/variables.tf new file mode 100644 index 0000000..115a233 --- /dev/null +++ b/getting-started/gcp/variables.tf @@ -0,0 +1 @@ +# Variable definitions go here From e46de3c1545f01aa677e5a9c3447888baf5cc696 Mon Sep 17 00:00:00 2001 From: Robin Norwood Date: Wed, 21 Aug 2019 14:21:11 -0500 Subject: [PATCH 16/35] Add terraform.tfvars --- getting-started/gcp/terraform.tfvars | 1 + 1 file changed, 1 insertion(+) create mode 100644 getting-started/gcp/terraform.tfvars diff --git a/getting-started/gcp/terraform.tfvars b/getting-started/gcp/terraform.tfvars new file mode 100644 index 0000000..5be524d --- /dev/null +++ b/getting-started/gcp/terraform.tfvars @@ -0,0 +1 @@ +# Variable value assignments go here From 9e88126fc7c3231f8bf8ef420ccf4be8247117c1 Mon Sep 17 00:00:00 2001 From: Robin Norwood Date: Wed, 21 Aug 2019 14:24:01 -0500 Subject: [PATCH 17/35] Add outputs.tf --- getting-started/gcp/outputs.tf | 1 + 1 file changed, 1 insertion(+) create mode 100644 getting-started/gcp/outputs.tf diff --git a/getting-started/gcp/outputs.tf b/getting-started/gcp/outputs.tf new file mode 100644 index 0000000..d36d91b --- /dev/null +++ b/getting-started/gcp/outputs.tf @@ -0,0 +1 @@ +# Output definitions go here From 39bc3dc6ec40a05f9e93f97efe30e475adcdadc6 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach <26+topfunky@users.noreply.github.com> Date: Wed, 21 Aug 2019 15:10:07 -0700 Subject: [PATCH 18/35] Ignore terraform.tfvars It's risky to store terraform.tfvars in the repo since it might eventually have sensitive information. This commit provides an example if needed but doesn't commit the actual file to the repoIgnore terraform.tfvars It's risky to store terraform.tfvars in the repo since it might eventually have sensitive information. This commit provides an example if needed but doesn't commit the actual file to the repo. --- getting-started/gcp/.gitignore | 3 +++ .../gcp/{terraform.tfvars => terraform.tfvars.example} | 0 2 files changed, 3 insertions(+) create mode 100644 getting-started/gcp/.gitignore rename getting-started/gcp/{terraform.tfvars => terraform.tfvars.example} (100%) diff --git a/getting-started/gcp/.gitignore b/getting-started/gcp/.gitignore new file mode 100644 index 0000000..4f2e2cf --- /dev/null +++ b/getting-started/gcp/.gitignore @@ -0,0 +1,3 @@ +terraform.tfvars +.terraform + diff --git a/getting-started/gcp/terraform.tfvars b/getting-started/gcp/terraform.tfvars.example similarity index 100% rename from getting-started/gcp/terraform.tfvars rename to getting-started/gcp/terraform.tfvars.example From 0dbbdc25d84cf4d57454703e3f71c62867177275 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach <26+topfunky@users.noreply.github.com> Date: Tue, 3 Dec 2019 18:13:41 -0800 Subject: [PATCH 19/35] Simple project for use with Terraform Cloud --- getting-started/tfc/main.tf | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 getting-started/tfc/main.tf diff --git a/getting-started/tfc/main.tf b/getting-started/tfc/main.tf new file mode 100644 index 0000000..bb76087 --- /dev/null +++ b/getting-started/tfc/main.tf @@ -0,0 +1,24 @@ +terraform { + backend "remote" { + organization = "my-organization" + + workspaces { + name = "random-pet-demo" + } + } +} + +variable "stage" { + default = "production" +} + +resource "random_pet" "server" { + keepers = { + # Generate a new pet name each time we switch to a new stage + stage = "${var.stage}" + } +} + +output "random_server_id" { + value = random_pet.server.id +} From dc91f22082f005470126d7d591384b879b62c712 Mon Sep 17 00:00:00 2001 From: Geoffrey Grosenbach <26+topfunky@users.noreply.github.com> Date: Wed, 4 Dec 2019 11:13:52 -0800 Subject: [PATCH 20/35] Comment out Terraform config as starting point For a Katacoda Terraform Cloud scenario --- getting-started/tfc/main.tf | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/getting-started/tfc/main.tf b/getting-started/tfc/main.tf index bb76087..851354b 100644 --- a/getting-started/tfc/main.tf +++ b/getting-started/tfc/main.tf @@ -1,12 +1,11 @@ -terraform { - backend "remote" { - organization = "my-organization" - - workspaces { - name = "random-pet-demo" - } - } -} +// terraform { +// backend "remote" { +// organization = "my-organization" +// workspaces { +// name = "random-pet-demo" +// } +// } +// } variable "stage" { default = "production" From b82af99c672561207c9c205c8ac2f6d0f724120a Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song Date: Wed, 8 Sep 2021 16:51:41 +0800 Subject: [PATCH 21/35] initial commit --- .terraform.lock.hcl | 20 ++++++++++++++ main.tf | 46 +++++++++++++++++++++++++++++---- outputs.tf | 7 +++++ server/main.tf | 63 +++++++++++++++++++++++++++++++++++++++++++++ server/outputs.tf | 7 +++++ server/variables.tf | 24 +++++++++++++++++ variables.tf | 21 +++++++++++++++ 7 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 .terraform.lock.hcl create mode 100644 outputs.tf create mode 100644 server/main.tf create mode 100644 server/outputs.tf create mode 100644 server/variables.tf create mode 100644 variables.tf diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..a7373fa --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,20 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "3.57.0" + hashes = [ + "h1:H6JCnoa3swF3rgHL0ys9KNArffU+IEGPvhQ6JnfQY/c=", + "zh:241a4203078ea35f63202b613f0e4b428a842734ded62d9f487cdf7c2a66d639", + "zh:2c1cbf3cd03a2a7ff267be09cedf1698738c372b1411ca74cfcb3bf4b0846f27", + "zh:318ad2331f60e03d284f90f728486b9df7ac9570af641c43b56216357e624b52", + "zh:43ff96b34b4829a34693281492786b9ca6dd06870dd45b0ae82ea352c33353d7", + "zh:6c36b874622603793fc637272742d84ecbf68dfe4c8d8148bb6e9b733cd0e216", + "zh:7a1aaac01c82d06f9ebc997ae2094a7d96e7a467aaaeaa1cda64ee952f3144d8", + "zh:9b917b03b8771f87a021fe7aa9fd00ae06cc455a1eaa1fb748930182617b2772", + "zh:bd90550e6d9311092170f4935e42e91e6d8bed5241e41eca39fa4aeca28d9c6f", + "zh:be5076ea705c174581fd616b118e0c17d15bd8ab0da1b3eee4f3fb6b11e78f2c", + "zh:f4f0d13414c932ecf65ba92daab6e755c244dcb77b4be59a3ac18ba2f56cdc00", + "zh:fa3575a23fd20ce00658977374491022c4c0c36a00260ebeebb0c3f3af4824aa", + ] +} diff --git a/main.tf b/main.tf index 5b367d1..d88c38c 100644 --- a/main.tf +++ b/main.tf @@ -1,9 +1,45 @@ +terraform { + required_version = ">= 0.12.0" +} + provider "aws" { - access_key = "" - secret_key = "" - region = "" } -resource "aws_instance" "web" { - # ... +data "aws_ami" "ubuntu_16_04" { + most_recent = true + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + } + + owners = ["099720109477"] +} + +module "server" { + source = "./server" + + num_webs = var.num_webs + identity = var.identity + ami = data.aws_ami.ubuntu_16_04.image_id + ingress_cidr = var.ingress_cidr + public_key = var.public_key + private_key = var.private_key +} + +### REMOVE +output "pri_var" { + value = var.private_key +} + +output "pri_file" { + value = file("~/.ssh/id_general") } + +output "pub_var" { + value = var.public_key +} + +output "pub_file" { + value = file("~/.ssh/id_general.pub") +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..641333d --- /dev/null +++ b/outputs.tf @@ -0,0 +1,7 @@ +output "public_ip" { + value = module.server.public_ip +} + +output "public_dns" { + value = module.server.public_dns +} \ No newline at end of file diff --git a/server/main.tf b/server/main.tf new file mode 100644 index 0000000..e8a4a45 --- /dev/null +++ b/server/main.tf @@ -0,0 +1,63 @@ +resource "aws_key_pair" "default" { + key_name = "${var.identity}-key" + public_key = var.public_key + #public_key = file("~/.ssh/id_general.pub") +} + +resource "aws_security_group" "default" { + name_prefix = var.identity + + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Created-by = "Terraform" + Identity = var.identity + } +} + +resource "aws_instance" "web" { + ami = var.ami + instance_type = "t2.medium" + count = var.num_webs + + vpc_security_group_ids = [aws_security_group.default.id] + + key_name = aws_key_pair.default.id + + tags = { + Name = "${var.identity} web ${count.index + 1}/${var.num_webs}" + Identity = var.identity + } + + connection { + type = "ssh" + user = "ubuntu" + #private_key = var.private_key + private_key = file("~/.ssh/id_general") + host = self.public_ip + timeout = "1m" + } + + provisioner "file" { + source = "assets" + destination = "/tmp/" + } + + provisioner "remote-exec" { + inline = [ + "sudo sh /tmp/assets/setup-web.sh", + ] + } +} diff --git a/server/outputs.tf b/server/outputs.tf new file mode 100644 index 0000000..cf2b091 --- /dev/null +++ b/server/outputs.tf @@ -0,0 +1,7 @@ +output "public_ip" { + value = [aws_instance.web.*.public_ip] +} + +output "public_dns" { + value = [aws_instance.web.*.public_dns] +} \ No newline at end of file diff --git a/server/variables.tf b/server/variables.tf new file mode 100644 index 0000000..78b793e --- /dev/null +++ b/server/variables.tf @@ -0,0 +1,24 @@ +variable "ami" { + description = "Base machine image for running this server" +} + +variable "num_webs" { + description = "The number of servers to create" + default = 1 +} + +variable "identity" { + description = "A unique name for this server" +} + +variable "ingress_cidr" { + description = "IP address block from which connections to this instance will be made" +} + +variable "public_key" { + description = "Contents of the public key used to connect to this instance" +} + +variable "private_key" { + description = "Contents of the private key used to connect to this instance" +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..0e1cd8d --- /dev/null +++ b/variables.tf @@ -0,0 +1,21 @@ +variable "identity" { + description = "A unique name for your resources" +} + +variable "public_key" { + description = "Contents of the public key used to connect to this instance" +} + +variable "private_key" { + description = "Contents of the private key used to connect to this instance" +} + +variable "ingress_cidr" { + description = "IP block from which connections to this instance will be made" + default = "0.0.0.0/0" +} + +variable "num_webs" { + description = "The number of servers to run" + default = "1" +} \ No newline at end of file From f49e0d99089ff7f5f8eea72c2521c4f2baebc028 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song Date: Wed, 8 Sep 2021 16:53:01 +0800 Subject: [PATCH 22/35] fixed typo --- server/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/main.tf b/server/main.tf index e8a4a45..561f1a9 100644 --- a/server/main.tf +++ b/server/main.tf @@ -44,8 +44,8 @@ resource "aws_instance" "web" { connection { type = "ssh" user = "ubuntu" - #private_key = var.private_key - private_key = file("~/.ssh/id_general") + private_key = var.private_key + #private_key = file("~/.ssh/id_general") host = self.public_ip timeout = "1m" } From cacaf53111628dfeebfbdff27b6b39ed53166f35 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song Date: Wed, 8 Sep 2021 16:56:51 +0800 Subject: [PATCH 23/35] removed extra output --- main.tf | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/main.tf b/main.tf index d88c38c..13c9dba 100644 --- a/main.tf +++ b/main.tf @@ -26,20 +26,3 @@ module "server" { public_key = var.public_key private_key = var.private_key } - -### REMOVE -output "pri_var" { - value = var.private_key -} - -output "pri_file" { - value = file("~/.ssh/id_general") -} - -output "pub_var" { - value = var.public_key -} - -output "pub_file" { - value = file("~/.ssh/id_general.pub") -} \ No newline at end of file From d35ace33980f60d3ffa99dbfcae271e525070712 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Mon, 13 Sep 2021 15:07:56 +0800 Subject: [PATCH 24/35] Update main.tf --- main.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.tf b/main.tf index 287956a..b1313ab 100644 --- a/main.tf +++ b/main.tf @@ -3,6 +3,8 @@ terraform { } provider "aws" { + # MODIFY this line to look for 2.27.0 or greater + version = ">= 2.20.0" } data "aws_ami" "ubuntu_16_04" { From 27ac5f6fc0d919821b840984bed7b5a78232c6ac Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Mon, 13 Sep 2021 15:08:08 +0800 Subject: [PATCH 25/35] Update main.tf --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b1313ab..28c4e75 100644 --- a/main.tf +++ b/main.tf @@ -4,7 +4,7 @@ terraform { provider "aws" { # MODIFY this line to look for 2.27.0 or greater - version = ">= 2.20.0" + version = ">= 2.21.0" } data "aws_ami" "ubuntu_16_04" { From 7920df5a3e2ca4a3a4446b15239742411794f40f Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Tue, 14 Sep 2021 15:37:26 +0800 Subject: [PATCH 26/35] Update main.tf --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 28c4e75..f7b347f 100644 --- a/main.tf +++ b/main.tf @@ -4,7 +4,7 @@ terraform { provider "aws" { # MODIFY this line to look for 2.27.0 or greater - version = ">= 2.21.0" + version = ">= 2.22.0" } data "aws_ami" "ubuntu_16_04" { From 1bcf4fcd4800b4367342c768892557737b940511 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song Date: Tue, 14 Sep 2021 16:37:06 +0800 Subject: [PATCH 27/35] cleanup --- server/main.tf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/main.tf b/server/main.tf index 3b40689..d5ab390 100644 --- a/server/main.tf +++ b/server/main.tf @@ -1,6 +1,7 @@ resource "aws_key_pair" "default" { key_name = "${var.identity}-key" public_key = var.public_key + #public_key = file("~/.ssh/id_general.pub") } resource "aws_security_group" "default" { @@ -44,7 +45,9 @@ resource "aws_instance" "web" { type = "ssh" user = "ubuntu" private_key = var.private_key + #private_key = file("~/.ssh/id_general") host = self.public_ip + timeout = "1m" } provisioner "file" { @@ -57,4 +60,4 @@ resource "aws_instance" "web" { "sudo sh /tmp/assets/setup-web.sh", ] } -} +} \ No newline at end of file From 0463d3e741d38ae5101d3a5eb8452a1349340435 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song Date: Tue, 14 Sep 2021 16:37:15 +0800 Subject: [PATCH 28/35] Fixed ami issue --- 05_multi-provider/main.tf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/05_multi-provider/main.tf b/05_multi-provider/main.tf index f4a71f8..c5662e0 100644 --- a/05_multi-provider/main.tf +++ b/05_multi-provider/main.tf @@ -24,6 +24,17 @@ provider "aws" { data "github_ip_ranges" "test" { } +data "aws_ami" "ubuntu_16_04" { + most_recent = true + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + } + + owners = ["099720109477"] +} + resource "aws_security_group" "training" { name_prefix = var.namespace @@ -50,7 +61,7 @@ resource "aws_key_pair" "training" { } resource "aws_instance" "example" { - ami = var.ami + ami = data.aws_ami.ubuntu_16_04.image_id instance_type = "t2.micro" vpc_security_group_ids = [aws_security_group.training.id] From 664ab7059c94e0c9e5601053f19eceaaaa5a9a90 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song Date: Thu, 16 Sep 2021 15:13:13 +0800 Subject: [PATCH 29/35] Added support for ipv6 from GitHubwq --- 05_multi-provider/main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/05_multi-provider/main.tf b/05_multi-provider/main.tf index c5662e0..6c558c4 100644 --- a/05_multi-provider/main.tf +++ b/05_multi-provider/main.tf @@ -51,7 +51,8 @@ resource "aws_security_group" "training" { protocol = "-1" cidr_blocks = ["0.0.0.0/0"] - #cidr_blocks = data.github_ip_ranges.test.pages + #cidr_blocks = slice (data.github_ip_ranges.test.pages, 0, 5) + #ipv6_cidr_blocks = slice (data.github_ip_ranges.test.pages, 6, length(data.github_ip_ranges.test.pages)) } } From 0cb9aa8908521edc81267d3aa41c04064f1ea3de Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:40:26 +0800 Subject: [PATCH 30/35] Update main.tf --- server/main.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/main.tf b/server/main.tf index d5ab390..7e3ca5d 100644 --- a/server/main.tf +++ b/server/main.tf @@ -1,7 +1,7 @@ resource "aws_key_pair" "default" { key_name = "${var.identity}-key" - public_key = var.public_key - #public_key = file("~/.ssh/id_general.pub") + #public_key = var.public_key + public_key = file("~/.ssh/id_rsa.pub") } resource "aws_security_group" "default" { @@ -44,8 +44,8 @@ resource "aws_instance" "web" { connection { type = "ssh" user = "ubuntu" - private_key = var.private_key - #private_key = file("~/.ssh/id_general") + #private_key = var.private_key + private_key = file("~/.ssh/id_rsa") host = self.public_ip timeout = "1m" } @@ -60,4 +60,4 @@ resource "aws_instance" "web" { "sudo sh /tmp/assets/setup-web.sh", ] } -} \ No newline at end of file +} From 147163b98e3a2d9001ef01eaa6ec95cee0ae5e0d Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:40:58 +0800 Subject: [PATCH 31/35] Update variables.tf --- variables.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variables.tf b/variables.tf index c677b18..3a60e9b 100644 --- a/variables.tf +++ b/variables.tf @@ -4,10 +4,12 @@ variable "identity" { variable "public_key" { description = "Contents of the public key used to connect to this instance" + default = "" } variable "private_key" { description = "Contents of the private key used to connect to this instance" + default = "" } variable "ingress_cidr" { From e6cfa8a503a50bef23fc934f14316654cf40b273 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:43:46 +0800 Subject: [PATCH 32/35] Update variables.tf --- variables.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/variables.tf b/variables.tf index 3a60e9b..acb6b70 100644 --- a/variables.tf +++ b/variables.tf @@ -21,3 +21,8 @@ variable "num_webs" { description = "The number of servers to run" default = "1" } + +variable "github_token" { + description = "The GitHub Token" + default = "" +} From 9606cf9a87f558fb45bc8d73683bf13add851613 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:49:20 +0800 Subject: [PATCH 33/35] Update variables.tf --- variables.tf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/variables.tf b/variables.tf index acb6b70..3a60e9b 100644 --- a/variables.tf +++ b/variables.tf @@ -21,8 +21,3 @@ variable "num_webs" { description = "The number of servers to run" default = "1" } - -variable "github_token" { - description = "The GitHub Token" - default = "" -} From 98e5f96785b1daf3e1e47751372f422566cd5421 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Tue, 5 Jul 2022 15:13:47 +0800 Subject: [PATCH 34/35] Update main.tf --- server/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.tf b/server/main.tf index 7e3ca5d..c28d244 100644 --- a/server/main.tf +++ b/server/main.tf @@ -29,7 +29,7 @@ resource "aws_security_group" "default" { resource "aws_instance" "web" { ami = var.ami - instance_type = "t2.medium" + instance_type = "t2.small" count = var.num_webs vpc_security_group_ids = [aws_security_group.default.id] From dc8c9a9e70ea09fe9adc7ac8989fd4f1e1c57b10 Mon Sep 17 00:00:00 2001 From: ecsd-matthew-song <44193019+ecsd-matthew-song@users.noreply.github.com> Date: Tue, 5 Jul 2022 15:18:04 +0800 Subject: [PATCH 35/35] Update main.tf --- server/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.tf b/server/main.tf index c28d244..7e3ca5d 100644 --- a/server/main.tf +++ b/server/main.tf @@ -29,7 +29,7 @@ resource "aws_security_group" "default" { resource "aws_instance" "web" { ami = var.ami - instance_type = "t2.small" + instance_type = "t2.medium" count = var.num_webs vpc_security_group_ids = [aws_security_group.default.id]