From 7d9b1a62cf02d460f3a3a5eca69348c22fb93e9e Mon Sep 17 00:00:00 2001 From: Syed Quadri Date: Thu, 13 Jun 2024 15:21:19 -0500 Subject: [PATCH] fixed vcdl-864 --- .../01-setup-our-environment/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../02-hello-terraform/assignment.md | 51 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../03-aws-credentials/assignment.md | 34 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../04-terraform-code/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../05-terraform-init-provider/assignment.md | 42 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../06-provider-quiz/assignment.md | 22 + .../07-terraform-validate/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../08-terraform-plan/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../09-terraform-variables/assignment.md | 29 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../10-terraform-add-a-variable/assignment.md | 43 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../11-variables-quiz/assignment.md | 22 + .../12-tf-graph/assignment.md | 46 + .../check-workstation | 0 .../cleanup-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../13-tf-plan-and-apply/assignment.md | 42 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../14-tf-plan-again/assignment.md | 43 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../15-change-prefix/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../16-add-a-tag/assignment.md | 33 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../17-add-virtual-network/assignment.md | 30 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../18-complete-the-build/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../19-tf-graph-again/assignment.md | 34 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../20-terraform-apply-quiz/assignment.md | 22 + .../21-use-a-provisioner/assignment.md | 59 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../22-add-an-output/assignment.md | 55 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../23-fun-with-variables/assignment.md | 67 ++ .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../24-terraform-variables-quiz/assignment.md | 20 + .../25-hcp-terraform-setup/assignment.md | 38 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../26-configure-remote-state/assignment.md | 57 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../27-terraform-destroy/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../terraform-intro-aws/config.yml | 2 +- instruqt-tracks/terraform-intro-aws/track.yml | 1049 +--------------- .../01-setup-our-environment/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../02-hello-terraform/assignment.md | 51 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../03-azure-credentials/assignment.md | 40 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../04-terraform-code/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../05-terraform-init-provider/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../06-provider-quiz/assignment.md | 22 + .../07-terraform-validate/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../08-terraform-plan/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../09-terraform-variables/assignment.md | 29 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../10-terraform-add-a-variable/assignment.md | 45 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../11-variables-quiz/assignment.md | 22 + .../12-tf-graph/assignment.md | 46 + .../check-workstation | 0 .../cleanup-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../13-tf-plan-and-apply/assignment.md | 42 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../14-tf-plan-again/assignment.md | 43 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../15-change-prefix/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../16-add-a-tag/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../17-add-virtual-network/assignment.md | 30 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../18-complete-the-build/assignment.md | 37 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../19-tf-graph-again/assignment.md | 34 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../20-terraform-apply-quiz/assignment.md | 22 + .../21-use-a-provisioner/assignment.md | 58 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../22-add-an-output/assignment.md | 55 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../23-fun-with-variables/assignment.md | 67 ++ .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../24-terraform-variables-quiz/assignment.md | 20 + .../25-hcp-terraform-setup/assignment.md | 38 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../26-configure-remote-state/assignment.md | 57 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../27-terraform-destroy/assignment.md | 37 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../terraform-intro-azure/config.yml | 2 +- .../terraform-intro-azure/track.yml | 1055 +---------------- .../01-setup-our-environment/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../02-hello-terraform/assignment.md | 48 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../03-gcp-credentials/assignment.md | 32 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../04-terraform-code/assignment.md | 40 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../05-terraform-init-provider/assignment.md | 42 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../06-provider-quiz/assignment.md | 22 + .../07-terraform-validate/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../08-terraform-plan/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../09-terraform-variables/assignment.md | 29 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../10-terraform-add-a-variable/assignment.md | 43 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../11-variables-quiz/assignment.md | 22 + .../12-tf-graph/assignment.md | 46 + .../check-workstation | 0 .../cleanup-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../13-tf-apply/assignment.md | 43 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../14-tf-plan-again/assignment.md | 43 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../15-change-prefix/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../16-add-virtual-network/assignment.md | 32 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../17-complete-the-build/assignment.md | 39 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../18-tf-graph-again/assignment.md | 34 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../19-terraform-apply-quiz/assignment.md | 22 + .../20-use-a-provisioner/assignment.md | 59 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../21-add-an-output/assignment.md | 55 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../22-fun-with-variables/assignment.md | 65 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../23-terraform-variables-quiz/assignment.md | 20 + .../24-hcp-terraform-setup/assignment.md | 38 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../25-configure-remote-state/assignment.md | 57 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../26-terraform-destroy/assignment.md | 35 + .../check-workstation | 0 .../setup-workstation | 0 .../solve-workstation | 0 .../terraform-intro-gcp/config.yml | 2 +- instruqt-tracks/terraform-intro-gcp/track.yml | 1015 +--------------- 293 files changed, 3159 insertions(+), 3074 deletions(-) create mode 100755 instruqt-tracks/terraform-intro-aws/01-setup-our-environment/assignment.md rename instruqt-tracks/terraform-intro-aws/{setup-our-environment => 01-setup-our-environment}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{setup-our-environment => 01-setup-our-environment}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{setup-our-environment => 01-setup-our-environment}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/02-hello-terraform/assignment.md rename instruqt-tracks/terraform-intro-aws/{hello-terraform => 02-hello-terraform}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{add-a-tag => 02-hello-terraform}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{hello-terraform => 02-hello-terraform}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/03-aws-credentials/assignment.md rename instruqt-tracks/terraform-intro-aws/{aws-credentials => 03-aws-credentials}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{add-an-output => 03-aws-credentials}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{aws-credentials => 03-aws-credentials}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/04-terraform-code/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-code => 04-terraform-code}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{add-virtual-network => 04-terraform-code}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{configure-remote-state => 04-terraform-code}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-init-provider => 05-terraform-init-provider}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{aws-credentials => 05-terraform-init-provider}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-init-provider => 05-terraform-init-provider}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/06-provider-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-aws/07-terraform-validate/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-validate => 07-terraform-validate}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{change-prefix => 07-terraform-validate}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-validate => 07-terraform-validate}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/08-terraform-plan/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-plan => 08-terraform-plan}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{configure-remote-state => 08-terraform-plan}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-plan => 08-terraform-plan}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/09-terraform-variables/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-variables => 09-terraform-variables}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{fun-with-variables => 09-terraform-variables}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-variables => 09-terraform-variables}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-add-a-variable => 10-terraform-add-a-variable}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-add-a-variable => 10-terraform-add-a-variable}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-add-a-variable => 10-terraform-add-a-variable}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/11-variables-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-aws/12-tf-graph/assignment.md rename instruqt-tracks/terraform-intro-aws/{tf-graph => 12-tf-graph}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-graph => 12-tf-graph}/cleanup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{hello-terraform => 12-tf-graph}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-graph => 12-tf-graph}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/assignment.md rename instruqt-tracks/terraform-intro-aws/{tf-plan-and-apply => 13-tf-plan-and-apply}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-code => 13-tf-plan-and-apply}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-plan-and-apply => 13-tf-plan-and-apply}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/14-tf-plan-again/assignment.md rename instruqt-tracks/terraform-intro-aws/{tf-plan-again => 14-tf-plan-again}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-plan-again => 14-tf-plan-again}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-plan-again => 14-tf-plan-again}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/15-change-prefix/assignment.md rename instruqt-tracks/terraform-intro-aws/{change-prefix => 15-change-prefix}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-destroy => 15-change-prefix}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{change-prefix => 15-change-prefix}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/16-add-a-tag/assignment.md rename instruqt-tracks/terraform-intro-aws/{add-a-tag => 16-add-a-tag}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-init-provider => 16-add-a-tag}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{add-a-tag => 16-add-a-tag}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/17-add-virtual-network/assignment.md rename instruqt-tracks/terraform-intro-aws/{add-virtual-network => 17-add-virtual-network}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-plan => 17-add-virtual-network}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{add-virtual-network => 17-add-virtual-network}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/18-complete-the-build/assignment.md rename instruqt-tracks/terraform-intro-aws/{complete-the-build => 18-complete-the-build}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{complete-the-build => 18-complete-the-build}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{complete-the-build => 18-complete-the-build}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/19-tf-graph-again/assignment.md rename instruqt-tracks/terraform-intro-aws/{tf-graph-again => 19-tf-graph-again}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-validate => 19-tf-graph-again}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{fun-with-variables => 19-tf-graph-again}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/20-terraform-apply-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/assignment.md rename instruqt-tracks/terraform-intro-aws/{use-a-provisioner => 21-use-a-provisioner}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-variables => 21-use-a-provisioner}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{use-a-provisioner => 21-use-a-provisioner}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/22-add-an-output/assignment.md rename instruqt-tracks/terraform-intro-aws/{add-an-output => 22-add-an-output}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-graph-again => 22-add-an-output}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{add-an-output => 22-add-an-output}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/23-fun-with-variables/assignment.md rename instruqt-tracks/terraform-intro-aws/{configure-remote-state => 23-fun-with-variables}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-graph => 23-fun-with-variables}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-cloud-setup => 23-fun-with-variables}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/24-terraform-variables-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/assignment.md rename instruqt-tracks/terraform-intro-aws/{fun-with-variables => 25-hcp-terraform-setup}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-cloud-setup => 25-hcp-terraform-setup}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-code => 25-hcp-terraform-setup}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/26-configure-remote-state/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-cloud-setup => 26-configure-remote-state}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-plan-and-apply => 26-configure-remote-state}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{tf-graph-again => 26-configure-remote-state}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-aws/27-terraform-destroy/assignment.md rename instruqt-tracks/terraform-intro-aws/{terraform-destroy => 27-terraform-destroy}/check-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{use-a-provisioner => 27-terraform-destroy}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-aws/{terraform-destroy => 27-terraform-destroy}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/01-setup-our-environment/assignment.md rename instruqt-tracks/terraform-intro-azure/{setup-our-environment => 01-setup-our-environment}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{setup-our-environment => 01-setup-our-environment}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{setup-our-environment => 01-setup-our-environment}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/02-hello-terraform/assignment.md rename instruqt-tracks/terraform-intro-azure/{hello-terraform => 02-hello-terraform}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{add-a-tag => 02-hello-terraform}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{hello-terraform => 02-hello-terraform}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/03-azure-credentials/assignment.md rename instruqt-tracks/terraform-intro-azure/{azure-credentials => 03-azure-credentials}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{add-an-output => 03-azure-credentials}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{azure-credentials => 03-azure-credentials}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/04-terraform-code/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-code => 04-terraform-code}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{add-virtual-network => 04-terraform-code}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{configure-remote-state => 04-terraform-code}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-init-provider => 05-terraform-init-provider}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{azure-credentials => 05-terraform-init-provider}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-init-provider => 05-terraform-init-provider}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/06-provider-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-azure/07-terraform-validate/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-validate => 07-terraform-validate}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{change-prefix => 07-terraform-validate}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-validate => 07-terraform-validate}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/08-terraform-plan/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-plan => 08-terraform-plan}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{configure-remote-state => 08-terraform-plan}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-plan => 08-terraform-plan}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/09-terraform-variables/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-variables => 09-terraform-variables}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{fun-with-variables => 09-terraform-variables}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-variables => 09-terraform-variables}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-add-a-variable => 10-terraform-add-a-variable}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{hello-terraform => 10-terraform-add-a-variable}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-add-a-variable => 10-terraform-add-a-variable}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/11-variables-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-azure/12-tf-graph/assignment.md rename instruqt-tracks/terraform-intro-azure/{tf-graph => 12-tf-graph}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-graph => 12-tf-graph}/cleanup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-add-a-variable => 12-tf-graph}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-graph => 12-tf-graph}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/assignment.md rename instruqt-tracks/terraform-intro-azure/{tf-plan-and-apply => 13-tf-plan-and-apply}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-code => 13-tf-plan-and-apply}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-plan-and-apply => 13-tf-plan-and-apply}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/14-tf-plan-again/assignment.md rename instruqt-tracks/terraform-intro-azure/{tf-plan-again => 14-tf-plan-again}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-plan-again => 14-tf-plan-again}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-plan-again => 14-tf-plan-again}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/15-change-prefix/assignment.md rename instruqt-tracks/terraform-intro-azure/{change-prefix => 15-change-prefix}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-destroy => 15-change-prefix}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{change-prefix => 15-change-prefix}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/16-add-a-tag/assignment.md rename instruqt-tracks/terraform-intro-azure/{add-a-tag => 16-add-a-tag}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-init-provider => 16-add-a-tag}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{add-a-tag => 16-add-a-tag}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/17-add-virtual-network/assignment.md rename instruqt-tracks/terraform-intro-azure/{add-virtual-network => 17-add-virtual-network}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-plan => 17-add-virtual-network}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{add-virtual-network => 17-add-virtual-network}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/18-complete-the-build/assignment.md rename instruqt-tracks/terraform-intro-azure/{complete-the-build => 18-complete-the-build}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{complete-the-build => 18-complete-the-build}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{complete-the-build => 18-complete-the-build}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/19-tf-graph-again/assignment.md rename instruqt-tracks/terraform-intro-azure/{tf-graph-again => 19-tf-graph-again}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-validate => 19-tf-graph-again}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{fun-with-variables => 19-tf-graph-again}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/20-terraform-apply-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/assignment.md rename instruqt-tracks/terraform-intro-azure/{use-a-provisioner => 21-use-a-provisioner}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-variables => 21-use-a-provisioner}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{use-a-provisioner => 21-use-a-provisioner}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/22-add-an-output/assignment.md rename instruqt-tracks/terraform-intro-azure/{add-an-output => 22-add-an-output}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-graph-again => 22-add-an-output}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{add-an-output => 22-add-an-output}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/23-fun-with-variables/assignment.md rename instruqt-tracks/terraform-intro-azure/{configure-remote-state => 23-fun-with-variables}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-graph => 23-fun-with-variables}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-cloud-setup => 23-fun-with-variables}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/24-terraform-variables-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-cloud-setup => 25-hcp-terraform-setup}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-cloud-setup => 25-hcp-terraform-setup}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-code => 25-hcp-terraform-setup}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/26-configure-remote-state/assignment.md rename instruqt-tracks/terraform-intro-azure/{fun-with-variables => 26-configure-remote-state}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-plan-and-apply => 26-configure-remote-state}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{tf-graph-again => 26-configure-remote-state}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-azure/27-terraform-destroy/assignment.md rename instruqt-tracks/terraform-intro-azure/{terraform-destroy => 27-terraform-destroy}/check-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{use-a-provisioner => 27-terraform-destroy}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-azure/{terraform-destroy => 27-terraform-destroy}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/assignment.md rename instruqt-tracks/terraform-intro-gcp/{setup-our-environment => 01-setup-our-environment}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{setup-our-environment => 01-setup-our-environment}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{setup-our-environment => 01-setup-our-environment}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/02-hello-terraform/assignment.md rename instruqt-tracks/terraform-intro-gcp/{hello-terraform => 02-hello-terraform}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{add-an-output => 02-hello-terraform}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{hello-terraform => 02-hello-terraform}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/assignment.md rename instruqt-tracks/terraform-intro-gcp/{gcp-credentials => 03-gcp-credentials}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{add-virtual-network => 03-gcp-credentials}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{gcp-credentials => 03-gcp-credentials}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/04-terraform-code/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-cloud-setup => 04-terraform-code}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{change-prefix => 04-terraform-code}/setup-workstation (100%) mode change 100644 => 100755 rename instruqt-tracks/terraform-intro-gcp/{configure-remote-state => 04-terraform-code}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-init-provider => 05-terraform-init-provider}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{configure-remote-state => 05-terraform-init-provider}/setup-workstation (100%) mode change 100644 => 100755 rename instruqt-tracks/terraform-intro-gcp/{terraform-init-provider => 05-terraform-init-provider}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/06-provider-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-gcp/07-terraform-validate/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-validate => 07-terraform-validate}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{fun-with-variables => 07-terraform-validate}/setup-workstation (100%) mode change 100644 => 100755 rename instruqt-tracks/terraform-intro-gcp/{terraform-validate => 07-terraform-validate}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/08-terraform-plan/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-plan => 08-terraform-plan}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{gcp-credentials => 08-terraform-plan}/setup-workstation (100%) mode change 100644 => 100755 rename instruqt-tracks/terraform-intro-gcp/{terraform-plan => 08-terraform-plan}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/09-terraform-variables/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-variables => 09-terraform-variables}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{hello-terraform => 09-terraform-variables}/setup-workstation (100%) mode change 100644 => 100755 rename instruqt-tracks/terraform-intro-gcp/{terraform-variables => 09-terraform-variables}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-add-a-variable => 10-terraform-add-a-variable}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-add-a-variable => 10-terraform-add-a-variable}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-add-a-variable => 10-terraform-add-a-variable}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/11-variables-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-gcp/12-tf-graph/assignment.md rename instruqt-tracks/terraform-intro-gcp/{tf-graph => 12-tf-graph}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-graph => 12-tf-graph}/cleanup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-code => 12-tf-graph}/setup-workstation (100%) mode change 100755 => 100644 rename instruqt-tracks/terraform-intro-gcp/{tf-graph => 12-tf-graph}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/13-tf-apply/assignment.md rename instruqt-tracks/terraform-intro-gcp/{tf-apply => 13-tf-apply}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-destroy => 13-tf-apply}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-apply => 13-tf-apply}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/assignment.md rename instruqt-tracks/terraform-intro-gcp/{tf-plan-again => 14-tf-plan-again}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-plan-again => 14-tf-plan-again}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-plan-again => 14-tf-plan-again}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/15-change-prefix/assignment.md rename instruqt-tracks/terraform-intro-gcp/{change-prefix => 15-change-prefix}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-init-provider => 15-change-prefix}/setup-workstation (100%) mode change 100755 => 100644 rename instruqt-tracks/terraform-intro-gcp/{change-prefix => 15-change-prefix}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/assignment.md rename instruqt-tracks/terraform-intro-gcp/{add-virtual-network => 16-add-virtual-network}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-plan => 16-add-virtual-network}/setup-workstation (100%) mode change 100755 => 100644 rename instruqt-tracks/terraform-intro-gcp/{add-virtual-network => 16-add-virtual-network}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/17-complete-the-build/assignment.md rename instruqt-tracks/terraform-intro-gcp/{complete-the-build => 17-complete-the-build}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{complete-the-build => 17-complete-the-build}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{complete-the-build => 17-complete-the-build}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-code => 18-tf-graph-again}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-validate => 18-tf-graph-again}/setup-workstation (100%) mode change 100755 => 100644 rename instruqt-tracks/terraform-intro-gcp/{fun-with-variables => 18-tf-graph-again}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/19-terraform-apply-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/assignment.md rename instruqt-tracks/terraform-intro-gcp/{use-a-provisioner => 20-use-a-provisioner}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-variables => 20-use-a-provisioner}/setup-workstation (100%) mode change 100755 => 100644 rename instruqt-tracks/terraform-intro-gcp/{use-a-provisioner => 20-use-a-provisioner}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/21-add-an-output/assignment.md rename instruqt-tracks/terraform-intro-gcp/{add-an-output => 21-add-an-output}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-apply => 21-add-an-output}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{add-an-output => 21-add-an-output}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/assignment.md rename instruqt-tracks/terraform-intro-gcp/{configure-remote-state => 22-fun-with-variables}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-graph-again => 22-fun-with-variables}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-cloud-setup => 22-fun-with-variables}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/23-terraform-variables-quiz/assignment.md create mode 100755 instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/assignment.md rename instruqt-tracks/terraform-intro-gcp/{tf-graph-again => 24-hcp-terraform-setup}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-cloud-setup => 24-hcp-terraform-setup}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-code => 24-hcp-terraform-setup}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/assignment.md rename instruqt-tracks/terraform-intro-gcp/{fun-with-variables => 25-configure-remote-state}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-graph => 25-configure-remote-state}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{tf-graph-again => 25-configure-remote-state}/solve-workstation (100%) create mode 100755 instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/assignment.md rename instruqt-tracks/terraform-intro-gcp/{terraform-destroy => 26-terraform-destroy}/check-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{use-a-provisioner => 26-terraform-destroy}/setup-workstation (100%) rename instruqt-tracks/terraform-intro-gcp/{terraform-destroy => 26-terraform-destroy}/solve-workstation (100%) diff --git a/instruqt-tracks/terraform-intro-aws/01-setup-our-environment/assignment.md b/instruqt-tracks/terraform-intro-aws/01-setup-our-environment/assignment.md new file mode 100755 index 00000000..be87e361 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/01-setup-our-environment/assignment.md @@ -0,0 +1,39 @@ +--- +slug: setup-our-environment +id: ebj23ohhehzw +type: challenge +title: "\U0001F3E1 Moving in - Explore Your Workspace" +teaser: | + Explore the Terraform code for the hashicat application. +notes: +- type: text + contents: | + Setting up your environment... + Keep an eye on the bottom right corner to know when you can get started. +- type: text + contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD, + Windows, Solaris and Linux. +- type: text + contents: The Terraform language is designed to be both human and machine-readable. +- type: text + contents: Most modern code editors support Terraform syntax highlighting. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors. + +When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor! + +Throughout this track, please execute all commands on the "Shell" tab. + +Congratulations, you are ready to start working with Terraform on AWS. We'll use the hashicat-aws example app in the rest of the challenges as you learn new Terraform skills. + +Click the **Check** button to continue. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/setup-our-environment/check-workstation b/instruqt-tracks/terraform-intro-aws/01-setup-our-environment/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/setup-our-environment/check-workstation rename to instruqt-tracks/terraform-intro-aws/01-setup-our-environment/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/setup-our-environment/setup-workstation b/instruqt-tracks/terraform-intro-aws/01-setup-our-environment/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/setup-our-environment/setup-workstation rename to instruqt-tracks/terraform-intro-aws/01-setup-our-environment/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/setup-our-environment/solve-workstation b/instruqt-tracks/terraform-intro-aws/01-setup-our-environment/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/setup-our-environment/solve-workstation rename to instruqt-tracks/terraform-intro-aws/01-setup-our-environment/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/02-hello-terraform/assignment.md b/instruqt-tracks/terraform-intro-aws/02-hello-terraform/assignment.md new file mode 100755 index 00000000..feadf750 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/02-hello-terraform/assignment.md @@ -0,0 +1,51 @@ +--- +slug: hello-terraform +id: e0tq7efazoo2 +type: challenge +title: "\U0001F44B Getting to Know Terraform" +teaser: | + Learn Terraform basics and command line syntax. +notes: +- type: text + contents: |- + Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation. + + It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html +- type: text + contents: |- + Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH. + + Check out this tutorial for step-by-step instructions: + + https://learn.hashicorp.com/terraform/getting-started/install.html + + We've pre-installed Terraform in your Instruqt lab environment for you. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Let's start with some basic Terraform commands. +Run the following commands on the "Shell" tab. + +Check the version of Terraform running on your machine: + +``` +terraform version +``` + +You can always get help if you're curious about command syntax: + +``` +terraform --help +``` + +Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation. + +Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/hello-terraform/check-workstation b/instruqt-tracks/terraform-intro-aws/02-hello-terraform/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/hello-terraform/check-workstation rename to instruqt-tracks/terraform-intro-aws/02-hello-terraform/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/add-a-tag/setup-workstation b/instruqt-tracks/terraform-intro-aws/02-hello-terraform/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-a-tag/setup-workstation rename to instruqt-tracks/terraform-intro-aws/02-hello-terraform/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/hello-terraform/solve-workstation b/instruqt-tracks/terraform-intro-aws/02-hello-terraform/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/hello-terraform/solve-workstation rename to instruqt-tracks/terraform-intro-aws/02-hello-terraform/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/03-aws-credentials/assignment.md b/instruqt-tracks/terraform-intro-aws/03-aws-credentials/assignment.md new file mode 100755 index 00000000..335c4041 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/03-aws-credentials/assignment.md @@ -0,0 +1,34 @@ +--- +slug: aws-credentials +id: qtjyikiuvx9z +type: challenge +title: "\U0001F510 Connecting Terraform to AWS" +teaser: | + Connecting to AWS with Access Keys and Secret Keys. +notes: +- type: text + contents: Did you know HCL stands for "HashiCorp Configuration Language"? +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +In order to authenticate to AWS and build resources, Terraform requires you to provide a set of credentials, backed by an appropriate IAM policy. + +For this training environment, we have prepared some temporary AWS credentials and stored them as environment variables. Terraform will automatically read and use the environment variables that are configured in your shell environment. + +Run the following commands on the "Shell" tab: + +``` +echo $AWS_ACCESS_KEY_ID +echo $AWS_SECRET_ACCESS_KEY +``` +You should see valid AWS keys. If not, return to the track home page by clicking the **Close** button, stop the track, and then restart it. + +*Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/aws-credentials/check-workstation b/instruqt-tracks/terraform-intro-aws/03-aws-credentials/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/aws-credentials/check-workstation rename to instruqt-tracks/terraform-intro-aws/03-aws-credentials/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/add-an-output/setup-workstation b/instruqt-tracks/terraform-intro-aws/03-aws-credentials/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-an-output/setup-workstation rename to instruqt-tracks/terraform-intro-aws/03-aws-credentials/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/aws-credentials/solve-workstation b/instruqt-tracks/terraform-intro-aws/03-aws-credentials/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/aws-credentials/solve-workstation rename to instruqt-tracks/terraform-intro-aws/03-aws-credentials/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/04-terraform-code/assignment.md b/instruqt-tracks/terraform-intro-aws/04-terraform-code/assignment.md new file mode 100755 index 00000000..7513273e --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/04-terraform-code/assignment.md @@ -0,0 +1,39 @@ +--- +slug: terraform-code +id: ozizhb0unuov +type: challenge +title: "\U0001F468‍\U0001F4BB What does Terraform code look like?" +teaser: | + The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure. +notes: +- type: text + contents: |- + Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`. + + By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files. + + You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files: + ``` + ls *.tf + ``` + The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon. + + Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first: + + **main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.
+ **variables.tf** - Use this file to define which variables will be available to your users.
+ **outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run. + + Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-code/check-workstation b/instruqt-tracks/terraform-intro-aws/04-terraform-code/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-code/check-workstation rename to instruqt-tracks/terraform-intro-aws/04-terraform-code/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/add-virtual-network/setup-workstation b/instruqt-tracks/terraform-intro-aws/04-terraform-code/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-virtual-network/setup-workstation rename to instruqt-tracks/terraform-intro-aws/04-terraform-code/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/configure-remote-state/solve-workstation b/instruqt-tracks/terraform-intro-aws/04-terraform-code/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/configure-remote-state/solve-workstation rename to instruqt-tracks/terraform-intro-aws/04-terraform-code/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/assignment.md b/instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/assignment.md new file mode 100755 index 00000000..ebb2320a --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/assignment.md @@ -0,0 +1,42 @@ +--- +slug: terraform-init-provider +id: rxw0ladzg8zc +type: challenge +title: "\U0001F3E1 Terraform Init - Install the Providers" +teaser: | + Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers. +notes: +- type: text + contents: |- + The Terraform core program isn't very useful by itself. Terraform needs the help of a *provider* to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here: + + https://registry.terraform.io/browse/providers + + Today we'll be using a few different providers, but the main one is the *aws* provider. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track. + +Before we can do anything with Terraform we need to initialize our workspace. Run the following command in your "Shell" tab: +``` +terraform init +``` + +The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them. + +Run the following command to verify that the aws provider was installed under the ".terraform" directory: + +``` +ls .terraform/providers/registry.terraform.io/hashicorp +``` + +This hidden directory is where all modules and plugins are stored. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-init-provider/check-workstation b/instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-init-provider/check-workstation rename to instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/aws-credentials/setup-workstation b/instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/aws-credentials/setup-workstation rename to instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-init-provider/solve-workstation b/instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-init-provider/solve-workstation rename to instruqt-tracks/terraform-intro-aws/05-terraform-init-provider/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/06-provider-quiz/assignment.md b/instruqt-tracks/terraform-intro-aws/06-provider-quiz/assignment.md new file mode 100755 index 00000000..8a95ed1d --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/06-provider-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: provider-quiz +id: qtjoepabjrlx +type: quiz +title: "\U0001F4DD Quiz 1 - Providers and Modules" +teaser: | + A quiz about Terraform init +notes: +- type: text + contents: | + It's quiz time! +answers: +- In the /tmp directory +- In the user's home directory +- In the .terraform directory +- None of the above +solution: +- 2 +difficulty: basic +timelimit: 10000 +--- +Where does Terraform store its modules and providers? diff --git a/instruqt-tracks/terraform-intro-aws/07-terraform-validate/assignment.md b/instruqt-tracks/terraform-intro-aws/07-terraform-validate/assignment.md new file mode 100755 index 00000000..f0cf5c3f --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/07-terraform-validate/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-validate +id: 0ge7cn9kcnom +type: challenge +title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code" +teaser: | + Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly. +notes: +- type: text + contents: Terraform has a built-in syntax checker. You can run it with the `terraform + validate` command. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Terraform comes with a built-in subcommand called *validate*. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly. + +Edit the main.tf file and remove the double quotes between `aws_vpc` and `hashicat` on line 14 of the file, keeping the space that was between them. Save the file. + +Validate your code: + +``` +terraform validate +``` + +Now put the double quotes back in line 14, save the file, and run the validate command again. This time you should pass the validation test. + +`terraform validate` is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-validate/check-workstation b/instruqt-tracks/terraform-intro-aws/07-terraform-validate/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-validate/check-workstation rename to instruqt-tracks/terraform-intro-aws/07-terraform-validate/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/change-prefix/setup-workstation b/instruqt-tracks/terraform-intro-aws/07-terraform-validate/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/change-prefix/setup-workstation rename to instruqt-tracks/terraform-intro-aws/07-terraform-validate/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-validate/solve-workstation b/instruqt-tracks/terraform-intro-aws/07-terraform-validate/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-validate/solve-workstation rename to instruqt-tracks/terraform-intro-aws/07-terraform-validate/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/08-terraform-plan/assignment.md b/instruqt-tracks/terraform-intro-aws/08-terraform-plan/assignment.md new file mode 100755 index 00000000..fe6793d3 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/08-terraform-plan/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-plan +id: wrnxxdklcxbq +type: challenge +title: "\U0001F914 Terraform Plan - Dry Run Mode" +teaser: | + Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run `terraform plan` and view the output. +notes: +- type: text + contents: |- + `terraform plan` allows you to preview any changes to your environment in a safe way. + + This can help you identify any unexpected changes before you deploy them, not after they are already built. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Run the `terraform plan` command: + +``` +terraform plan +``` + +When you run this command Terraform will prompt you to enter the `prefix` variable. + +Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name. + +The prefix will become part of the name for our VPC, subnet, EC2 instance and other resources. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-plan/check-workstation b/instruqt-tracks/terraform-intro-aws/08-terraform-plan/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-plan/check-workstation rename to instruqt-tracks/terraform-intro-aws/08-terraform-plan/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/configure-remote-state/setup-workstation b/instruqt-tracks/terraform-intro-aws/08-terraform-plan/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/configure-remote-state/setup-workstation rename to instruqt-tracks/terraform-intro-aws/08-terraform-plan/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-plan/solve-workstation b/instruqt-tracks/terraform-intro-aws/08-terraform-plan/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-plan/solve-workstation rename to instruqt-tracks/terraform-intro-aws/08-terraform-plan/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/09-terraform-variables/assignment.md b/instruqt-tracks/terraform-intro-aws/09-terraform-variables/assignment.md new file mode 100755 index 00000000..2ac3a20b --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/09-terraform-variables/assignment.md @@ -0,0 +1,29 @@ +--- +slug: terraform-variables +id: d9uqeneyhruz +type: challenge +title: "\U0001F39B️ Working with Terraform Variables" +teaser: | + Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables. +notes: +- type: text + contents: The `terraform.tfvars` file is a convenient place for users to configure + their variables. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later. + +Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case). + +**Be sure to click the disk icon above the file to save your change!** + +Now run `terraform plan` again. This time you won't have to enter your prefix manually. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-variables/check-workstation b/instruqt-tracks/terraform-intro-aws/09-terraform-variables/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-variables/check-workstation rename to instruqt-tracks/terraform-intro-aws/09-terraform-variables/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/fun-with-variables/setup-workstation b/instruqt-tracks/terraform-intro-aws/09-terraform-variables/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/fun-with-variables/setup-workstation rename to instruqt-tracks/terraform-intro-aws/09-terraform-variables/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-variables/solve-workstation b/instruqt-tracks/terraform-intro-aws/09-terraform-variables/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-variables/solve-workstation rename to instruqt-tracks/terraform-intro-aws/09-terraform-variables/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/assignment.md b/instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/assignment.md new file mode 100755 index 00000000..12d9534b --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/assignment.md @@ -0,0 +1,43 @@ +--- +slug: terraform-add-a-variable +id: zdbscmg1vqjl +type: challenge +title: "\U0001F5FC Change Your Location" +teaser: | + Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable. +notes: +- type: text + contents: |- + You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file. + + In this challenge, you will pick the location where your AWS resources should be deployed. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set another variable that will determine the location where your AWS infrastructure will be deployed. + +First run another plan so you'll be able to compare what happens after you change the location. + +``` +terraform plan +``` + +Choose an AWS region near you but different from the default one which is "us-east-1". Add a `region` variable to your "terraform.tfvars" file, setting it to your desired region such as `us-west-1`, `eu-west-2`, or `ap-southeast-1`. + +See this [page](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) for a list of valid AWS regions. + +Choosing a region close to you can help improve speed and performance. + +**Be sure to click the disk icon above the file to save your change!** + +Once you've set your `region` variable, try running `terraform plan` again. What's different this time? + +Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-add-a-variable/check-workstation b/instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-add-a-variable/check-workstation rename to instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-add-a-variable/setup-workstation b/instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-add-a-variable/setup-workstation rename to instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-add-a-variable/solve-workstation b/instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-add-a-variable/solve-workstation rename to instruqt-tracks/terraform-intro-aws/10-terraform-add-a-variable/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/11-variables-quiz/assignment.md b/instruqt-tracks/terraform-intro-aws/11-variables-quiz/assignment.md new file mode 100755 index 00000000..d8928dab --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/11-variables-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: variables-quiz +id: tyodsjvgyh6w +type: quiz +title: "\U0001F4DD Quiz 2 - Variables" +teaser: | + A quiz about Terraform variables +notes: +- type: text + contents: | + Another quiz, get ready! +answers: +- On the command line +- As environment variables +- In the variables.tf file +- In the terraform.tfvars file +solution: +- 2 +difficulty: basic +timelimit: 10000 +--- +Where are terraform variables usually *declared*? diff --git a/instruqt-tracks/terraform-intro-aws/12-tf-graph/assignment.md b/instruqt-tracks/terraform-intro-aws/12-tf-graph/assignment.md new file mode 100755 index 00000000..105ea2bf --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/12-tf-graph/assignment.md @@ -0,0 +1,46 @@ +--- +slug: tf-graph +id: 4q6h5ttt7zb5 +type: challenge +title: "\U0001F4C8 Terraform Graph" +teaser: | + Terraform creates a graph of all the infrastructure defined in your code. +notes: +- type: text + contents: Terraform Graph can provide a visual representation of all your infrastructure. + This is handy for finding dependency issues or resources that will be affected + by a change. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Terraform Graph + type: service + hostname: workstation + port: 5000 +difficulty: basic +timelimit: 10000 +--- +Try running the `terraform graph` command: + +``` +terraform graph +``` + +This generates code that can be used to create a visual map of your infrastructure. The graph data is in [DOT graph description language format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). There are several graphing tools you can use to visualize this data, including the free Blast Radius tool. You can learn more about Blast Radius here: + +https://28mm.github.io/blast-radius-docs/ + +Start up a Blast Radius server with the following command: + +``` +blast-radius --serve . +``` + +Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) + +Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. + +**NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. + +Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph/check-workstation b/instruqt-tracks/terraform-intro-aws/12-tf-graph/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph/check-workstation rename to instruqt-tracks/terraform-intro-aws/12-tf-graph/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph/cleanup-workstation b/instruqt-tracks/terraform-intro-aws/12-tf-graph/cleanup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph/cleanup-workstation rename to instruqt-tracks/terraform-intro-aws/12-tf-graph/cleanup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/hello-terraform/setup-workstation b/instruqt-tracks/terraform-intro-aws/12-tf-graph/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/hello-terraform/setup-workstation rename to instruqt-tracks/terraform-intro-aws/12-tf-graph/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph/solve-workstation b/instruqt-tracks/terraform-intro-aws/12-tf-graph/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph/solve-workstation rename to instruqt-tracks/terraform-intro-aws/12-tf-graph/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/assignment.md b/instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/assignment.md new file mode 100755 index 00000000..fbf9e367 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/assignment.md @@ -0,0 +1,42 @@ +--- +slug: tf-plan-and-apply +id: jenvz4vgpcok +type: challenge +title: "\U0001F468‍\U0001F4BB Terraform Plan and Terraform Apply" +teaser: | + The `terraform plan` command can be run anytime to get a preview of changes that Terraform might make. When you run Terraform apply these changes are implemented, and Terraform builds, updates, or destroys resources. +notes: +- type: text + contents: |- + By default, the `terraform apply` command runs a Terraform plan to show you what changes it wants to make. + + Terraform maps out all the changes it needs to make before applying them. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Now that we've configured our required variables we can apply our changes. + +Run the `terraform plan` command first to see what will happen: + +``` +terraform plan +``` +Confirm the proper prefix and location are displayed in the plan output. + +Then run `terraform apply` and watch your resources being built. + +``` +terraform apply +``` + +You'll need to enter **yes** when Terraform prompts you with the "Do you want to perform these actions?" question. + +Right now our code only defines a VPC. We'll be building upon this starting point in the next challenge. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/tf-plan-and-apply/check-workstation b/instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-plan-and-apply/check-workstation rename to instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-code/setup-workstation b/instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-code/setup-workstation rename to instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-plan-and-apply/solve-workstation b/instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-plan-and-apply/solve-workstation rename to instruqt-tracks/terraform-intro-aws/13-tf-plan-and-apply/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/14-tf-plan-again/assignment.md b/instruqt-tracks/terraform-intro-aws/14-tf-plan-again/assignment.md new file mode 100755 index 00000000..8c84247e --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/14-tf-plan-again/assignment.md @@ -0,0 +1,43 @@ +--- +slug: tf-plan-again +id: oxmdpa6rocnw +type: challenge +title: "\U0001F469‍\U0001F4BB Test and Repair" +teaser: | + Terraform is idempotent. Each resource in your code will be examined, and if it already exists Terraform will leave it alone. +notes: +- type: text + contents: |- + Terraform is an *idempotent* application. + + Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. + + https://en.wikipedia.org/wiki/Idempotence +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Try running `terraform plan` again and see what happens: + +``` +terraform plan +``` + +Since your VPC has already been built, Terraform will report that there are no changes required. + +This is normal and expected. + +Now try running another apply: + +``` +terraform apply +``` + +Terraform checks each resource to ensure it is in the proper state. It will not re-create your VPC if it is already provisioned correctly. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/tf-plan-again/check-workstation b/instruqt-tracks/terraform-intro-aws/14-tf-plan-again/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-plan-again/check-workstation rename to instruqt-tracks/terraform-intro-aws/14-tf-plan-again/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-plan-again/setup-workstation b/instruqt-tracks/terraform-intro-aws/14-tf-plan-again/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-plan-again/setup-workstation rename to instruqt-tracks/terraform-intro-aws/14-tf-plan-again/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-plan-again/solve-workstation b/instruqt-tracks/terraform-intro-aws/14-tf-plan-again/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-plan-again/solve-workstation rename to instruqt-tracks/terraform-intro-aws/14-tf-plan-again/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/15-change-prefix/assignment.md b/instruqt-tracks/terraform-intro-aws/15-change-prefix/assignment.md new file mode 100755 index 00000000..c61fb62e --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/15-change-prefix/assignment.md @@ -0,0 +1,35 @@ +--- +slug: change-prefix +id: kgo0ykyxezo0 +type: challenge +title: "\U0001F6EB Change Your Prefix" +teaser: | + When your Terraform code changes, your infrastructure will be modified to match the updated code. Terraform is a declarative language. +notes: +- type: text + contents: |- + Terraform can create, destroy, update in place, or destroy and re-create your infrastructure. Some types of resources can be updated without deleting them. Major changes usually require a teardown and rebuild. + + Terraform always tries to match the current infrastructure to what has been defined in your code. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Edit the `terraform.tfvars` file to change your prefix. You could simply add a number to the end if you like. Or change it to something entirely new. + +Save the `terraform.tfvars` file and run your apply command again. + +``` +terraform apply +``` + +Type "yes" when prompted. + +Observe the output. What happened? \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/change-prefix/check-workstation b/instruqt-tracks/terraform-intro-aws/15-change-prefix/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/change-prefix/check-workstation rename to instruqt-tracks/terraform-intro-aws/15-change-prefix/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-destroy/setup-workstation b/instruqt-tracks/terraform-intro-aws/15-change-prefix/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-destroy/setup-workstation rename to instruqt-tracks/terraform-intro-aws/15-change-prefix/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/change-prefix/solve-workstation b/instruqt-tracks/terraform-intro-aws/15-change-prefix/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/change-prefix/solve-workstation rename to instruqt-tracks/terraform-intro-aws/15-change-prefix/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/16-add-a-tag/assignment.md b/instruqt-tracks/terraform-intro-aws/16-add-a-tag/assignment.md new file mode 100755 index 00000000..fb9564b6 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/16-add-a-tag/assignment.md @@ -0,0 +1,33 @@ +--- +slug: add-a-tag +id: nv5xjz6pyjrx +type: challenge +title: "\U0001F3F7️ Add a Tag to Your VPC" +teaser: | + Terraform can change some resources in in place without deleting them. Adding tags is a non-destructive action. +notes: +- type: text + contents: Adding, changing, or removing tags is a non-destructive action. Terraform + can tag your resources without re-creating them. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Several resource types support AWS's tags. Read the Terraform documentation for the `aws_vpc` resource to learn about the `tags` argument and its format. + +[Terraform Docs: the aws_vpc resource - Click Here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc) + +Add a tag to your VPC resource in the **main.tf** file. The name of the tag should be `environment` and the value should be `Production`. (The tag is case-sensitive. Make sure you use a capital P.) + +Hint: Read the examples carefully! Unlike the other resource arguments you've seen, the value of the `tags` argument must be a **map** (a `{key = "value"}` data structure). Additionally, you must use `=` after `tags` and after `environment`. For more about Terraform's data types, see the [Terraform language documentation](https://www.terraform.io/docs/configuration/expressions.html#types-and-values). + +Re-run `terraform apply` and answer "yes" when prompted. + +What happens? \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/add-a-tag/check-workstation b/instruqt-tracks/terraform-intro-aws/16-add-a-tag/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-a-tag/check-workstation rename to instruqt-tracks/terraform-intro-aws/16-add-a-tag/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-init-provider/setup-workstation b/instruqt-tracks/terraform-intro-aws/16-add-a-tag/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-init-provider/setup-workstation rename to instruqt-tracks/terraform-intro-aws/16-add-a-tag/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/add-a-tag/solve-workstation b/instruqt-tracks/terraform-intro-aws/16-add-a-tag/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-a-tag/solve-workstation rename to instruqt-tracks/terraform-intro-aws/16-add-a-tag/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/17-add-virtual-network/assignment.md b/instruqt-tracks/terraform-intro-aws/17-add-virtual-network/assignment.md new file mode 100755 index 00000000..2ea66a84 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/17-add-virtual-network/assignment.md @@ -0,0 +1,30 @@ +--- +slug: add-virtual-network +id: 9ptlans5zhfw +type: challenge +title: "\U0001F5A7 Add a Virtual Network" +teaser: | + Terraform resources are like building blocks. You can continue adding more blocks until your infrastructure reaches the desired state. +notes: +- type: text + contents: Terraform code can be built incrementally, one or two resources at a time. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Open the **main.tf** file again and uncomment the next resource block in the file. The type of resource is **aws_subnet** and it is named **hashicat**. + +Uncomment the code by removing the `#` characters from the beginning of each line. Be sure to save the file. + +Now run `terraform apply` again and answer "yes" when prompted. Observe the results. + +Look at the **vpc_id** parameter inside the aws_subnet resource. See how it points back at the first resource in the file? The subnet resource inherits settings from the VPC. + +Terraform can map out the complex web of dependencies between hundreds of interconnected resources. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/add-virtual-network/check-workstation b/instruqt-tracks/terraform-intro-aws/17-add-virtual-network/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-virtual-network/check-workstation rename to instruqt-tracks/terraform-intro-aws/17-add-virtual-network/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-plan/setup-workstation b/instruqt-tracks/terraform-intro-aws/17-add-virtual-network/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-plan/setup-workstation rename to instruqt-tracks/terraform-intro-aws/17-add-virtual-network/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/add-virtual-network/solve-workstation b/instruqt-tracks/terraform-intro-aws/17-add-virtual-network/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-virtual-network/solve-workstation rename to instruqt-tracks/terraform-intro-aws/17-add-virtual-network/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/18-complete-the-build/assignment.md b/instruqt-tracks/terraform-intro-aws/18-complete-the-build/assignment.md new file mode 100755 index 00000000..3a8a1117 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/18-complete-the-build/assignment.md @@ -0,0 +1,39 @@ +--- +slug: complete-the-build +id: lbfvxdqle2rk +type: challenge +title: "\U0001F3D7️ Complete the Build" +teaser: | + Terraform code can stand up everything from VPCs, to virtual networks, to VMs and containers. +notes: +- type: text + contents: The `-auto-approve` flag can be used to override the "Are you sure?" questions + that appear before an apply or destroy. Use with caution! +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +We've uncommented all the rest of the Terraform code in the **main.tf** file for you. Run a `terraform plan` to see what will be built: + +``` +terraform plan +``` + +Now run an apply to build the HashiCat application: + +``` +terraform apply -auto-approve +``` + +It can take up to five minutes for the application to finish deploying. You will know it is complete when you see the Terraform output with your application URL at the end of the run. + +If the application won't load just run `terraform apply` again. This will attempt to reinstall the webserver and start your application if it's not running. + +Open your web application in a new browser tab by clicking on the URL in the `catapp_url` output. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/complete-the-build/check-workstation b/instruqt-tracks/terraform-intro-aws/18-complete-the-build/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/complete-the-build/check-workstation rename to instruqt-tracks/terraform-intro-aws/18-complete-the-build/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/complete-the-build/setup-workstation b/instruqt-tracks/terraform-intro-aws/18-complete-the-build/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/complete-the-build/setup-workstation rename to instruqt-tracks/terraform-intro-aws/18-complete-the-build/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/complete-the-build/solve-workstation b/instruqt-tracks/terraform-intro-aws/18-complete-the-build/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/complete-the-build/solve-workstation rename to instruqt-tracks/terraform-intro-aws/18-complete-the-build/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/19-tf-graph-again/assignment.md b/instruqt-tracks/terraform-intro-aws/19-tf-graph-again/assignment.md new file mode 100755 index 00000000..744e0ed4 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/19-tf-graph-again/assignment.md @@ -0,0 +1,34 @@ +--- +slug: tf-graph-again +id: dzpnmofdi51v +type: challenge +title: "\U0001F4C8 Terraform Graph" +teaser: | + Revisit graph to see what has changed. +notes: +- type: text + contents: Let's revisit our graph to see what has changed. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Terraform Graph + type: service + hostname: workstation + port: 5000 +difficulty: basic +timelimit: 10000 +--- +Start up a Blast Radius server with the following command: + +``` +blast-radius --serve . +``` + +Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) + +Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. + +**NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. + +Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph-again/check-workstation b/instruqt-tracks/terraform-intro-aws/19-tf-graph-again/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph-again/check-workstation rename to instruqt-tracks/terraform-intro-aws/19-tf-graph-again/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-validate/setup-workstation b/instruqt-tracks/terraform-intro-aws/19-tf-graph-again/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-validate/setup-workstation rename to instruqt-tracks/terraform-intro-aws/19-tf-graph-again/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/fun-with-variables/solve-workstation b/instruqt-tracks/terraform-intro-aws/19-tf-graph-again/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/fun-with-variables/solve-workstation rename to instruqt-tracks/terraform-intro-aws/19-tf-graph-again/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/20-terraform-apply-quiz/assignment.md b/instruqt-tracks/terraform-intro-aws/20-terraform-apply-quiz/assignment.md new file mode 100755 index 00000000..acd0bce9 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/20-terraform-apply-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: terraform-apply-quiz +id: xyuiqhtqzbpq +type: quiz +title: "\U0001F4DD Quiz 3 - Terraform Apply" +teaser: | + What happens when you run `terraform apply` without a plan file? +notes: +- type: text + contents: | + It's quiz time! +answers: +- Terraform runs without any plan +- Terraform reads the previous plan and then applies it +- Terraform runs a new plan right before the apply +- None of the above +solution: +- 2 +difficulty: basic +timelimit: 10000 +--- +What happens when you run `terraform apply` without specifying a plan file? diff --git a/instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/assignment.md b/instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/assignment.md new file mode 100755 index 00000000..e56adaf8 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/assignment.md @@ -0,0 +1,59 @@ +--- +slug: use-a-provisioner +id: sqy7awg7mrho +type: challenge +title: "\U0001F6E0️ Use a Provisioner" +teaser: | + Terraform works great with many different provisioning tools including Chef, Puppet, Ansible, Bash, and Powershell. +notes: +- type: text + contents: Terraform provisioners run once at creation time. They do not run on subsequent + applies, except in special circumstances. (Like this training lab...) +- type: text + contents: We've made some special adjustments to force the provisioner to run every + time you type terraform apply. This is so you can practice playing with provisioners + without destroying and recreating your virtual machine every time you make a change. +- type: text + contents: |- + ``` + ______________________ + < Cows love Terraform! > + ---------------------- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || || + ============================= + ``` +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Open the `main.tf` file on the "Code Editor" tab. Scroll down until you find the `remote-exec` provisioner block. + +Add the following two lines at the end of the inline list of commands: + +``` +"sudo apt -y install cowsay", +"cowsay Mooooooooooo!", +``` + +After copying them into your buffer, it will be easier to paste them if you hide the assignment by clicking the ">" icon . Click it again to redisplay the assignment. Be sure to save the file. + +This might be a good time to use the `terraform fmt` command to line up the commands nicely. + +Now apply your changes: + +``` +terraform apply -auto-approve +``` + +Scroll back through the log output. You should see an ASCII art cow saying "Moooooooo!" \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/use-a-provisioner/check-workstation b/instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/use-a-provisioner/check-workstation rename to instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-variables/setup-workstation b/instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-variables/setup-workstation rename to instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/use-a-provisioner/solve-workstation b/instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/use-a-provisioner/solve-workstation rename to instruqt-tracks/terraform-intro-aws/21-use-a-provisioner/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/22-add-an-output/assignment.md b/instruqt-tracks/terraform-intro-aws/22-add-an-output/assignment.md new file mode 100755 index 00000000..6fdd277c --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/22-add-an-output/assignment.md @@ -0,0 +1,55 @@ +--- +slug: add-an-output +id: eykyj0r8kspo +type: challenge +title: "\U0001F5A8️ Add an Output" +teaser: | + Outputs are used to convey useful information such as IP addresses, application URLs or other useful data. +notes: +- type: text + contents: You can mix plain text along with Terraform data in your outputs. Outputs + can be used to convey useful information to your users at the end of a run. +- type: text + contents: The `terraform refresh` command will sync your state file with what exists + in your infrastructure. A refresh command will not change your infrastructure. +- type: text + contents: The `terraform output` command can be run any time you want to see your + Terraform outputs again. Run `terraform output ` to view a single + output. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Open the **outputs.tf** file on the "Code Editor" tab. Note the public_dns output in the file. + +Add a second output for the `public_ip` of your web server. It's going to look almost exactly like the first output but will instead output an IP address instead of a DNS name. + +Name your output `catapp_ip`. + +You may refer to the docs page to see what types of outputs are valid: + +[Terraform AWS Docs - Click Here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#attributes-reference) +[Terraform Outputs Docs - Click Here](https://www.terraform.io/docs/configuration/outputs.html) + +Be sure to save the changes to the **outputs.tf** file. + +Run the Terraform refresh command to view your new output: + +``` +terraform refresh +``` + +You can run the Terraform output command to view all your outputs: + +``` +terraform output +``` + +You can click on either URL to use the web app. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/add-an-output/check-workstation b/instruqt-tracks/terraform-intro-aws/22-add-an-output/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-an-output/check-workstation rename to instruqt-tracks/terraform-intro-aws/22-add-an-output/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph-again/setup-workstation b/instruqt-tracks/terraform-intro-aws/22-add-an-output/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph-again/setup-workstation rename to instruqt-tracks/terraform-intro-aws/22-add-an-output/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/add-an-output/solve-workstation b/instruqt-tracks/terraform-intro-aws/22-add-an-output/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/add-an-output/solve-workstation rename to instruqt-tracks/terraform-intro-aws/22-add-an-output/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/23-fun-with-variables/assignment.md b/instruqt-tracks/terraform-intro-aws/23-fun-with-variables/assignment.md new file mode 100755 index 00000000..b57dde4e --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/23-fun-with-variables/assignment.md @@ -0,0 +1,67 @@ +--- +slug: fun-with-variables +id: 5qgxis0l5aqi +type: challenge +title: "\U0001F436 Fun With Variables" +teaser: | + Variables give the consumers of your Terraform code an easy way to customize their infrastructure. +notes: +- type: text + contents: |- + Terraform variables have five levels of precedence. 1=highest 5=lowest: + + 1. Command line flag - run as a command line switch + 1. Configuration file - set in your terraform.tfvars file + 1. Environment variable - part of your shell environment + 1. Default Config - default value in variables.tf + 1. User manual entry - if not specified, prompt the user for entry +- type: text + contents: |- + Here are some other fun placeholder sites you can try with the **placeholder** variable: + + placedog.net
+ placebear.com
+ www.fillmurray.com
+ www.placecage.com
+ placebeard.it
+ loremflickr.com
+ baconmockup.com
+ placeimg.com
+tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +There are several ways to configure Terraform variables. So far we've been using the `terraform.tfvars` file to set our variables. Try re-deploying your application with different **height** and **width** variables on the command line. Reload the webapp after each apply to observe any changes. + +``` +terraform apply -auto-approve -var height=600 -var width=800 +``` + +Next try setting an environment variable that Terraform can read. Run this command to set the placeholder variable: + +``` +export TF_VAR_placeholder=placedog.net +``` + +Run another `terraform apply -auto-approve` command: + +``` +terraform apply -auto-approve +``` + +Now try it again with the same variable set differently on the command line: + +``` +terraform apply -auto-approve -var placeholder=placebear.com +``` + +Which variable took precedence? Why? + +See this [doc](https://www.terraform.io/docs/configuration/variables.html#variable-definition-precedence) if you're unsure. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/configure-remote-state/check-workstation b/instruqt-tracks/terraform-intro-aws/23-fun-with-variables/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/configure-remote-state/check-workstation rename to instruqt-tracks/terraform-intro-aws/23-fun-with-variables/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph/setup-workstation b/instruqt-tracks/terraform-intro-aws/23-fun-with-variables/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph/setup-workstation rename to instruqt-tracks/terraform-intro-aws/23-fun-with-variables/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-cloud-setup/solve-workstation b/instruqt-tracks/terraform-intro-aws/23-fun-with-variables/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-cloud-setup/solve-workstation rename to instruqt-tracks/terraform-intro-aws/23-fun-with-variables/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/24-terraform-variables-quiz/assignment.md b/instruqt-tracks/terraform-intro-aws/24-terraform-variables-quiz/assignment.md new file mode 100755 index 00000000..62a3d560 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/24-terraform-variables-quiz/assignment.md @@ -0,0 +1,20 @@ +--- +slug: terraform-variables-quiz +id: zfhadgfqnggb +type: quiz +title: "\U0001F4DD Quiz 4 - Terraform Variables" +teaser: | + How do Terraform variables get set or overridden? +notes: +- type: text + contents: | + Get ready for another quiz... +answers: +- The environment variable +- The tfvars config file +solution: +- 1 +difficulty: basic +timelimit: 10000 +--- +You have the same variable set in a *.tfvars file and as an environment variable. Which one takes precedence? diff --git a/instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/assignment.md b/instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/assignment.md new file mode 100755 index 00000000..86e63fb2 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/assignment.md @@ -0,0 +1,38 @@ +--- +slug: hcp-terraform-setup +id: 7yst2rh6xarz +type: challenge +title: ☁️ HCP Terraform Setup +teaser: | + HCP Terraform offers unlimited free Terraform state storage for users. Safeguard your state files by storing them remotely in HCP Terraform. +notes: +- type: text + contents: HCP Terraform remote state storage is free for all users. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +During this challenge and the next one, you'll use the remote state feature of HCP Terraform to store your state file in the cloud. In order to do this you'll need a HCP Terraform account. Click on the URL below and sign up for a free account if you don't have one already: + +https://app.terraform.io/signup/account + +If you already have an account you can simply sign in with your existing credentials. + +Once you're signed into HCP Terraform create a new organization called YOURNAME-training. Replace YOURNAME with your own name or other text. + +Next you'll be prompted to create a workspace. You can skip the VCS integration step by clicking the "CLI-driven workflow" panel. Name your workspace **hashicat-aws**. + +**Note:** If you already have a **hashicat-aws** workspace, please delete the workspace by selecting the **Settings >> Destruction and Deletion** menu, clicking the "Delete from HCP Terraform" button, typing "hashicat-aws" to confirm, and then clicking the "Delete workspace" button. Then re-create it as above. Doing this avoids possible problems with mis-matched state versions when executing local runs after having executed remote runs. This could happen if you played the [HCP Terraform with AWS](https://play.instruqt.com/hashicorp/tracks/terraform-cloud-aws) track and then played this track. + +Run `terraform version` on the "Shell" tab and then set the **Terraform Version** to match on the workspace's **Settings >> General** settings page. + +Also, change the **Execution Mode** to **Local**. + +Be sure to save your settings by clicking the "Save settings" button at the bottom of the page! This will allow us to run Terraform commands from our workstation with local variables, which we'll do in the next challenge. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/fun-with-variables/check-workstation b/instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/fun-with-variables/check-workstation rename to instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-cloud-setup/setup-workstation b/instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-cloud-setup/setup-workstation rename to instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-code/solve-workstation b/instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-code/solve-workstation rename to instruqt-tracks/terraform-intro-aws/25-hcp-terraform-setup/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/26-configure-remote-state/assignment.md b/instruqt-tracks/terraform-intro-aws/26-configure-remote-state/assignment.md new file mode 100755 index 00000000..6ab95751 --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/26-configure-remote-state/assignment.md @@ -0,0 +1,57 @@ +--- +slug: configure-remote-state +id: 6zxps7lnohph +type: challenge +title: "\U0001F39B️ Configure Remote State" +teaser: | + The terraform command line tool can store its state in HCP Terraform. All that is required is a user token. +notes: +- type: text + contents: |- + With *local* execution mode the Terraform commands and variables all remain + on your workstation. + + With *remote* execution mode Terraform runs in a HCP Terraform + container environment. All variables must be configured in the cloud environment with this method. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +- title: Credentials File + type: code + hostname: workstation + path: /root/.terraform.d/credentials.tfrc.json +difficulty: basic +timelimit: 10000 +--- +During this challenge we'll configure HCP Terraform as a remote state backend, and then migrate our existing state file to HCP Terraform. + +Edit the "remote_backend.tf" file and replace the YOURORGANIZATION placeholder with your org name. Be sure to save the file. + +Let's generate a new **user token** for use on your workstation. Visit the User Settings > Tokens page in HCP Terraform: + +https://app.terraform.io/app/settings/tokens + +Click on the **Create an API token** button. You can name the token whatever you like. Copy the entire token using your mouse or the small copy-paste icon. + +Back in the Instruqt track, you need to add your API token to a file called "credentials.tfrc.json". Select the "Credentials File" tab and open the `/root/.terraform.d/credentials.tfrc.json` file directly. + +Replace the part that says YOURTOKEN with what you copied from HCP Terraform. Be sure to save the file. + +Your token is now safely stored in the `/root/.terraform.d/credentials.tfrc.json` file. + +Now run `terraform init` to migrate your state to HCP Terraform. + +``` +terraform init +``` + +Type "yes" when it prompts you to migrate your state into HCP Terraform. + +Your state is now safely stored in HCP Terraform. You can verify this on the "States" tab of your workspace in the TFC UI. + +Run a `terraform apply -auto-approve` and watch your state file evolve with each change. You can browse through previous state files with the HCP Terraform UI. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-cloud-setup/check-workstation b/instruqt-tracks/terraform-intro-aws/26-configure-remote-state/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-cloud-setup/check-workstation rename to instruqt-tracks/terraform-intro-aws/26-configure-remote-state/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-plan-and-apply/setup-workstation b/instruqt-tracks/terraform-intro-aws/26-configure-remote-state/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-plan-and-apply/setup-workstation rename to instruqt-tracks/terraform-intro-aws/26-configure-remote-state/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/tf-graph-again/solve-workstation b/instruqt-tracks/terraform-intro-aws/26-configure-remote-state/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/tf-graph-again/solve-workstation rename to instruqt-tracks/terraform-intro-aws/26-configure-remote-state/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/27-terraform-destroy/assignment.md b/instruqt-tracks/terraform-intro-aws/27-terraform-destroy/assignment.md new file mode 100755 index 00000000..f20edaef --- /dev/null +++ b/instruqt-tracks/terraform-intro-aws/27-terraform-destroy/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-destroy +id: zryuudhfezgj +type: challenge +title: "\U0001F525 Terraform Destroy" +teaser: | + Terraform can build infrastructure and also destroy it when you are done using it. This helps control costs and reduce infrastructure sprawl. +notes: +- type: text + contents: |- + Terraform can destroy infrastructure as easily as it can build it. + + Use `terraform destroy` with caution. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-aws +difficulty: basic +timelimit: 10000 +--- +Run the following command to destroy your infrastructure: + +``` +terraform destroy +``` + +You'll need to type "yes" when prompted to destroy your infrastructure. This is a safety feature to help prevent accidental deletion of important resources. + +Wait until the destroy action has completely finished before clicking on the **Check** button. + +Congratulations on completing the Intro to Terraform track! \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-aws/terraform-destroy/check-workstation b/instruqt-tracks/terraform-intro-aws/27-terraform-destroy/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-destroy/check-workstation rename to instruqt-tracks/terraform-intro-aws/27-terraform-destroy/check-workstation diff --git a/instruqt-tracks/terraform-intro-aws/use-a-provisioner/setup-workstation b/instruqt-tracks/terraform-intro-aws/27-terraform-destroy/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/use-a-provisioner/setup-workstation rename to instruqt-tracks/terraform-intro-aws/27-terraform-destroy/setup-workstation diff --git a/instruqt-tracks/terraform-intro-aws/terraform-destroy/solve-workstation b/instruqt-tracks/terraform-intro-aws/27-terraform-destroy/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-aws/terraform-destroy/solve-workstation rename to instruqt-tracks/terraform-intro-aws/27-terraform-destroy/solve-workstation diff --git a/instruqt-tracks/terraform-intro-aws/config.yml b/instruqt-tracks/terraform-intro-aws/config.yml index 82ed55e5..aecc2425 100644 --- a/instruqt-tracks/terraform-intro-aws/config.yml +++ b/instruqt-tracks/terraform-intro-aws/config.yml @@ -1,7 +1,7 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -version: "2" +version: "3" virtualmachines: - name: workstation image: instruqt-hashicorp/ubuntu-2004-base diff --git a/instruqt-tracks/terraform-intro-aws/track.yml b/instruqt-tracks/terraform-intro-aws/track.yml index 1e58f154..0468d1f5 100644 --- a/instruqt-tracks/terraform-intro-aws/track.yml +++ b/instruqt-tracks/terraform-intro-aws/track.yml @@ -1,9 +1,5 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -slug: terraform-intro-aws -id: mxj2yxho4ygy -type: track +slug: wip-vcdl-846-terraform-intro-aws +id: jcykt4xymnwf title: Intro to Terraform on AWS teaser: | Provision the HashiCat application on AWS Cloud using Terraform. @@ -14,1036 +10,23 @@ description: |- Kittens as a Service! icon: https://storage.googleapis.com/instruqt-hashicorp-tracks/logo/terraform.png tags: -- terraform - aws +- terraform - basics -owner: hashicorp +owner: hashicorp-field-ops developers: - sean.carolan@hashicorp.com - roger@hashicorp.com -private: true -published: true +- syed.quadri@hashicorp.com show_timer: true -challenges: -- slug: setup-our-environment - id: e2kiy6cgweb5 - type: challenge - title: "\U0001F3E1 Moving in - Explore Your Workspace" - teaser: | - Explore the Terraform code for the hashicat application. - notes: - - type: text - contents: | - Setting up your environment... - Keep an eye on the bottom right corner to know when you can get started. - - type: text - contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD, - Windows, Solaris and Linux. - - type: text - contents: The Terraform language is designed to be both human and machine-readable. - - type: text - contents: Most modern code editors support Terraform syntax highlighting. - assignment: |- - Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors. - - When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor! - - Throughout this track, please execute all commands on the "Shell" tab. - - Congratulations, you are ready to start working with Terraform on AWS. We'll use the hashicat-aws example app in the rest of the challenges as you learn new Terraform skills. - - Click the **Check** button to continue. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: hello-terraform - id: 3mgjyltxeu46 - type: challenge - title: "\U0001F44B Getting to Know Terraform" - teaser: | - Learn Terraform basics and command line syntax. - notes: - - type: text - contents: |- - Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation. - - It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html - - type: text - contents: |- - Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH. - - Check out this tutorial for step-by-step instructions: - - https://learn.hashicorp.com/terraform/getting-started/install.html - - We've pre-installed Terraform in your Instruqt lab environment for you. - assignment: |- - Let's start with some basic Terraform commands. - Run the following commands on the "Shell" tab. - - Check the version of Terraform running on your machine: - - ``` - terraform version - ``` - - You can always get help if you're curious about command syntax: - - ``` - terraform --help - ``` - - Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation. - - Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: aws-credentials - id: otyfptrkoonl - type: challenge - title: "\U0001F510 Connecting Terraform to AWS" - teaser: | - Connecting to AWS with Access Keys and Secret Keys. - notes: - - type: text - contents: Did you know HCL stands for "HashiCorp Configuration Language"? - assignment: |- - In order to authenticate to AWS and build resources, Terraform requires you to provide a set of credentials, backed by an appropriate IAM policy. - - For this training environment, we have prepared some temporary AWS credentials and stored them as environment variables. Terraform will automatically read and use the environment variables that are configured in your shell environment. - - Run the following commands on the "Shell" tab: - - ``` - echo $AWS_ACCESS_KEY_ID - echo $AWS_SECRET_ACCESS_KEY - ``` - You should see valid AWS keys. If not, return to the track home page by clicking the **Close** button, stop the track, and then restart it. - - *Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: terraform-code - id: duf2nfeyxvtd - type: challenge - title: "\U0001F468‍\U0001F4BB What does Terraform code look like?" - teaser: | - The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure. - notes: - - type: text - contents: |- - Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`. - - By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files. - - You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`. - assignment: |- - We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files: - ``` - ls *.tf - ``` - The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon. - - Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first: - - **main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.
- **variables.tf** - Use this file to define which variables will be available to your users.
- **outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run. - - Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: terraform-init-provider - id: a2oymo1mb9eh - type: challenge - title: "\U0001F3E1 Terraform Init - Install the Providers" - teaser: | - Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers. - notes: - - type: text - contents: |- - The Terraform core program isn't very useful by itself. Terraform needs the help of a *provider* to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here: - - https://registry.terraform.io/browse/providers - - Today we'll be using a few different providers, but the main one is the *aws* provider. - assignment: |- - We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track. - - Before we can do anything with Terraform we need to initialize our workspace. Run the following command in your "Shell" tab: - ``` - terraform init - ``` - - The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them. - - Run the following command to verify that the aws provider was installed under the ".terraform" directory: - - ``` - ls .terraform/providers/registry.terraform.io/hashicorp - ``` - - This hidden directory is where all modules and plugins are stored. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: provider-quiz - id: pbyboywk5jg7 - type: quiz - title: "\U0001F4DD Quiz 1 - Providers and Modules" - teaser: | - A quiz about Terraform init - notes: - - type: text - contents: | - It's quiz time! - assignment: | - Where does Terraform store its modules and providers? - answers: - - In the /tmp directory - - In the user's home directory - - In the .terraform directory - - None of the above - solution: - - 2 - difficulty: basic - timelimit: 1000 -- slug: terraform-validate - id: eqm4fimi2xzb - type: challenge - title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code" - teaser: | - Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly. - notes: - - type: text - contents: Terraform has a built-in syntax checker. You can run it with the `terraform - validate` command. - assignment: |- - Terraform comes with a built-in subcommand called *validate*. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly. - - Edit the main.tf file and remove the double quotes between `aws_vpc` and `hashicat` on line 14 of the file, keeping the space that was between them. Save the file. - - Validate your code: - - ``` - terraform validate - ``` - - Now put the double quotes back in line 14, save the file, and run the validate command again. This time you should pass the validation test. - - `terraform validate` is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: terraform-plan - id: jxmapmlxc4xu - type: challenge - title: "\U0001F914 Terraform Plan - Dry Run Mode" - teaser: | - Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run `terraform plan` and view the output. - notes: - - type: text - contents: |- - `terraform plan` allows you to preview any changes to your environment in a safe way. - - This can help you identify any unexpected changes before you deploy them, not after they are already built. - assignment: |- - Run the `terraform plan` command: - - ``` - terraform plan - ``` - - When you run this command Terraform will prompt you to enter the `prefix` variable. - - Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name. - - The prefix will become part of the name for our VPC, subnet, EC2 instance and other resources. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: terraform-variables - id: etyrybl9jrx2 - type: challenge - title: "\U0001F39B️ Working with Terraform Variables" - teaser: | - Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables. - notes: - - type: text - contents: The `terraform.tfvars` file is a convenient place for users to configure - their variables. - assignment: |- - In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later. - - Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case). - - **Be sure to click the disk icon above the file to save your change!** - - Now run `terraform plan` again. This time you won't have to enter your prefix manually. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: terraform-add-a-variable - id: 0etxzjuyyjej - type: challenge - title: "\U0001F5FC Change Your Location" - teaser: | - Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable. - notes: - - type: text - contents: |- - You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file. - - In this challenge, you will pick the location where your AWS resources should be deployed. - assignment: |- - In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set another variable that will determine the location where your AWS infrastructure will be deployed. - - First run another plan so you'll be able to compare what happens after you change the location. - - ``` - terraform plan - ``` - - Choose an AWS region near you but different from the default one which is "us-east-1". Add a `region` variable to your "terraform.tfvars" file, setting it to your desired region such as `us-west-1`, `eu-west-2`, or `ap-southeast-1`. - - See this [page](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) for a list of valid AWS regions. - - Choosing a region close to you can help improve speed and performance. - - **Be sure to click the disk icon above the file to save your change!** - - Once you've set your `region` variable, try running `terraform plan` again. What's different this time? - - Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: variables-quiz - id: fg979clmuhnf - type: quiz - title: "\U0001F4DD Quiz 2 - Variables" - teaser: | - A quiz about Terraform variables - notes: - - type: text - contents: | - Another quiz, get ready! - assignment: | - Where are terraform variables usually *declared*? - answers: - - On the command line - - As environment variables - - In the variables.tf file - - In the terraform.tfvars file - solution: - - 2 - difficulty: basic - timelimit: 1000 -- slug: tf-graph - id: gjzkyckui1qs - type: challenge - title: "\U0001F4C8 Terraform Graph" - teaser: | - Terraform creates a graph of all the infrastructure defined in your code. - notes: - - type: text - contents: Terraform Graph can provide a visual representation of all your infrastructure. - This is handy for finding dependency issues or resources that will be affected - by a change. - assignment: |- - Try running the `terraform graph` command: - - ``` - terraform graph - ``` - - This generates code that can be used to create a visual map of your infrastructure. The graph data is in [DOT graph description language format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). There are several graphing tools you can use to visualize this data, including the free Blast Radius tool. You can learn more about Blast Radius here: - - https://28mm.github.io/blast-radius-docs/ - - Start up a Blast Radius server with the following command: - - ``` - blast-radius --serve . - ``` - - Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) - - Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. - - **NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. - - Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Terraform Graph - type: service - hostname: workstation - port: 5000 - difficulty: basic - timelimit: 1000 -- slug: tf-plan-and-apply - id: tmcnfjqerhjn - type: challenge - title: "\U0001F468‍\U0001F4BB Terraform Plan and Terraform Apply" - teaser: | - The `terraform plan` command can be run anytime to get a preview of changes that Terraform might make. When you run Terraform apply these changes are implemented, and Terraform builds, updates, or destroys resources. - notes: - - type: text - contents: |- - By default, the `terraform apply` command runs a Terraform plan to show you what changes it wants to make. - - Terraform maps out all the changes it needs to make before applying them. - assignment: |- - Now that we've configured our required variables we can apply our changes. - - Run the `terraform plan` command first to see what will happen: - - ``` - terraform plan - ``` - Confirm the proper prefix and location are displayed in the plan output. - - Then run `terraform apply` and watch your resources being built. - - ``` - terraform apply - ``` - - You'll need to enter **yes** when Terraform prompts you with the "Do you want to perform these actions?" question. - - Right now our code only defines a VPC. We'll be building upon this starting point in the next challenge. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: tf-plan-again - id: zjg4qligpxmr - type: challenge - title: "\U0001F469‍\U0001F4BB Test and Repair" - teaser: | - Terraform is idempotent. Each resource in your code will be examined, and if it already exists Terraform will leave it alone. - notes: - - type: text - contents: |- - Terraform is an *idempotent* application. - - Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. - - https://en.wikipedia.org/wiki/Idempotence - assignment: |- - Try running `terraform plan` again and see what happens: - - ``` - terraform plan - ``` - - Since your VPC has already been built, Terraform will report that there are no changes required. - - This is normal and expected. - - Now try running another apply: - - ``` - terraform apply - ``` - - Terraform checks each resource to ensure it is in the proper state. It will not re-create your VPC if it is already provisioned correctly. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: change-prefix - id: 4taa0qxk0qpq - type: challenge - title: "\U0001F6EB Change Your Prefix" - teaser: | - When your Terraform code changes, your infrastructure will be modified to match the updated code. Terraform is a declarative language. - notes: - - type: text - contents: |- - Terraform can create, destroy, update in place, or destroy and re-create your infrastructure. Some types of resources can be updated without deleting them. Major changes usually require a teardown and rebuild. - - Terraform always tries to match the current infrastructure to what has been defined in your code. - assignment: |- - Edit the `terraform.tfvars` file to change your prefix. You could simply add a number to the end if you like. Or change it to something entirely new. - - Save the `terraform.tfvars` file and run your apply command again. - - ``` - terraform apply - ``` - - Type "yes" when prompted. - - Observe the output. What happened? - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: add-a-tag - id: 1vrdile3jhtx - type: challenge - title: "\U0001F3F7️ Add a Tag to Your VPC" - teaser: | - Terraform can change some resources in in place without deleting them. Adding tags is a non-destructive action. - notes: - - type: text - contents: Adding, changing, or removing tags is a non-destructive action. Terraform - can tag your resources without re-creating them. - assignment: |- - Several resource types support AWS's tags. Read the Terraform documentation for the `aws_vpc` resource to learn about the `tags` argument and its format. - - [Terraform Docs: the aws_vpc resource - Click Here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc) - - Add a tag to your VPC resource in the **main.tf** file. The name of the tag should be `environment` and the value should be `Production`. (The tag is case-sensitive. Make sure you use a capital P.) - - Hint: Read the examples carefully! Unlike the other resource arguments you've seen, the value of the `tags` argument must be a **map** (a `{key = "value"}` data structure). Additionally, you must use `=` after `tags` and after `environment`. For more about Terraform's data types, see the [Terraform language documentation](https://www.terraform.io/docs/configuration/expressions.html#types-and-values). - - Re-run `terraform apply` and answer "yes" when prompted. - - What happens? - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: add-virtual-network - id: apdyj8oi7xve - type: challenge - title: "\U0001F5A7 Add a Virtual Network" - teaser: | - Terraform resources are like building blocks. You can continue adding more blocks until your infrastructure reaches the desired state. - notes: - - type: text - contents: Terraform code can be built incrementally, one or two resources at a - time. - assignment: |- - Open the **main.tf** file again and uncomment the next resource block in the file. The type of resource is **aws_subnet** and it is named **hashicat**. - - Uncomment the code by removing the `#` characters from the beginning of each line. Be sure to save the file. - - Now run `terraform apply` again and answer "yes" when prompted. Observe the results. - - Look at the **vpc_id** parameter inside the aws_subnet resource. See how it points back at the first resource in the file? The subnet resource inherits settings from the VPC. - - Terraform can map out the complex web of dependencies between hundreds of interconnected resources. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: complete-the-build - id: ig96derdd8oc - type: challenge - title: "\U0001F3D7️ Complete the Build" - teaser: | - Terraform code can stand up everything from VPCs, to virtual networks, to VMs and containers. - notes: - - type: text - contents: The `-auto-approve` flag can be used to override the "Are you sure?" - questions that appear before an apply or destroy. Use with caution! - assignment: |- - We've uncommented all the rest of the Terraform code in the **main.tf** file for you. Run a `terraform plan` to see what will be built: - - ``` - terraform plan - ``` - - Now run an apply to build the HashiCat application: - - ``` - terraform apply -auto-approve - ``` - - It can take up to five minutes for the application to finish deploying. You will know it is complete when you see the Terraform output with your application URL at the end of the run. - - If the application won't load just run `terraform apply` again. This will attempt to reinstall the webserver and start your application if it's not running. - - Open your web application in a new browser tab by clicking on the URL in the `catapp_url` output. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: tf-graph-again - id: acjsqgigx2gb - type: challenge - title: "\U0001F4C8 Terraform Graph" - teaser: | - Revisit graph to see what has changed. - notes: - - type: text - contents: Let's revisit our graph to see what has changed. - assignment: |- - Start up a Blast Radius server with the following command: - - ``` - blast-radius --serve . - ``` - - Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) - - Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. - - **NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. - - Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Terraform Graph - type: service - hostname: workstation - port: 5000 - difficulty: basic - timelimit: 1000 -- slug: terraform-apply-quiz - id: ujt4uqcg6rhu - type: quiz - title: "\U0001F4DD Quiz 3 - Terraform Apply" - teaser: | - What happens when you run `terraform apply` without a plan file? - notes: - - type: text - contents: | - It's quiz time! - assignment: | - What happens when you run `terraform apply` without specifying a plan file? - answers: - - Terraform runs without any plan - - Terraform reads the previous plan and then applies it - - Terraform runs a new plan right before the apply - - None of the above - solution: - - 2 - difficulty: basic - timelimit: 1000 -- slug: use-a-provisioner - id: p8kqkeclltim - type: challenge - title: "\U0001F6E0️ Use a Provisioner" - teaser: | - Terraform works great with many different provisioning tools including Chef, Puppet, Ansible, Bash, and Powershell. - notes: - - type: text - contents: Terraform provisioners run once at creation time. They do not run on - subsequent applies, except in special circumstances. (Like this training lab...) - - type: text - contents: We've made some special adjustments to force the provisioner to run - every time you type terraform apply. This is so you can practice playing with - provisioners without destroying and recreating your virtual machine every time - you make a change. - - type: text - contents: |- - ``` - ______________________ - < Cows love Terraform! > - ---------------------- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || - ============================= - ``` - assignment: |- - Open the `main.tf` file on the "Code Editor" tab. Scroll down until you find the `remote-exec` provisioner block. - - Add the following two lines at the end of the inline list of commands: - - ``` - "sudo apt -y install cowsay", - "cowsay Mooooooooooo!", - ``` - - After copying them into your buffer, it will be easier to paste them if you hide the assignment by clicking the ">" icon . Click it again to redisplay the assignment. Be sure to save the file. - - This might be a good time to use the `terraform fmt` command to line up the commands nicely. - - Now apply your changes: - - ``` - terraform apply -auto-approve - ``` - - Scroll back through the log output. You should see an ASCII art cow saying "Moooooooo!" - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: add-an-output - id: rn7ke6dr2oij - type: challenge - title: "\U0001F5A8️ Add an Output" - teaser: | - Outputs are used to convey useful information such as IP addresses, application URLs or other useful data. - notes: - - type: text - contents: You can mix plain text along with Terraform data in your outputs. Outputs - can be used to convey useful information to your users at the end of a run. - - type: text - contents: The `terraform refresh` command will sync your state file with what - exists in your infrastructure. A refresh command will not change your infrastructure. - - type: text - contents: The `terraform output` command can be run any time you want to see your - Terraform outputs again. Run `terraform output ` to view a single - output. - assignment: |- - Open the **outputs.tf** file on the "Code Editor" tab. Note the public_dns output in the file. - - Add a second output for the `public_ip` of your web server. It's going to look almost exactly like the first output but will instead output an IP address instead of a DNS name. - - Name your output `catapp_ip`. - - You may refer to the docs page to see what types of outputs are valid: - - [Terraform AWS Docs - Click Here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#attributes-reference) - [Terraform Outputs Docs - Click Here](https://www.terraform.io/docs/configuration/outputs.html) - - Be sure to save the changes to the **outputs.tf** file. - - Run the Terraform refresh command to view your new output: - - ``` - terraform refresh - ``` - - You can run the Terraform output command to view all your outputs: - - ``` - terraform output - ``` - - You can click on either URL to use the web app. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: fun-with-variables - id: 3wzirlxydsu5 - type: challenge - title: "\U0001F436 Fun With Variables" - teaser: | - Variables give the consumers of your Terraform code an easy way to customize their infrastructure. - notes: - - type: text - contents: |- - Terraform variables have five levels of precedence. 1=highest 5=lowest: - - 1. Command line flag - run as a command line switch - 1. Configuration file - set in your terraform.tfvars file - 1. Environment variable - part of your shell environment - 1. Default Config - default value in variables.tf - 1. User manual entry - if not specified, prompt the user for entry - - type: text - contents: |- - Here are some other fun placeholder sites you can try with the **placeholder** variable: - - placedog.net
- placebear.com
- www.fillmurray.com
- www.placecage.com
- placebeard.it
- loremflickr.com
- baconmockup.com
- placeimg.com
- assignment: |- - There are several ways to configure Terraform variables. So far we've been using the `terraform.tfvars` file to set our variables. Try re-deploying your application with different **height** and **width** variables on the command line. Reload the webapp after each apply to observe any changes. - - ``` - terraform apply -auto-approve -var height=600 -var width=800 - ``` - - Next try setting an environment variable that Terraform can read. Run this command to set the placeholder variable: - - ``` - export TF_VAR_placeholder=placedog.net - ``` - - Run another `terraform apply -auto-approve` command: - - ``` - terraform apply -auto-approve - ``` - - Now try it again with the same variable set differently on the command line: - - ``` - terraform apply -auto-approve -var placeholder=placebear.com - ``` - - Which variable took precedence? Why? - - See this [doc](https://www.terraform.io/docs/configuration/variables.html#variable-definition-precedence) if you're unsure. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: terraform-variables-quiz - id: wu4ccjgdibjc - type: quiz - title: "\U0001F4DD Quiz 4 - Terraform Variables" - teaser: | - How do Terraform variables get set or overridden? - notes: - - type: text - contents: | - Get ready for another quiz... - assignment: | - You have the same variable set in a *.tfvars file and as an environment variable. Which one takes precedence? - answers: - - The environment variable - - The tfvars config file - solution: - - 1 - difficulty: basic - timelimit: 1000 -- slug: hcp-terraform-setup - id: jlx3zubmjrid - type: challenge - title: ☁️ HCP Terraform Setup - teaser: | - HCP Terraform offers unlimited free Terraform state storage for users. Safeguard your state files by storing them remotely in HCP Terraform. - notes: - - type: text - contents: HCP Terraform remote state storage is free for all users. - assignment: |- - During this challenge and the next one, you'll use the remote state feature of HCP Terraform to store your state file in the cloud. In order to do this you'll need a HCP Terraform account. Click on the URL below and sign up for a free account if you don't have one already: - - https://app.terraform.io/signup/account - - If you already have an account you can simply sign in with your existing credentials. - - Once you're signed into HCP Terraform create a new organization called YOURNAME-training. Replace YOURNAME with your own name or other text. - - Next you'll be prompted to create a workspace. You can skip the VCS integration step by clicking the "CLI-driven workflow" panel. Name your workspace **hashicat-aws**. - - **Note:** If you already have a **hashicat-aws** workspace, please delete the workspace by selecting the **Settings >> Destruction and Deletion** menu, clicking the "Delete from HCP Terraform" button, typing "hashicat-aws" to confirm, and then clicking the "Delete workspace" button. Then re-create it as above. Doing this avoids possible problems with mis-matched state versions when executing local runs after having executed remote runs. This could happen if you played the [HCP Terraform with AWS](https://play.instruqt.com/hashicorp/tracks/terraform-cloud-aws) track and then played this track. - - Run `terraform version` on the "Shell" tab and then set the **Terraform Version** to match on the workspace's **Settings >> General** settings page. - - Also, change the **Execution Mode** to **Local**. - - Be sure to save your settings by clicking the "Save settings" button at the bottom of the page! This will allow us to run Terraform commands from our workstation with local variables, which we'll do in the next challenge. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -- slug: configure-remote-state - id: aa8drk1l6e1e - type: challenge - title: "\U0001F39B️ Configure Remote State" - teaser: | - The terraform command line tool can store its state in HCP Terraform. All that is required is a user token. - notes: - - type: text - contents: |- - With *local* execution mode the Terraform commands and variables all remain - on your workstation. - - With *remote* execution mode Terraform runs in a HCP Terraform - container environment. All variables must be configured in the cloud environment with this method. - assignment: |- - During this challenge we'll configure HCP Terraform as a remote state backend, and then migrate our existing state file to HCP Terraform. - - Edit the "remote_backend.tf" file and replace the YOURORGANIZATION placeholder with your org name. Be sure to save the file. - - Let's generate a new **user token** for use on your workstation. Visit the User Settings > Tokens page in HCP Terraform: - - https://app.terraform.io/app/settings/tokens - - Click on the **Create an API token** button. You can name the token whatever you like. Copy the entire token using your mouse or the small copy-paste icon. - - Back in the Instruqt track, you need to add your API token to a file called "credentials.tfrc.json". Select the "Credentials File" tab and open the `/root/.terraform.d/credentials.tfrc.json` file directly. - - Replace the part that says YOURTOKEN with what you copied from HCP Terraform. Be sure to save the file. - - Your token is now safely stored in the `/root/.terraform.d/credentials.tfrc.json` file. - - Now run `terraform init` to migrate your state to HCP Terraform. - - ``` - terraform init - ``` - - Type "yes" when it prompts you to migrate your state into HCP Terraform. - - Your state is now safely stored in HCP Terraform. You can verify this on the "States" tab of your workspace in the TFC UI. - - Run a `terraform apply -auto-approve` and watch your state file evolve with each change. You can browse through previous state files with the HCP Terraform UI. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - - title: Credentials File - type: code - hostname: workstation - path: /root/.terraform.d/credentials.tfrc.json - difficulty: basic - timelimit: 1000 -- slug: terraform-destroy - id: uej56ttohwuv - type: challenge - title: "\U0001F525 Terraform Destroy" - teaser: | - Terraform can build infrastructure and also destroy it when you are done using it. This helps control costs and reduce infrastructure sprawl. - notes: - - type: text - contents: |- - Terraform can destroy infrastructure as easily as it can build it. - - Use `terraform destroy` with caution. - assignment: |- - Run the following command to destroy your infrastructure: - - ``` - terraform destroy - ``` - - You'll need to type "yes" when prompted to destroy your infrastructure. This is a safety feature to help prevent accidental deletion of important resources. - - Wait until the destroy action has completely finished before clicking on the **Check** button. - - Congratulations on completing the Intro to Terraform track! - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-aws - difficulty: basic - timelimit: 1000 -checksum: "190704902276224425" +idle_timeout: 7200 +timelimit: 14400 +lab_config: + overlay: false + width: 33 + position: right + sidebar_enabled: true + feedback_recap_enabled: true + loadingMessages: true + hideStopButton: false +checksum: "5050346962910484889" diff --git a/instruqt-tracks/terraform-intro-azure/01-setup-our-environment/assignment.md b/instruqt-tracks/terraform-intro-azure/01-setup-our-environment/assignment.md new file mode 100755 index 00000000..111d033c --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/01-setup-our-environment/assignment.md @@ -0,0 +1,39 @@ +--- +slug: setup-our-environment +id: erun28lc0cgi +type: challenge +title: Moving in - Explore Your Workspace +teaser: | + Explore the Terraform code for the hashicat application. +notes: +- type: text + contents: | + Setting up your environment... + Keep an eye on the bottom right corner to know when you can get started. +- type: text + contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD, + Windows, Solaris and Linux. +- type: text + contents: The Terraform language is designed to be both human and machine-readable. +- type: text + contents: Most modern code editors support Terraform syntax highlighting. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors. + +When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor! + +Throughout this track, please execute all commands on the "Shell" tab. + +Congratulations, you are ready to start working with Terraform on Azure. We'll use the hashicat-azure example app in the rest of the challenges as you learn new Terraform skills. + +Click the **Check** button to continue. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/setup-our-environment/check-workstation b/instruqt-tracks/terraform-intro-azure/01-setup-our-environment/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/setup-our-environment/check-workstation rename to instruqt-tracks/terraform-intro-azure/01-setup-our-environment/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/setup-our-environment/setup-workstation b/instruqt-tracks/terraform-intro-azure/01-setup-our-environment/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/setup-our-environment/setup-workstation rename to instruqt-tracks/terraform-intro-azure/01-setup-our-environment/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/setup-our-environment/solve-workstation b/instruqt-tracks/terraform-intro-azure/01-setup-our-environment/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/setup-our-environment/solve-workstation rename to instruqt-tracks/terraform-intro-azure/01-setup-our-environment/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/02-hello-terraform/assignment.md b/instruqt-tracks/terraform-intro-azure/02-hello-terraform/assignment.md new file mode 100755 index 00000000..30fefb70 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/02-hello-terraform/assignment.md @@ -0,0 +1,51 @@ +--- +slug: hello-terraform +id: xnar3nai5z5l +type: challenge +title: Getting to Know Terraform +teaser: | + Learn Terraform basics and command line syntax. +notes: +- type: text + contents: |- + Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation. + + It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html +- type: text + contents: |- + Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH. + + Check out this tutorial for step-by-step instructions: + + https://learn.hashicorp.com/terraform/getting-started/install.html + + We've pre-installed Terraform in your Instruqt lab environment for you. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 106700 +--- +Let's start with some basic Terraform commands. +Run the following commands on the "Shell" tab. + +Check the version of Terraform running on your machine: + +``` +terraform version +``` + +You can always get help if you're curious about command syntax: + +``` +terraform --help +``` + +Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation. Terraform is also pre-installed in Azure Cloud Shell. + +Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/hello-terraform/check-workstation b/instruqt-tracks/terraform-intro-azure/02-hello-terraform/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/hello-terraform/check-workstation rename to instruqt-tracks/terraform-intro-azure/02-hello-terraform/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/add-a-tag/setup-workstation b/instruqt-tracks/terraform-intro-azure/02-hello-terraform/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-a-tag/setup-workstation rename to instruqt-tracks/terraform-intro-azure/02-hello-terraform/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/hello-terraform/solve-workstation b/instruqt-tracks/terraform-intro-azure/02-hello-terraform/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/hello-terraform/solve-workstation rename to instruqt-tracks/terraform-intro-azure/02-hello-terraform/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/03-azure-credentials/assignment.md b/instruqt-tracks/terraform-intro-azure/03-azure-credentials/assignment.md new file mode 100755 index 00000000..cca8bead --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/03-azure-credentials/assignment.md @@ -0,0 +1,40 @@ +--- +slug: azure-credentials +id: v23bafxcbbi2 +type: challenge +title: Connecting Terraform to Azure Cloud +teaser: | + Safely connect to the Azure APIs using a service principal. +notes: +- type: text + contents: |- + Microsoft has a great tutorial for setting up Azure credentials on your laptop or virtual workstation: + https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure +- type: text + contents: |- + Azure Cloud Shell is another easy way to get started with Terraform. With Azure Cloud Shell, Terraform is pre-installed and ready to go. + https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure#use-azure-cloud-shell +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Terraform needs credentials to be able to connect to Azure and build resources. + +We've pre-installed some temporary credentials in your Instruqt training environment. These credentials are stored as environment variables. You should never store sensitive API keys inside your source code. + +Terraform can automatically read and use the environment variables that are in your shell environment. + +Run the following command on your "Shell" tab to see your temporary credentials: +``` +env | grep ARM_CLIENT +``` +You should see valid Azure credentials. If not, return to the track home page by clicking the **Close** button, stop the track, and then restart it. + +*Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/azure-credentials/check-workstation b/instruqt-tracks/terraform-intro-azure/03-azure-credentials/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/azure-credentials/check-workstation rename to instruqt-tracks/terraform-intro-azure/03-azure-credentials/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/add-an-output/setup-workstation b/instruqt-tracks/terraform-intro-azure/03-azure-credentials/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-an-output/setup-workstation rename to instruqt-tracks/terraform-intro-azure/03-azure-credentials/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/azure-credentials/solve-workstation b/instruqt-tracks/terraform-intro-azure/03-azure-credentials/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/azure-credentials/solve-workstation rename to instruqt-tracks/terraform-intro-azure/03-azure-credentials/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/04-terraform-code/assignment.md b/instruqt-tracks/terraform-intro-azure/04-terraform-code/assignment.md new file mode 100755 index 00000000..fa811fdb --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/04-terraform-code/assignment.md @@ -0,0 +1,39 @@ +--- +slug: terraform-code +id: ebawz69ogecl +type: challenge +title: "\U0001F468‍\U0001F4BB What does Terraform code look like?" +teaser: | + The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure. +notes: +- type: text + contents: |- + Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`. + + By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files. + + You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files: +``` +ls *.tf +``` +The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon. + +Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first: + +**main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.
+**variables.tf** - Use this file to define which variables will be available to your users.
+**outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run. + +Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-code/check-workstation b/instruqt-tracks/terraform-intro-azure/04-terraform-code/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-code/check-workstation rename to instruqt-tracks/terraform-intro-azure/04-terraform-code/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/add-virtual-network/setup-workstation b/instruqt-tracks/terraform-intro-azure/04-terraform-code/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-virtual-network/setup-workstation rename to instruqt-tracks/terraform-intro-azure/04-terraform-code/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/configure-remote-state/solve-workstation b/instruqt-tracks/terraform-intro-azure/04-terraform-code/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/configure-remote-state/solve-workstation rename to instruqt-tracks/terraform-intro-azure/04-terraform-code/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/assignment.md b/instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/assignment.md new file mode 100755 index 00000000..1e4f31dc --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/assignment.md @@ -0,0 +1,39 @@ +--- +slug: terraform-init-provider +id: dl5lggdlau7w +type: challenge +title: ☁️ Terraform Init - Install the Azure Provider +teaser: | + Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers. +notes: +- type: text + contents: |- + The Terraform core program isn't very useful by itself. Terraform needs the help of a **provider** to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here: + + https://registry.terraform.io/browse/providers + + Today we'll be using the **azurerm** provider. AzureRM stands for Azure Resource Manager. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track. + +Before we can do anything with Terraform we need to initialize our workspace. Run the following command in your "Shell" tab: +``` +terraform init +``` +The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them. + +Run the following command to verify that the azurerm provider was installed under the ".terraform" directory:: +``` +ls .terraform/providers/registry.terraform.io/hashicorp +``` +This hidden directory is where all modules and plugins are stored. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-init-provider/check-workstation b/instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-init-provider/check-workstation rename to instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/azure-credentials/setup-workstation b/instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/azure-credentials/setup-workstation rename to instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-init-provider/solve-workstation b/instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-init-provider/solve-workstation rename to instruqt-tracks/terraform-intro-azure/05-terraform-init-provider/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/06-provider-quiz/assignment.md b/instruqt-tracks/terraform-intro-azure/06-provider-quiz/assignment.md new file mode 100755 index 00000000..83a7d4c9 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/06-provider-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: provider-quiz +id: ghubb2efccqe +type: quiz +title: "\U0001F4DD Quiz 1 - Providers and Modules" +teaser: | + A quiz about Terraform init +notes: +- type: text + contents: | + It's quiz time! +answers: +- In the /tmp directory +- In the user's home directory +- In the .terraform directory +- None of the above +solution: +- 2 +difficulty: basic +timelimit: 10670 +--- +Where does Terraform store its modules and providers? diff --git a/instruqt-tracks/terraform-intro-azure/07-terraform-validate/assignment.md b/instruqt-tracks/terraform-intro-azure/07-terraform-validate/assignment.md new file mode 100755 index 00000000..1ef2d352 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/07-terraform-validate/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-validate +id: ql7s3lt7czlt +type: challenge +title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code" +teaser: | + Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly. +notes: +- type: text + contents: Terraform has a built-in syntax checker. You can run it with the `terraform + validate` command. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Terraform comes with a built-in subcommand called **validate**. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly. + +Edit the main.tf file and remove the double quotes between `azurerm_resource_group` and `myresourcegroup` on line 14 of the file, keeping the space that was between them. Save the file. + +Validate your code: + +``` +terraform validate +``` + +Now put the double quotes back in line 14, save the file, and run the validate command again. This time you should pass the validation test. + +**terraform validate** is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-validate/check-workstation b/instruqt-tracks/terraform-intro-azure/07-terraform-validate/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-validate/check-workstation rename to instruqt-tracks/terraform-intro-azure/07-terraform-validate/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/change-prefix/setup-workstation b/instruqt-tracks/terraform-intro-azure/07-terraform-validate/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/change-prefix/setup-workstation rename to instruqt-tracks/terraform-intro-azure/07-terraform-validate/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-validate/solve-workstation b/instruqt-tracks/terraform-intro-azure/07-terraform-validate/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-validate/solve-workstation rename to instruqt-tracks/terraform-intro-azure/07-terraform-validate/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/08-terraform-plan/assignment.md b/instruqt-tracks/terraform-intro-azure/08-terraform-plan/assignment.md new file mode 100755 index 00000000..7ffc0847 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/08-terraform-plan/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-plan +id: 8p4sbkkwvinj +type: challenge +title: "\U0001F914 Terraform Plan - Dry Run Mode" +teaser: | + Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run Terraform plan and view the output. +notes: +- type: text + contents: |- + `terraform plan` allows you to preview any changes to your environment in a safe way. + + This can help you identify any unexpected changes before you deploy them, not after they are already built. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Run the **terraform plan** command: +``` +terraform plan +``` +When you run this command Terraform will prompt you to enter the `prefix` variable. + +Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name. + +**Keep your prefix string all lower case, and between 5-12 characters long. Do not use an underscore in your prefix.** + +The prefix will become part of your application hostname, and therefore must be DNS-compliant. Valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, and the hyphen (-). A hostname may not start with a hyphen. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-plan/check-workstation b/instruqt-tracks/terraform-intro-azure/08-terraform-plan/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-plan/check-workstation rename to instruqt-tracks/terraform-intro-azure/08-terraform-plan/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/configure-remote-state/setup-workstation b/instruqt-tracks/terraform-intro-azure/08-terraform-plan/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/configure-remote-state/setup-workstation rename to instruqt-tracks/terraform-intro-azure/08-terraform-plan/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-plan/solve-workstation b/instruqt-tracks/terraform-intro-azure/08-terraform-plan/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-plan/solve-workstation rename to instruqt-tracks/terraform-intro-azure/08-terraform-plan/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/09-terraform-variables/assignment.md b/instruqt-tracks/terraform-intro-azure/09-terraform-variables/assignment.md new file mode 100755 index 00000000..f6fe6326 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/09-terraform-variables/assignment.md @@ -0,0 +1,29 @@ +--- +slug: terraform-variables +id: zk0uf2fwq5ov +type: challenge +title: "\U0001F39B️ Working with Terraform Variables" +teaser: | + Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables. +notes: +- type: text + contents: The `terraform.tfvars` file is a convenient place for users to configure + their variables. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later. + +Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case). + +**Be sure to click the disk icon above the file to save your change!** + +Now run `terraform plan` again. This time you won't have to enter your prefix manually. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-variables/check-workstation b/instruqt-tracks/terraform-intro-azure/09-terraform-variables/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-variables/check-workstation rename to instruqt-tracks/terraform-intro-azure/09-terraform-variables/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/fun-with-variables/setup-workstation b/instruqt-tracks/terraform-intro-azure/09-terraform-variables/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/fun-with-variables/setup-workstation rename to instruqt-tracks/terraform-intro-azure/09-terraform-variables/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-variables/solve-workstation b/instruqt-tracks/terraform-intro-azure/09-terraform-variables/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-variables/solve-workstation rename to instruqt-tracks/terraform-intro-azure/09-terraform-variables/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/assignment.md b/instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/assignment.md new file mode 100755 index 00000000..b3fb8c41 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/assignment.md @@ -0,0 +1,45 @@ +--- +slug: terraform-add-a-variable +id: fphpygshh3gq +type: challenge +title: "\U0001F5FC Change Your Location" +teaser: | + Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable. +notes: +- type: text + contents: |- + You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file. + + In this challenge, you will pick the location where your Azure resources should be deployed. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set another variable that will determine the location where your Azure infrastructure will be deployed. + +First run another plan so you'll be able to compare what happens after you change the location. + +``` +terraform plan +``` + +Choose an Azure location near to you but different from the default one which is "eastus". Add a `location` variable to your "terraform.tfvars" file, setting it to your desired location such as `East US`, `UK South`, or `Southeast Asia`. You can also use shorter names like `eastus`, `uksouth`, or `southeastasia`; in fact, Terraform will convert the longer names with spaces to the shorter names without them. + +See this [page](https://azure.microsoft.com/en-us/global-infrastructure/geographies/) for a list of valid Azure locations (which shows the longer names with spaces). + +Choosing a location close to you can help improve speed and performance. + +(**Note that not all Azure regions support all VM types**; if you get an error about the SKU failing because of capacity restrictions when you run the Terraform commands below, try changing to a different region.) + +**Be sure to click the disk icon above the file to save your change!** + +Once you've set your location variable try running `terraform plan` again. What's different this time? + +Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-add-a-variable/check-workstation b/instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-add-a-variable/check-workstation rename to instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/hello-terraform/setup-workstation b/instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/hello-terraform/setup-workstation rename to instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-add-a-variable/solve-workstation b/instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-add-a-variable/solve-workstation rename to instruqt-tracks/terraform-intro-azure/10-terraform-add-a-variable/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/11-variables-quiz/assignment.md b/instruqt-tracks/terraform-intro-azure/11-variables-quiz/assignment.md new file mode 100755 index 00000000..5abf40c3 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/11-variables-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: variables-quiz +id: 84pwqaghg6d3 +type: quiz +title: "\U0001F4DD Quiz 2 - Variables" +teaser: | + A quiz about Terraform variables +notes: +- type: text + contents: | + Another quiz, get ready! +answers: +- On the command line +- As environment variables +- In the variables.tf file +- In the terraform.tfvars file +solution: +- 2 +difficulty: basic +timelimit: 10670 +--- +Where are terraform variables usually *declared*? diff --git a/instruqt-tracks/terraform-intro-azure/12-tf-graph/assignment.md b/instruqt-tracks/terraform-intro-azure/12-tf-graph/assignment.md new file mode 100755 index 00000000..53b1a8d6 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/12-tf-graph/assignment.md @@ -0,0 +1,46 @@ +--- +slug: tf-graph +id: 1vwn6qdcabyo +type: challenge +title: "\U0001F4C8 Terraform Graph" +teaser: | + Terraform creates a graph of all the infrastructure defined in your code. +notes: +- type: text + contents: Terraform Graph can provide a visual representation of all your infrastructure. + This is handy for finding dependency issues or resources that will be affected + by a change. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Terraform Graph + type: service + hostname: workstation + port: 5000 +difficulty: basic +timelimit: 10670 +--- +Try running the `terraform graph` command: + +``` +terraform graph +``` + +This generates code that can be used to create a visual map of your infrastructure. The graph data is in [DOT graph description language format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). There are several graphing tools you can use to visualize this data, including the free Blast Radius tool. You can learn more about Blast Radius here: + +https://28mm.github.io/blast-radius-docs/ + +Start up a Blast Radius server with the following command: + +``` +blast-radius --serve . +``` + +Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) + +Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. + +**NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. + +Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph/check-workstation b/instruqt-tracks/terraform-intro-azure/12-tf-graph/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph/check-workstation rename to instruqt-tracks/terraform-intro-azure/12-tf-graph/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph/cleanup-workstation b/instruqt-tracks/terraform-intro-azure/12-tf-graph/cleanup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph/cleanup-workstation rename to instruqt-tracks/terraform-intro-azure/12-tf-graph/cleanup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-add-a-variable/setup-workstation b/instruqt-tracks/terraform-intro-azure/12-tf-graph/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-add-a-variable/setup-workstation rename to instruqt-tracks/terraform-intro-azure/12-tf-graph/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph/solve-workstation b/instruqt-tracks/terraform-intro-azure/12-tf-graph/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph/solve-workstation rename to instruqt-tracks/terraform-intro-azure/12-tf-graph/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/assignment.md b/instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/assignment.md new file mode 100755 index 00000000..7a94417c --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/assignment.md @@ -0,0 +1,42 @@ +--- +slug: tf-plan-and-apply +id: hy0vbzbpngji +type: challenge +title: "\U0001F468‍\U0001F4BB Terraform Plan and Terraform Apply" +teaser: | + The terraform plan command can be run anytime to get a preview of changes that Terraform might make. When you run terraform apply these changes are implemented, and Terraform builds, updates, or destroys resources. +notes: +- type: text + contents: |- + By default, the `terraform apply` command runs a Terraform plan to show you what changes it wants to make. + + Terraform maps out all the changes it needs to make before applying them. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Now that we've configured our required variables we can apply our changes. + +Run the `terraform plan` command first to see what will happen: + +``` +terraform plan +``` +Confirm the proper prefix and location are displayed in the plan output. + +Then run *terraform apply* and watch your resource group being built. + +``` +terraform apply +``` + +You'll need to enter *yes* when Terraform prompts you with the "Do you want to perform these actions?" question. + +Right now our code only defines a single Azure resource group. We'll be building upon this starting point in the next challenge. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/tf-plan-and-apply/check-workstation b/instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-plan-and-apply/check-workstation rename to instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-code/setup-workstation b/instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-code/setup-workstation rename to instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-plan-and-apply/solve-workstation b/instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-plan-and-apply/solve-workstation rename to instruqt-tracks/terraform-intro-azure/13-tf-plan-and-apply/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/14-tf-plan-again/assignment.md b/instruqt-tracks/terraform-intro-azure/14-tf-plan-again/assignment.md new file mode 100755 index 00000000..f7369f63 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/14-tf-plan-again/assignment.md @@ -0,0 +1,43 @@ +--- +slug: tf-plan-again +id: zygbx8xdmnaa +type: challenge +title: "\U0001F469‍\U0001F4BB Test and Repair" +teaser: | + Terraform is idempotent. Each resource in your code will be examined, and if it already exists Terraform will leave it alone. +notes: +- type: text + contents: |- + Terraform is an *idempotent* application. + + Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. + + https://en.wikipedia.org/wiki/Idempotence +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Try running `terraform plan` again and see what happens: + +``` +terraform plan +``` + +Since your Azure resource group has already been built, Terraform will report that there are no changes required. + +This is normal and expected. + +Now try running another apply: + +``` +terraform apply +``` + +Terraform checks each resource to ensure it is in the proper state. It will not re-create your resource group if it is already provisioned correctly. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/tf-plan-again/check-workstation b/instruqt-tracks/terraform-intro-azure/14-tf-plan-again/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-plan-again/check-workstation rename to instruqt-tracks/terraform-intro-azure/14-tf-plan-again/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-plan-again/setup-workstation b/instruqt-tracks/terraform-intro-azure/14-tf-plan-again/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-plan-again/setup-workstation rename to instruqt-tracks/terraform-intro-azure/14-tf-plan-again/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-plan-again/solve-workstation b/instruqt-tracks/terraform-intro-azure/14-tf-plan-again/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-plan-again/solve-workstation rename to instruqt-tracks/terraform-intro-azure/14-tf-plan-again/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/15-change-prefix/assignment.md b/instruqt-tracks/terraform-intro-azure/15-change-prefix/assignment.md new file mode 100755 index 00000000..5cb16467 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/15-change-prefix/assignment.md @@ -0,0 +1,35 @@ +--- +slug: change-prefix +id: 1juoqov8vnx0 +type: challenge +title: "\U0001F6EB Change Your Prefix" +teaser: | + When your Terraform code changes, your infrastructure will be modified to match the updated code. Terraform is a declarative language. +notes: +- type: text + contents: |- + Terraform can create, destroy, update in place, or destroy and re-create your infrastructure. Some types of resources can be updated without deleting them. Major changes usually require a teardown and rebuild. + + Terraform always tries to match the current infrastructure to what has been defined in your code. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Edit the **terraform.tfvars** file to change your prefix. + +Save the **terraform.tfvars** file and run your apply command again. + +``` +terraform apply +``` + +Type "yes" when prompted. + +Observe the output. What happened? \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/change-prefix/check-workstation b/instruqt-tracks/terraform-intro-azure/15-change-prefix/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/change-prefix/check-workstation rename to instruqt-tracks/terraform-intro-azure/15-change-prefix/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-destroy/setup-workstation b/instruqt-tracks/terraform-intro-azure/15-change-prefix/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-destroy/setup-workstation rename to instruqt-tracks/terraform-intro-azure/15-change-prefix/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/change-prefix/solve-workstation b/instruqt-tracks/terraform-intro-azure/15-change-prefix/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/change-prefix/solve-workstation rename to instruqt-tracks/terraform-intro-azure/15-change-prefix/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/16-add-a-tag/assignment.md b/instruqt-tracks/terraform-intro-azure/16-add-a-tag/assignment.md new file mode 100755 index 00000000..409e6c0c --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/16-add-a-tag/assignment.md @@ -0,0 +1,35 @@ +--- +slug: add-a-tag +id: szow0ncj2rqi +type: challenge +title: "\U0001F3F7️ Add a Tag to Your Resource Group" +teaser: | + Terraform can change some resources in in place without deleting them. Adding tags is a non-destructive action. +notes: +- type: text + contents: Adding, changing, or removing tags is a non-destructive action. Terraform + can tag your resources without re-creating them. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Read the Terraform documentation for the azurerm_resource_group resource: + +[Azure Terraform Docs - Click Here](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) + +Add a tag to your resource group in the **main.tf** file using the `tags` argument of the `azurerm_resource_group` resource. + +The name of the tag should be `environment` and the value should be `Production` surrounded by double-quotes. The tag is case-sensitive. Make sure you use a capital P. You'll need to use `=` after `environment`. + +Be sure to save the file. + +Re-run `terraform apply`. + +What happens? \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/add-a-tag/check-workstation b/instruqt-tracks/terraform-intro-azure/16-add-a-tag/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-a-tag/check-workstation rename to instruqt-tracks/terraform-intro-azure/16-add-a-tag/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-init-provider/setup-workstation b/instruqt-tracks/terraform-intro-azure/16-add-a-tag/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-init-provider/setup-workstation rename to instruqt-tracks/terraform-intro-azure/16-add-a-tag/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/add-a-tag/solve-workstation b/instruqt-tracks/terraform-intro-azure/16-add-a-tag/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-a-tag/solve-workstation rename to instruqt-tracks/terraform-intro-azure/16-add-a-tag/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/17-add-virtual-network/assignment.md b/instruqt-tracks/terraform-intro-azure/17-add-virtual-network/assignment.md new file mode 100755 index 00000000..efbf7c12 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/17-add-virtual-network/assignment.md @@ -0,0 +1,30 @@ +--- +slug: add-virtual-network +id: 2byhpkuve0uw +type: challenge +title: "\U0001F5A7 Add a Virtual Network" +teaser: | + Terraform resources are like building blocks. You can continue adding more blocks until your infrastructure reaches the desired state. +notes: +- type: text + contents: Terraform code can be built incrementally, one or two resources at a time. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Open the **main.tf** file again and uncomment the next resource block in the file. The type of resource is **azurerm_virtual_network** and it is named **vnet**. + +Uncomment the code by removing the `#` characters from the beginning of each line. Be sure to save the file. + +Now run `terraform apply` again and answer "yes" when prompted. Observe the results. + +Look at the **location** and **resource_group_name** parameters inside the vnet resource. See how they point back at the first resource in the file? The virtual network resource inherits settings from the resource group. + +Terraform can map out the complex web of dependencies between hundreds of interconnected resources. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/add-virtual-network/check-workstation b/instruqt-tracks/terraform-intro-azure/17-add-virtual-network/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-virtual-network/check-workstation rename to instruqt-tracks/terraform-intro-azure/17-add-virtual-network/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-plan/setup-workstation b/instruqt-tracks/terraform-intro-azure/17-add-virtual-network/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-plan/setup-workstation rename to instruqt-tracks/terraform-intro-azure/17-add-virtual-network/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/add-virtual-network/solve-workstation b/instruqt-tracks/terraform-intro-azure/17-add-virtual-network/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-virtual-network/solve-workstation rename to instruqt-tracks/terraform-intro-azure/17-add-virtual-network/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/18-complete-the-build/assignment.md b/instruqt-tracks/terraform-intro-azure/18-complete-the-build/assignment.md new file mode 100755 index 00000000..07fb56b7 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/18-complete-the-build/assignment.md @@ -0,0 +1,37 @@ +--- +slug: complete-the-build +id: trfoujcx6peo +type: challenge +title: "\U0001F3D7️ Complete the Build" +teaser: | + Terraform code can stand up everything from resource groups, to virtual networks, to VMs and containers. +notes: +- type: text + contents: The `-auto-approve` flag can be used to override the "Are you sure?" questions + that appear before an apply or destroy. Use with caution! +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +We've uncommented all the rest of the Terraform code in the **main.tf** file for you. Run a `terraform plan` to see what will be built: + +``` +terraform plan +``` + +Now run an apply to build the HashiCat application: + +``` +terraform apply -auto-approve +``` + +It can take up to ten minutes for the application to finish deploying. You will know it is complete when you see the Terraform output with your application URL at the end of the run. + +Open your web application in a new browser tab by clicking on the URL in the `catapp_url` output. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/complete-the-build/check-workstation b/instruqt-tracks/terraform-intro-azure/18-complete-the-build/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/complete-the-build/check-workstation rename to instruqt-tracks/terraform-intro-azure/18-complete-the-build/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/complete-the-build/setup-workstation b/instruqt-tracks/terraform-intro-azure/18-complete-the-build/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/complete-the-build/setup-workstation rename to instruqt-tracks/terraform-intro-azure/18-complete-the-build/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/complete-the-build/solve-workstation b/instruqt-tracks/terraform-intro-azure/18-complete-the-build/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/complete-the-build/solve-workstation rename to instruqt-tracks/terraform-intro-azure/18-complete-the-build/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/19-tf-graph-again/assignment.md b/instruqt-tracks/terraform-intro-azure/19-tf-graph-again/assignment.md new file mode 100755 index 00000000..f968a8c3 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/19-tf-graph-again/assignment.md @@ -0,0 +1,34 @@ +--- +slug: tf-graph-again +id: j4haitcpwyyb +type: challenge +title: "\U0001F4C8 Terraform Graph" +teaser: | + Revisit graph to see what has changed. +notes: +- type: text + contents: Let's revisit our graph to see what has changed. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Terraform Graph + type: service + hostname: workstation + port: 5000 +difficulty: basic +timelimit: 10670 +--- +Start up a Blast Radius server with the following command: + +``` +blast-radius --serve . +``` + +Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) + +Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. + +**NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. + +Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph-again/check-workstation b/instruqt-tracks/terraform-intro-azure/19-tf-graph-again/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph-again/check-workstation rename to instruqt-tracks/terraform-intro-azure/19-tf-graph-again/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-validate/setup-workstation b/instruqt-tracks/terraform-intro-azure/19-tf-graph-again/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-validate/setup-workstation rename to instruqt-tracks/terraform-intro-azure/19-tf-graph-again/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/fun-with-variables/solve-workstation b/instruqt-tracks/terraform-intro-azure/19-tf-graph-again/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/fun-with-variables/solve-workstation rename to instruqt-tracks/terraform-intro-azure/19-tf-graph-again/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/20-terraform-apply-quiz/assignment.md b/instruqt-tracks/terraform-intro-azure/20-terraform-apply-quiz/assignment.md new file mode 100755 index 00000000..e739a1e8 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/20-terraform-apply-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: terraform-apply-quiz +id: pqzhlrhyji8j +type: quiz +title: "\U0001F4DD Quiz 3 - Terraform Apply" +teaser: | + What happens when you run `terraform apply` without a plan file? +notes: +- type: text + contents: | + It's quiz time! +answers: +- Terraform runs without any plan +- Terraform reads the previous plan and then applies it +- Terraform runs a new plan right before the apply +- None of the above +solution: +- 2 +difficulty: basic +timelimit: 10670 +--- +What happens when you run `terraform apply` without specifying a plan file? diff --git a/instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/assignment.md b/instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/assignment.md new file mode 100755 index 00000000..769fafdf --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/assignment.md @@ -0,0 +1,58 @@ +--- +slug: use-a-provisioner +id: hucz5xz4ihjs +type: challenge +title: "\U0001F6E0️ Use a Provisioner" +teaser: | + Terraform works great with many different provisioning tools including Chef, Puppet, Ansible, Bash, and Powershell. +notes: +- type: text + contents: Terraform provisioners run once at creation time. They do not run on subsequent + applies, except in special circumstances. (Like this training lab...) +- type: text + contents: We've made some special adjustments to force the provisioner to run every + time you type terraform apply. This is so you can practice playing with provisioners + without destroying and recreating your virtual machine every time you make a change. +- type: text + contents: |- + ``` + ______________________ + < Cows love Terraform! > + ---------------------- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || || + ============================= + ``` +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Open the `main.tf` file on the "Code Editor" tab. Scroll down until you find the `remote-exec` provisioner block, or search the file and find it with CTRL-F. + +Add the following two lines at the end of the inline list of commands: + +``` +"sudo apt -y install cowsay", +"cowsay Mooooooooooo!", +``` +After copying them into your buffer, it will be easier to paste them if you hide the assignment by clicking the ">" icon. Click it again to redisplay the assignment. Be sure to save the file. + +This might be a good time to use the `terraform fmt` command to line up the commands nicely. + +Now apply your changes: + +``` +terraform apply -auto-approve +``` + +Scroll back through the log output. You should see an ASCII art cow saying "Moooooooo!" \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/use-a-provisioner/check-workstation b/instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/use-a-provisioner/check-workstation rename to instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-variables/setup-workstation b/instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-variables/setup-workstation rename to instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/use-a-provisioner/solve-workstation b/instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/use-a-provisioner/solve-workstation rename to instruqt-tracks/terraform-intro-azure/21-use-a-provisioner/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/22-add-an-output/assignment.md b/instruqt-tracks/terraform-intro-azure/22-add-an-output/assignment.md new file mode 100755 index 00000000..a2788d8b --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/22-add-an-output/assignment.md @@ -0,0 +1,55 @@ +--- +slug: add-an-output +id: mavyhkc54a76 +type: challenge +title: "\U0001F5A8️ Add an Output" +teaser: | + Outputs are used to convey useful information such as IP addresses, application URLs or other useful data. +notes: +- type: text + contents: You can mix plain text along with Terraform data in your outputs. Outputs + can be used to convey useful information to your users at the end of a run. +- type: text + contents: The `terraform refresh` command will sync your state file with what exists + in your infrastructure. A refresh command will not change your infrastructure. +- type: text + contents: The `terraform output` command can be run any time you want to see your + Terraform outputs again. Run `terraform output ` to view a single + output. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Open the **outputs.tf** file on the "Code Editor" tab. + +Add a second output for the `ip_address` of your web server. It's going to look almost exactly like the first output but will instead output an IP address instead of a DNS name. + +Name your output `catapp_ip`. + +You may refer to the docs page to see what types of outputs are valid: + +[Terraform Azure Docs - Click Here](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip#attributes-reference) +[Terraform Outputs Docs - Click Here](https://www.terraform.io/docs/configuration/outputs.html) + +Be sure to save the changes to the **outputs.tf** file. + +Run the terraform refresh command to view your new output: + +``` +terraform refresh +``` + +You can run the Terraform output command to view all your outputs: + +``` +terraform output +``` + +You can click on either URL to use the web app. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/add-an-output/check-workstation b/instruqt-tracks/terraform-intro-azure/22-add-an-output/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-an-output/check-workstation rename to instruqt-tracks/terraform-intro-azure/22-add-an-output/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph-again/setup-workstation b/instruqt-tracks/terraform-intro-azure/22-add-an-output/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph-again/setup-workstation rename to instruqt-tracks/terraform-intro-azure/22-add-an-output/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/add-an-output/solve-workstation b/instruqt-tracks/terraform-intro-azure/22-add-an-output/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/add-an-output/solve-workstation rename to instruqt-tracks/terraform-intro-azure/22-add-an-output/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/23-fun-with-variables/assignment.md b/instruqt-tracks/terraform-intro-azure/23-fun-with-variables/assignment.md new file mode 100755 index 00000000..03837da3 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/23-fun-with-variables/assignment.md @@ -0,0 +1,67 @@ +--- +slug: fun-with-variables +id: q3swwmy27cvi +type: challenge +title: "\U0001F436 Fun With Variables" +teaser: | + Variables give the consumers of your Terraform code an easy way to customize their infrastructure. +notes: +- type: text + contents: |- + Terraform variables have five levels of precedence. 1=highest 5=lowest: + + 1. Command line flag - run as a command line switch + 1. Configuration file - set in your terraform.tfvars file + 1. Environment variable - part of your shell environment + 1. Default Config - default value in variables.tf + 1. User manual entry - if not specified, prompt the user for entry +- type: text + contents: |- + Here are some other fun placeholder sites you can try with the **placeholder** variable: + + placedog.net
+ placebear.com
+ www.fillmurray.com
+ www.placecage.com
+ placebeard.it
+ loremflickr.com
+ baconmockup.com
+ placeimg.com
+tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +There are several ways to configure Terraform variables. So far we've been using the **terraform.tfvars** file to set our variables. Try re-deploying your application with different **height** and **width** variables on the command line. Reload the webapp after each apply to observe any changes. + +``` +terraform apply -auto-approve -var height=600 -var width=800 +``` + +Next try setting an environment variable that Terraform can read. Run this command to set the placeholder variable: + +``` +export TF_VAR_placeholder=placedog.net +``` + +Run another `terraform apply -auto-approve` command: + +``` +terraform apply -auto-approve +``` + +Now try it again with the same variable set differently on the command line: + +``` +terraform apply -auto-approve -var placeholder=placebear.com +``` + +Which variable took precedence? Why? + +See this [doc](https://www.terraform.io/docs/configuration/variables.html#variable-definition-precedence) if you're unsure. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/configure-remote-state/check-workstation b/instruqt-tracks/terraform-intro-azure/23-fun-with-variables/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/configure-remote-state/check-workstation rename to instruqt-tracks/terraform-intro-azure/23-fun-with-variables/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph/setup-workstation b/instruqt-tracks/terraform-intro-azure/23-fun-with-variables/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph/setup-workstation rename to instruqt-tracks/terraform-intro-azure/23-fun-with-variables/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-cloud-setup/solve-workstation b/instruqt-tracks/terraform-intro-azure/23-fun-with-variables/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-cloud-setup/solve-workstation rename to instruqt-tracks/terraform-intro-azure/23-fun-with-variables/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/24-terraform-variables-quiz/assignment.md b/instruqt-tracks/terraform-intro-azure/24-terraform-variables-quiz/assignment.md new file mode 100755 index 00000000..86a3fd1f --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/24-terraform-variables-quiz/assignment.md @@ -0,0 +1,20 @@ +--- +slug: terraform-variables-quiz +id: 3ukxio6zc1w0 +type: quiz +title: "\U0001F4DD Quiz 4 - Terraform Variables" +teaser: | + How do Terraform variables get set or overridden? +notes: +- type: text + contents: | + Get ready for another quiz... +answers: +- The environment variable +- The tfvars config file +solution: +- 1 +difficulty: basic +timelimit: 10670 +--- +You have the same variable set in a *.tfvars file and as an environment variable. Which one takes precedence? diff --git a/instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/assignment.md b/instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/assignment.md new file mode 100755 index 00000000..2f5bc080 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/assignment.md @@ -0,0 +1,38 @@ +--- +slug: hcp-terraform-setup +id: iqi9tsxbya43 +type: challenge +title: ☁️ HCP Terraform Setup +teaser: | + HCP Terraform offers unlimited free Terraform state storage for users. Safeguard your state files by storing them remotely in HCP Terraform. +notes: +- type: text + contents: HCP Terraform remote state storage is free for all users. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +During this challenge and the next one, you'll use the remote state feature of HCP Terraform to store your state file in the cloud. In order to do this you'll need a HCP Terraform account. Click on the URL below and sign up for a free account if you don't have one already: + +https://app.terraform.io/signup/account + +If you already have an account you can simply sign in with your existing credentials. + +Once you're signed into HCP Terraform create a new organization called YOURNAME-training. Replace YOURNAME with your own name or other text. + +Next you'll be prompted to create a workspace. You can skip the VCS integration step by clicking the "CLI-driven workflow" panel. Name your workspace **hashicat-azure**. + +**Note:** If you already have a **hashicat-azure** workspace, please delete the workspace by selecting the **Settings >> Destruction and Deletion** menu, clicking the "Delete from HCP Terraform" button, typing "hashicat-azure" to confirm, and then clicking the "Delete workspace" button. Then re-create it as above. Doing this avoids possible problems with mis-matched state versions when executing local runs after having executed remote runs. This could happen if you played the [HCP Terraform with Azure](https://play.instruqt.com/hashicorp/tracks/terraform-cloud-azure) track and then played this track. + +Run `terraform version` on the "Shell" tab and then set the **Terraform Version** to match on the workspace's **Settings >> General** settings page. + +Also, change the **Execution Mode** to **Local**. + +Be sure to save your settings by clicking the "Save settings" button at the bottom of the page! This will allow us to run Terraform commands from our workstation with local variables, which we'll do in the next challenge. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-cloud-setup/check-workstation b/instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-cloud-setup/check-workstation rename to instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-cloud-setup/setup-workstation b/instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-cloud-setup/setup-workstation rename to instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-code/solve-workstation b/instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-code/solve-workstation rename to instruqt-tracks/terraform-intro-azure/25-hcp-terraform-setup/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/26-configure-remote-state/assignment.md b/instruqt-tracks/terraform-intro-azure/26-configure-remote-state/assignment.md new file mode 100755 index 00000000..03be7d35 --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/26-configure-remote-state/assignment.md @@ -0,0 +1,57 @@ +--- +slug: configure-remote-state +id: au2yujjwn1vh +type: challenge +title: "\U0001F39B️ Configure Remote State" +teaser: | + The Terraform command line tool can store its state in HCP Terraform. All that is required is a user token. +notes: +- type: text + contents: |- + With *local* execution mode the Terraform commands and variables all remain + on your workstation. + + With *remote* execution mode Terraform runs in a HCP Terraform + container environment. All variables must be configured in the cloud environment with this method. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +- title: Credentials File + type: code + hostname: workstation + path: /root/.terraform.d/credentials.tfrc.json +difficulty: basic +timelimit: 10670 +--- +During this challenge we'll configure HCP Terraform as a remote state backend, and then migrate our existing state file to HCP Terraform. + +Edit the "remote_backend.tf" file and replace the YOURORGANIZATION and YOURWORKSPACE placeholders with your org name and workspace name. Be sure to save the file. + +Let's generate a new **user token** for use on your workstation. Visit the User Settings > Tokens page in HCP Terraform: + +https://app.terraform.io/app/settings/tokens + +Click on the **Create an API token** button. You can name the token whatever you like. Copy the entire token using your mouse or the small copy-paste icon. + +Back in the Instruqt track, you need to add your API token to a file called "credentials.tfrc.json". Select the "Credentials File" tab and open the `/root/.terraform.d/credentials.tfrc.json` file directly. + +Replace the part that says YOURTOKEN with what you copied from HCP Terraform. Be sure to save the file. + +Your token is now safely stored in the `/root/.terraform.d/credentials.tfrc.json` file. + +Now run `terraform init` to migrate your state to HCP Terraform. + +``` +terraform init +``` + +Type "yes" when it prompts you to migrate your state to HCP Terraform. + +Your state is now safely stored in HCP Terraform. You can verify this on the "States" tab of your workspace in the TFC UI. + +Run a `terraform apply -auto-approve` and watch your state file evolve with each change. You can browse through previous state files with the HCP Terraform UI. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/fun-with-variables/check-workstation b/instruqt-tracks/terraform-intro-azure/26-configure-remote-state/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/fun-with-variables/check-workstation rename to instruqt-tracks/terraform-intro-azure/26-configure-remote-state/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-plan-and-apply/setup-workstation b/instruqt-tracks/terraform-intro-azure/26-configure-remote-state/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-plan-and-apply/setup-workstation rename to instruqt-tracks/terraform-intro-azure/26-configure-remote-state/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/tf-graph-again/solve-workstation b/instruqt-tracks/terraform-intro-azure/26-configure-remote-state/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/tf-graph-again/solve-workstation rename to instruqt-tracks/terraform-intro-azure/26-configure-remote-state/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/27-terraform-destroy/assignment.md b/instruqt-tracks/terraform-intro-azure/27-terraform-destroy/assignment.md new file mode 100755 index 00000000..373d9dba --- /dev/null +++ b/instruqt-tracks/terraform-intro-azure/27-terraform-destroy/assignment.md @@ -0,0 +1,37 @@ +--- +slug: terraform-destroy +id: khbfotgar75h +type: challenge +title: "\U0001F525 Terraform Destroy" +teaser: | + Terraform can build infrastructure and also destroy it when you are done using it. This helps control costs and reduce infrastructure sprawl. +notes: +- type: text + contents: |- + Terraform can destroy infrastructure as easily as it can build it. + + Use `terraform destroy` with caution. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-azure +difficulty: basic +timelimit: 10670 +--- +Run the following command to destroy your infrastructure: + +``` +terraform destroy +``` + +You'll need to type "yes" when prompted to destroy your infrastructure. This is a safety feature to help prevent accidental deletion of important resources. + +Wait until the destroy action has completely finished before clicking on the *Check* button. + +Depending on the version of Terraform you are using, it is possible that the destroy action will fail. That will be resolved in a future version of Terraform. + +Congratulations on completing the Intro to Terraform track! \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-azure/terraform-destroy/check-workstation b/instruqt-tracks/terraform-intro-azure/27-terraform-destroy/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-destroy/check-workstation rename to instruqt-tracks/terraform-intro-azure/27-terraform-destroy/check-workstation diff --git a/instruqt-tracks/terraform-intro-azure/use-a-provisioner/setup-workstation b/instruqt-tracks/terraform-intro-azure/27-terraform-destroy/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/use-a-provisioner/setup-workstation rename to instruqt-tracks/terraform-intro-azure/27-terraform-destroy/setup-workstation diff --git a/instruqt-tracks/terraform-intro-azure/terraform-destroy/solve-workstation b/instruqt-tracks/terraform-intro-azure/27-terraform-destroy/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-azure/terraform-destroy/solve-workstation rename to instruqt-tracks/terraform-intro-azure/27-terraform-destroy/solve-workstation diff --git a/instruqt-tracks/terraform-intro-azure/config.yml b/instruqt-tracks/terraform-intro-azure/config.yml index e62f491d..19c469a4 100644 --- a/instruqt-tracks/terraform-intro-azure/config.yml +++ b/instruqt-tracks/terraform-intro-azure/config.yml @@ -1,7 +1,7 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -version: "2" +version: "3" virtualmachines: - name: workstation image: instruqt-hashicorp/ubuntu-2004-base diff --git a/instruqt-tracks/terraform-intro-azure/track.yml b/instruqt-tracks/terraform-intro-azure/track.yml index e765c2bd..7fc8b789 100644 --- a/instruqt-tracks/terraform-intro-azure/track.yml +++ b/instruqt-tracks/terraform-intro-azure/track.yml @@ -1,9 +1,5 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -slug: terraform-intro-azure -id: oppbddvupbkc -type: track +slug: wip-vcdl-846-terraform-intro-azure +id: nzwzce8frqo5 title: Intro to Terraform on Azure teaser: | Provision the HashiCat application on Azure Cloud using Terraform. @@ -13,1042 +9,23 @@ description: |- Kittens as a Service! icon: https://storage.googleapis.com/instruqt-hashicorp-tracks/logo/terraform.png tags: -- terraform - azure +- terraform - basics -owner: hashicorp +owner: hashicorp-field-ops developers: - roger@hashicorp.com - sean.carolan@hashicorp.com -private: true -published: true +- syed.quadri@hashicorp.com show_timer: true -challenges: -- slug: setup-our-environment - id: 11tsvhsfmamz - type: challenge - title: "\U0001F3E1 Moving in - Explore Your Workspace" - teaser: | - Explore the Terraform code for the hashicat application. - notes: - - type: text - contents: | - Setting up your environment... - Keep an eye on the bottom right corner to know when you can get started. - - type: text - contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD, - Windows, Solaris and Linux. - - type: text - contents: The Terraform language is designed to be both human and machine-readable. - - type: text - contents: Most modern code editors support Terraform syntax highlighting. - assignment: |- - Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors. - - When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor! - - Throughout this track, please execute all commands on the "Shell" tab. - - Congratulations, you are ready to start working with Terraform on Azure. We'll use the hashicat-azure example app in the rest of the challenges as you learn new Terraform skills. - - Click the **Check** button to continue. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: hello-terraform - id: komlxib2jult - type: challenge - title: "\U0001F44B Getting to Know Terraform" - teaser: | - Learn Terraform basics and command line syntax. - notes: - - type: text - contents: |- - Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation. - - It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html - - type: text - contents: |- - Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH. - - Check out this tutorial for step-by-step instructions: - - https://learn.hashicorp.com/terraform/getting-started/install.html - - We've pre-installed Terraform in your Instruqt lab environment for you. - assignment: |- - Let's start with some basic Terraform commands. - Run the following commands on the "Shell" tab. - - Check the version of Terraform running on your machine: - - ``` - terraform version - ``` - - You can always get help if you're curious about command syntax: - - ``` - terraform --help - ``` - - Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation. Terraform is also pre-installed in Azure Cloud Shell. - - Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: azure-credentials - id: 57gjkzcdmlym - type: challenge - title: "\U0001F510 Connecting Terraform to Azure Cloud" - teaser: | - Safely connect to the Azure APIs using a service principal. - notes: - - type: text - contents: |- - Microsoft has a great tutorial for setting up Azure credentials on your laptop or virtual workstation: - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure - - type: text - contents: |- - Azure Cloud Shell is another easy way to get started with Terraform. With Azure Cloud Shell, Terraform is pre-installed and ready to go. - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure#use-azure-cloud-shell - assignment: |- - Terraform needs credentials to be able to connect to Azure and build resources. - - We've pre-installed some temporary credentials in your Instruqt training environment. These credentials are stored as environment variables. You should never store sensitive API keys inside your source code. - - Terraform can automatically read and use the environment variables that are in your shell environment. - - Run the following command on your "Shell" tab to see your temporary credentials: - ``` - env | grep ARM_CLIENT - ``` - You should see valid Azure credentials. If not, return to the track home page by clicking the **Close** button, stop the track, and then restart it. - - *Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: terraform-code - id: 2g1awofxqb4b - type: challenge - title: "\U0001F468‍\U0001F4BB What does Terraform code look like?" - teaser: | - The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure. - notes: - - type: text - contents: |- - Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`. - - By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files. - - You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`. - assignment: |- - We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files: - ``` - ls *.tf - ``` - The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon. - - Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first: - - **main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.
- **variables.tf** - Use this file to define which variables will be available to your users.
- **outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run. - - Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: terraform-init-provider - id: 9ovxa69cpkvi - type: challenge - title: ☁️ Terraform Init - Install the Azure Provider - teaser: | - Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers. - notes: - - type: text - contents: |- - The Terraform core program isn't very useful by itself. Terraform needs the help of a **provider** to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here: - - https://registry.terraform.io/browse/providers - - Today we'll be using the **azurerm** provider. AzureRM stands for Azure Resource Manager. - assignment: |- - We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track. - - Before we can do anything with Terraform we need to initialize our workspace. Run the following command in your "Shell" tab: - ``` - terraform init - ``` - The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them. - - Run the following command to verify that the azurerm provider was installed under the ".terraform" directory:: - ``` - ls .terraform/providers/registry.terraform.io/hashicorp - ``` - This hidden directory is where all modules and plugins are stored. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: provider-quiz - id: qkug3tpu7wc8 - type: quiz - title: "\U0001F4DD Quiz 1 - Providers and Modules" - teaser: | - A quiz about Terraform init - notes: - - type: text - contents: | - It's quiz time! - assignment: | - Where does Terraform store its modules and providers? - answers: - - In the /tmp directory - - In the user's home directory - - In the .terraform directory - - None of the above - solution: - - 2 - difficulty: basic - timelimit: 1067 -- slug: terraform-validate - id: 5fyezuqqcwyp - type: challenge - title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code" - teaser: | - Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly. - notes: - - type: text - contents: Terraform has a built-in syntax checker. You can run it with the `terraform - validate` command. - assignment: |- - Terraform comes with a built-in subcommand called **validate**. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly. - - Edit the main.tf file and remove the double quotes between `azurerm_resource_group` and `myresourcegroup` on line 14 of the file, keeping the space that was between them. Save the file. - - Validate your code: - - ``` - terraform validate - ``` - - Now put the double quotes back in line 14, save the file, and run the validate command again. This time you should pass the validation test. - - **terraform validate** is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: terraform-plan - id: oa25zys0y9yr - type: challenge - title: "\U0001F914 Terraform Plan - Dry Run Mode" - teaser: | - Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run Terraform plan and view the output. - notes: - - type: text - contents: |- - `terraform plan` allows you to preview any changes to your environment in a safe way. - - This can help you identify any unexpected changes before you deploy them, not after they are already built. - assignment: |- - Run the **terraform plan** command: - ``` - terraform plan - ``` - When you run this command Terraform will prompt you to enter the `prefix` variable. - - Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name. - - **Keep your prefix string all lower case, and between 5-12 characters long. Do not use an underscore in your prefix.** - - The prefix will become part of your application hostname, and therefore must be DNS-compliant. Valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, and the hyphen (-). A hostname may not start with a hyphen. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: terraform-variables - id: bxjgjhy6pj0n - type: challenge - title: "\U0001F39B️ Working with Terraform Variables" - teaser: | - Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables. - notes: - - type: text - contents: The `terraform.tfvars` file is a convenient place for users to configure - their variables. - assignment: |- - In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later. - - Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case). - - **Be sure to click the disk icon above the file to save your change!** - - Now run `terraform plan` again. This time you won't have to enter your prefix manually. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: terraform-add-a-variable - id: sthkanuoyjix - type: challenge - title: "\U0001F5FC Change Your Location" - teaser: | - Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable. - notes: - - type: text - contents: |- - You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file. - - In this challenge, you will pick the location where your Azure resources should be deployed. - assignment: |- - In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set another variable that will determine the location where your Azure infrastructure will be deployed. - - First run another plan so you'll be able to compare what happens after you change the location. - - ``` - terraform plan - ``` - - Choose an Azure location near to you but different from the default one which is "eastus". Add a `location` variable to your "terraform.tfvars" file, setting it to your desired location such as `East US`, `UK South`, or `Southeast Asia`. You can also use shorter names like `eastus`, `uksouth`, or `southeastasia`; in fact, Terraform will convert the longer names with spaces to the shorter names without them. - - See this [page](https://azure.microsoft.com/en-us/global-infrastructure/geographies/) for a list of valid Azure locations (which shows the longer names with spaces). - - Choosing a location close to you can help improve speed and performance. - - (**Note that not all Azure regions support all VM types**; if you get an error about the SKU failing because of capacity restrictions when you run the Terraform commands below, try changing to a different region.) - - **Be sure to click the disk icon above the file to save your change!** - - Once you've set your location variable try running `terraform plan` again. What's different this time? - - Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: variables-quiz - id: cnenux7f8qep - type: quiz - title: "\U0001F4DD Quiz 2 - Variables" - teaser: | - A quiz about Terraform variables - notes: - - type: text - contents: | - Another quiz, get ready! - assignment: | - Where are terraform variables usually *declared*? - answers: - - On the command line - - As environment variables - - In the variables.tf file - - In the terraform.tfvars file - solution: - - 2 - difficulty: basic - timelimit: 1067 -- slug: tf-graph - id: pynjmvy4zxjx - type: challenge - title: "\U0001F4C8 Terraform Graph" - teaser: | - Terraform creates a graph of all the infrastructure defined in your code. - notes: - - type: text - contents: Terraform Graph can provide a visual representation of all your infrastructure. - This is handy for finding dependency issues or resources that will be affected - by a change. - assignment: |- - Try running the `terraform graph` command: - - ``` - terraform graph - ``` - - This generates code that can be used to create a visual map of your infrastructure. The graph data is in [DOT graph description language format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). There are several graphing tools you can use to visualize this data, including the free Blast Radius tool. You can learn more about Blast Radius here: - - https://28mm.github.io/blast-radius-docs/ - - Start up a Blast Radius server with the following command: - - ``` - blast-radius --serve . - ``` - - Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) - - Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. - - **NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. - - Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Terraform Graph - type: service - hostname: workstation - port: 5000 - difficulty: basic - timelimit: 1067 -- slug: tf-plan-and-apply - id: rwlnusfqiscq - type: challenge - title: "\U0001F468‍\U0001F4BB Terraform Plan and Terraform Apply" - teaser: | - The terraform plan command can be run anytime to get a preview of changes that Terraform might make. When you run terraform apply these changes are implemented, and Terraform builds, updates, or destroys resources. - notes: - - type: text - contents: |- - By default, the `terraform apply` command runs a Terraform plan to show you what changes it wants to make. - - Terraform maps out all the changes it needs to make before applying them. - assignment: |- - Now that we've configured our required variables we can apply our changes. - - Run the `terraform plan` command first to see what will happen: - - ``` - terraform plan - ``` - Confirm the proper prefix and location are displayed in the plan output. - - Then run *terraform apply* and watch your resource group being built. - - ``` - terraform apply - ``` - - You'll need to enter *yes* when Terraform prompts you with the "Do you want to perform these actions?" question. - - Right now our code only defines a single Azure resource group. We'll be building upon this starting point in the next challenge. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: tf-plan-again - id: m9pq5fqslxck - type: challenge - title: "\U0001F469‍\U0001F4BB Test and Repair" - teaser: | - Terraform is idempotent. Each resource in your code will be examined, and if it already exists Terraform will leave it alone. - notes: - - type: text - contents: |- - Terraform is an *idempotent* application. - - Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. - - https://en.wikipedia.org/wiki/Idempotence - assignment: |- - Try running `terraform plan` again and see what happens: - - ``` - terraform plan - ``` - - Since your Azure resource group has already been built, Terraform will report that there are no changes required. - - This is normal and expected. - - Now try running another apply: - - ``` - terraform apply - ``` - - Terraform checks each resource to ensure it is in the proper state. It will not re-create your resource group if it is already provisioned correctly. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: change-prefix - id: xf0u45nhfcyt - type: challenge - title: "\U0001F6EB Change Your Prefix" - teaser: | - When your Terraform code changes, your infrastructure will be modified to match the updated code. Terraform is a declarative language. - notes: - - type: text - contents: |- - Terraform can create, destroy, update in place, or destroy and re-create your infrastructure. Some types of resources can be updated without deleting them. Major changes usually require a teardown and rebuild. - - Terraform always tries to match the current infrastructure to what has been defined in your code. - assignment: |- - Edit the **terraform.tfvars** file to change your prefix. - - Save the **terraform.tfvars** file and run your apply command again. - - ``` - terraform apply - ``` - - Type "yes" when prompted. - - Observe the output. What happened? - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: add-a-tag - id: zom74l3f3uin - type: challenge - title: "\U0001F3F7️ Add a Tag to Your Resource Group" - teaser: | - Terraform can change some resources in in place without deleting them. Adding tags is a non-destructive action. - notes: - - type: text - contents: Adding, changing, or removing tags is a non-destructive action. Terraform - can tag your resources without re-creating them. - assignment: |- - Read the Terraform documentation for the azurerm_resource_group resource: - - [Azure Terraform Docs - Click Here](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) - - Add a tag to your resource group in the **main.tf** file using the `tags` argument of the `azurerm_resource_group` resource. - - The name of the tag should be `environment` and the value should be `Production` surrounded by double-quotes. The tag is case-sensitive. Make sure you use a capital P. You'll need to use `=` after `environment`. - - Be sure to save the file. - - Re-run `terraform apply`. - - What happens? - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: add-virtual-network - id: mucnzxji72ul - type: challenge - title: "\U0001F5A7 Add a Virtual Network" - teaser: | - Terraform resources are like building blocks. You can continue adding more blocks until your infrastructure reaches the desired state. - notes: - - type: text - contents: Terraform code can be built incrementally, one or two resources at a - time. - assignment: |- - Open the **main.tf** file again and uncomment the next resource block in the file. The type of resource is **azurerm_virtual_network** and it is named **vnet**. - - Uncomment the code by removing the `#` characters from the beginning of each line. Be sure to save the file. - - Now run `terraform apply` again and answer "yes" when prompted. Observe the results. - - Look at the **location** and **resource_group_name** parameters inside the vnet resource. See how they point back at the first resource in the file? The virtual network resource inherits settings from the resource group. - - Terraform can map out the complex web of dependencies between hundreds of interconnected resources. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: complete-the-build - id: qcvvtwcbkwoz - type: challenge - title: "\U0001F3D7️ Complete the Build" - teaser: | - Terraform code can stand up everything from resource groups, to virtual networks, to VMs and containers. - notes: - - type: text - contents: The `-auto-approve` flag can be used to override the "Are you sure?" - questions that appear before an apply or destroy. Use with caution! - assignment: |- - We've uncommented all the rest of the Terraform code in the **main.tf** file for you. Run a `terraform plan` to see what will be built: - - ``` - terraform plan - ``` - - Now run an apply to build the HashiCat application: - - ``` - terraform apply -auto-approve - ``` - - It can take up to ten minutes for the application to finish deploying. You will know it is complete when you see the Terraform output with your application URL at the end of the run. - - Open your web application in a new browser tab by clicking on the URL in the `catapp_url` output. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: tf-graph-again - id: rkgvhqpeny7h - type: challenge - title: "\U0001F4C8 Terraform Graph" - teaser: | - Revisit graph to see what has changed. - notes: - - type: text - contents: Let's revisit our graph to see what has changed. - assignment: |- - Start up a Blast Radius server with the following command: - - ``` - blast-radius --serve . - ``` - - Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon (which looks like a circular arrow) - - Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. - - **NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. - - Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Terraform Graph - type: service - hostname: workstation - port: 5000 - difficulty: basic - timelimit: 1067 -- slug: terraform-apply-quiz - id: 30lixl1wf8jx - type: quiz - title: "\U0001F4DD Quiz 3 - Terraform Apply" - teaser: | - What happens when you run `terraform apply` without a plan file? - notes: - - type: text - contents: | - It's quiz time! - assignment: | - What happens when you run `terraform apply` without specifying a plan file? - answers: - - Terraform runs without any plan - - Terraform reads the previous plan and then applies it - - Terraform runs a new plan right before the apply - - None of the above - solution: - - 2 - difficulty: basic - timelimit: 1067 -- slug: use-a-provisioner - id: 0bubkgzcop1w - type: challenge - title: "\U0001F6E0️ Use a Provisioner" - teaser: | - Terraform works great with many different provisioning tools including Chef, Puppet, Ansible, Bash, and Powershell. - notes: - - type: text - contents: Terraform provisioners run once at creation time. They do not run on - subsequent applies, except in special circumstances. (Like this training lab...) - - type: text - contents: We've made some special adjustments to force the provisioner to run - every time you type terraform apply. This is so you can practice playing with - provisioners without destroying and recreating your virtual machine every time - you make a change. - - type: text - contents: |- - ``` - ______________________ - < Cows love Terraform! > - ---------------------- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || - ============================= - ``` - assignment: |- - Open the `main.tf` file on the "Code Editor" tab. Scroll down until you find the `remote-exec` provisioner block, or search the file and find it with CTRL-F. - - Add the following two lines at the end of the inline list of commands: - - ``` - "sudo apt -y install cowsay", - "cowsay Mooooooooooo!", - ``` - After copying them into your buffer, it will be easier to paste them if you hide the assignment by clicking the ">" icon. Click it again to redisplay the assignment. Be sure to save the file. - - This might be a good time to use the `terraform fmt` command to line up the commands nicely. - - Now apply your changes: - - ``` - terraform apply -auto-approve - ``` - - Scroll back through the log output. You should see an ASCII art cow saying "Moooooooo!" - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: add-an-output - id: aboaf1semf3b - type: challenge - title: "\U0001F5A8️ Add an Output" - teaser: | - Outputs are used to convey useful information such as IP addresses, application URLs or other useful data. - notes: - - type: text - contents: You can mix plain text along with Terraform data in your outputs. Outputs - can be used to convey useful information to your users at the end of a run. - - type: text - contents: The `terraform refresh` command will sync your state file with what - exists in your infrastructure. A refresh command will not change your infrastructure. - - type: text - contents: The `terraform output` command can be run any time you want to see your - Terraform outputs again. Run `terraform output ` to view a single - output. - assignment: |- - Open the **outputs.tf** file on the "Code Editor" tab. - - Add a second output for the `ip_address` of your web server. It's going to look almost exactly like the first output but will instead output an IP address instead of a DNS name. - - Name your output `catapp_ip`. - - You may refer to the docs page to see what types of outputs are valid: - - [Terraform Azure Docs - Click Here](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip#attributes-reference) - [Terraform Outputs Docs - Click Here](https://www.terraform.io/docs/configuration/outputs.html) - - Be sure to save the changes to the **outputs.tf** file. - - Run the terraform refresh command to view your new output: - - ``` - terraform refresh - ``` - - You can run the Terraform output command to view all your outputs: - - ``` - terraform output - ``` - - You can click on either URL to use the web app. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: fun-with-variables - id: k9ppxpjeehlo - type: challenge - title: "\U0001F436 Fun With Variables" - teaser: | - Variables give the consumers of your Terraform code an easy way to customize their infrastructure. - notes: - - type: text - contents: |- - Terraform variables have five levels of precedence. 1=highest 5=lowest: - - 1. Command line flag - run as a command line switch - 1. Configuration file - set in your terraform.tfvars file - 1. Environment variable - part of your shell environment - 1. Default Config - default value in variables.tf - 1. User manual entry - if not specified, prompt the user for entry - - type: text - contents: |- - Here are some other fun placeholder sites you can try with the **placeholder** variable: - - placedog.net
- placebear.com
- www.fillmurray.com
- www.placecage.com
- placebeard.it
- loremflickr.com
- baconmockup.com
- placeimg.com
- assignment: |- - There are several ways to configure Terraform variables. So far we've been using the **terraform.tfvars** file to set our variables. Try re-deploying your application with different **height** and **width** variables on the command line. Reload the webapp after each apply to observe any changes. - - ``` - terraform apply -auto-approve -var height=600 -var width=800 - ``` - - Next try setting an environment variable that Terraform can read. Run this command to set the placeholder variable: - - ``` - export TF_VAR_placeholder=placedog.net - ``` - - Run another `terraform apply -auto-approve` command: - - ``` - terraform apply -auto-approve - ``` - - Now try it again with the same variable set differently on the command line: - - ``` - terraform apply -auto-approve -var placeholder=placebear.com - ``` - - Which variable took precedence? Why? - - See this [doc](https://www.terraform.io/docs/configuration/variables.html#variable-definition-precedence) if you're unsure. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: terraform-variables-quiz - id: qnrf6zxpmet0 - type: quiz - title: "\U0001F4DD Quiz 4 - Terraform Variables" - teaser: | - How do Terraform variables get set or overridden? - notes: - - type: text - contents: | - Get ready for another quiz... - assignment: | - You have the same variable set in a *.tfvars file and as an environment variable. Which one takes precedence? - answers: - - The environment variable - - The tfvars config file - solution: - - 1 - difficulty: basic - timelimit: 1067 -- slug: hcp-terraform-setup - id: mq6cxmxuoxyi - type: challenge - title: ☁️ HCP Terraform Setup - teaser: | - HCP Terraform offers unlimited free Terraform state storage for users. Safeguard your state files by storing them remotely in HCP Terraform. - notes: - - type: text - contents: HCP Terraform remote state storage is free for all users. - assignment: |- - During this challenge and the next one, you'll use the remote state feature of HCP Terraform to store your state file in the cloud. In order to do this you'll need a HCP Terraform account. Click on the URL below and sign up for a free account if you don't have one already: - - https://app.terraform.io/signup/account - - If you already have an account you can simply sign in with your existing credentials. - - Once you're signed into HCP Terraform create a new organization called YOURNAME-training. Replace YOURNAME with your own name or other text. - - Next you'll be prompted to create a workspace. You can skip the VCS integration step by clicking the "CLI-driven workflow" panel. Name your workspace **hashicat-azure**. - - **Note:** If you already have a **hashicat-azure** workspace, please delete the workspace by selecting the **Settings >> Destruction and Deletion** menu, clicking the "Delete from HCP Terraform" button, typing "hashicat-azure" to confirm, and then clicking the "Delete workspace" button. Then re-create it as above. Doing this avoids possible problems with mis-matched state versions when executing local runs after having executed remote runs. This could happen if you played the [HCP Terraform with Azure](https://play.instruqt.com/hashicorp/tracks/terraform-cloud-azure) track and then played this track. - - Run `terraform version` on the "Shell" tab and then set the **Terraform Version** to match on the workspace's **Settings >> General** settings page. - - Also, change the **Execution Mode** to **Local**. - - Be sure to save your settings by clicking the "Save settings" button at the bottom of the page! This will allow us to run Terraform commands from our workstation with local variables, which we'll do in the next challenge. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -- slug: configure-remote-state - id: xp7nr8olx0kl - type: challenge - title: "\U0001F39B️ Configure Remote State" - teaser: | - The Terraform command line tool can store its state in HCP Terraform. All that is required is a user token. - notes: - - type: text - contents: |- - With *local* execution mode the Terraform commands and variables all remain - on your workstation. - - With *remote* execution mode Terraform runs in a HCP Terraform - container environment. All variables must be configured in the cloud environment with this method. - assignment: |- - During this challenge we'll configure HCP Terraform as a remote state backend, and then migrate our existing state file to HCP Terraform. - - Edit the "remote_backend.tf" file and replace the YOURORGANIZATION and YOURWORKSPACE placeholders with your org name and workspace name. Be sure to save the file. - - Let's generate a new **user token** for use on your workstation. Visit the User Settings > Tokens page in HCP Terraform: - - https://app.terraform.io/app/settings/tokens - - Click on the **Create an API token** button. You can name the token whatever you like. Copy the entire token using your mouse or the small copy-paste icon. - - Back in the Instruqt track, you need to add your API token to a file called "credentials.tfrc.json". Select the "Credentials File" tab and open the `/root/.terraform.d/credentials.tfrc.json` file directly. - - Replace the part that says YOURTOKEN with what you copied from HCP Terraform. Be sure to save the file. - - Your token is now safely stored in the `/root/.terraform.d/credentials.tfrc.json` file. - - Now run `terraform init` to migrate your state to HCP Terraform. - - ``` - terraform init - ``` - - Type "yes" when it prompts you to migrate your state to HCP Terraform. - - Your state is now safely stored in HCP Terraform. You can verify this on the "States" tab of your workspace in the TFC UI. - - Run a `terraform apply -auto-approve` and watch your state file evolve with each change. You can browse through previous state files with the HCP Terraform UI. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - - title: Credentials File - type: code - hostname: workstation - path: /root/.terraform.d/credentials.tfrc.json - difficulty: basic - timelimit: 1067 -- slug: terraform-destroy - id: yzj2xzspnngn - type: challenge - title: "\U0001F525 Terraform Destroy" - teaser: | - Terraform can build infrastructure and also destroy it when you are done using it. This helps control costs and reduce infrastructure sprawl. - notes: - - type: text - contents: |- - Terraform can destroy infrastructure as easily as it can build it. - - Use `terraform destroy` with caution. - assignment: |- - Run the following command to destroy your infrastructure: - - ``` - terraform destroy - ``` - - You'll need to type "yes" when prompted to destroy your infrastructure. This is a safety feature to help prevent accidental deletion of important resources. - - Wait until the destroy action has completely finished before clicking on the *Check* button. - - Depending on the version of Terraform you are using, it is possible that the destroy action will fail. That will be resolved in a future version of Terraform. - - Congratulations on completing the Intro to Terraform track! - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-azure - difficulty: basic - timelimit: 1067 -checksum: "16067465216838756912" +idle_timeout: 7200 +timelimit: 14400 +lab_config: + overlay: false + width: 33 + position: right + sidebar_enabled: true + feedback_recap_enabled: true + loadingMessages: true + hideStopButton: false +checksum: "11593833918721249270" diff --git a/instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/assignment.md b/instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/assignment.md new file mode 100755 index 00000000..458f73f6 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/assignment.md @@ -0,0 +1,39 @@ +--- +slug: setup-our-environment +id: lgixeqrwyhou +type: challenge +title: "\U0001F3E1 Moving in - Explore Your Workspace" +teaser: | + Explore the Terraform code for the hashicat application. +notes: +- type: text + contents: | + Setting up your environment... + Keep an eye on the bottom right corner to know when you can get started. +- type: text + contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD, + Windows, Solaris and Linux. +- type: text + contents: The Terraform language is designed to be both human and machine-readable. +- type: text + contents: Most modern code editors support Terraform syntax highlighting. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors. + +When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor! + +Throughout this track, please execute all commands on the "Shell" tab. + +Congratulations, you are ready to start working with Terraform on GCP. We'll use the hashicat-gcp example app in the rest of the challenges as you learn new Terraform skills. + +Click the **Check** button to continue. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/setup-our-environment/check-workstation b/instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/setup-our-environment/check-workstation rename to instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/setup-our-environment/setup-workstation b/instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/setup-our-environment/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/setup-our-environment/solve-workstation b/instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/setup-our-environment/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/01-setup-our-environment/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/02-hello-terraform/assignment.md b/instruqt-tracks/terraform-intro-gcp/02-hello-terraform/assignment.md new file mode 100755 index 00000000..20c4aa45 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/02-hello-terraform/assignment.md @@ -0,0 +1,48 @@ +--- +slug: hello-terraform +id: vkstvwcmd0g8 +type: challenge +title: "\U0001F44B Getting to Know Terraform" +teaser: | + Learn Terraform basics and command line syntax. +notes: +- type: text + contents: |- + Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation. + + It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html +- type: text + contents: |- + Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH. + + Check out this tutorial for step-by-step instructions: + + https://learn.hashicorp.com/terraform/getting-started/install.html + + We've pre-installed Terraform in your Instruqt lab environment for you. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Let's start with some basic Terraform commands. + +Run the following commands on the "Shell" tab. + +Check the version of Terraform running on your machine: +``` +terraform version +``` +You can always get help if you're curious about command syntax: +``` +terraform --help +``` +Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation. + +Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/hello-terraform/check-workstation b/instruqt-tracks/terraform-intro-gcp/02-hello-terraform/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/hello-terraform/check-workstation rename to instruqt-tracks/terraform-intro-gcp/02-hello-terraform/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/add-an-output/setup-workstation b/instruqt-tracks/terraform-intro-gcp/02-hello-terraform/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/add-an-output/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/02-hello-terraform/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/hello-terraform/solve-workstation b/instruqt-tracks/terraform-intro-gcp/02-hello-terraform/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/hello-terraform/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/02-hello-terraform/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/assignment.md b/instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/assignment.md new file mode 100755 index 00000000..fd8706c1 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/assignment.md @@ -0,0 +1,32 @@ +--- +slug: gcp-credentials +id: hztyb5p4qfdz +type: challenge +title: "\U0001F510 Connecting Terraform to GCP" +teaser: | + Connecting to GCP with Google Credentials. +notes: +- type: text + contents: Did you know HCL stands for "HashiCorp Configuration Language"? +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +In order to authenticate to GCP and build resources, Terraform requires you to provide a set of credentials, backed by an appropriate IAM policy. + +For this training environment, we have prepared some temporary GCP credentials and stored them as an environment variable. Terraform will automatically read and use the environment variables that are configured in your shell environment. + +Run the following command on the "Shell" tab: + +``` +echo $GOOGLE_CREDENTIALS | jq +``` + +*Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/gcp-credentials/check-workstation b/instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/gcp-credentials/check-workstation rename to instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/add-virtual-network/setup-workstation b/instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/add-virtual-network/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/gcp-credentials/solve-workstation b/instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/gcp-credentials/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/03-gcp-credentials/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/04-terraform-code/assignment.md b/instruqt-tracks/terraform-intro-gcp/04-terraform-code/assignment.md new file mode 100755 index 00000000..5cdc0bca --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/04-terraform-code/assignment.md @@ -0,0 +1,40 @@ +--- +slug: terraform-code +id: tpglkqtsjynb +type: challenge +title: "\U0001F468‍\U0001F4BB What does Terraform code look like?" +teaser: | + The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure. +notes: +- type: text + contents: |- + Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`. + + By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files. + + You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files: + ``` + ls *.tf + ``` + + The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon. + + Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first: + + **main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.
+ **variables.tf** - Use this file to define which variables will be available to your users.
+ **outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run. + + Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-cloud-setup/check-workstation b/instruqt-tracks/terraform-intro-gcp/04-terraform-code/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-cloud-setup/check-workstation rename to instruqt-tracks/terraform-intro-gcp/04-terraform-code/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/change-prefix/setup-workstation b/instruqt-tracks/terraform-intro-gcp/04-terraform-code/setup-workstation old mode 100644 new mode 100755 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/change-prefix/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/04-terraform-code/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/configure-remote-state/solve-workstation b/instruqt-tracks/terraform-intro-gcp/04-terraform-code/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/configure-remote-state/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/04-terraform-code/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/assignment.md b/instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/assignment.md new file mode 100755 index 00000000..8c05b746 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/assignment.md @@ -0,0 +1,42 @@ +--- +slug: terraform-init-provider +id: 1tmqjwbq0gzb +type: challenge +title: "\U0001F3E1 Terraform Init - Install the Providers" +teaser: | + Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers. +notes: +- type: text + contents: |- + The Terraform core program isn't very useful by itself. Terraform needs the help of a *provider* to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here: + + https://registry.terraform.io/browse/providers + + Today we'll be using a few different providers, but the main one is the *gcp* provider. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track. + +Before we can do anything with Terraform we need to initialize our workspace. Run the following command on your "Shell" tab: +``` +terraform init +``` + +The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them. + +Run the following command to verify that the google provider was installed under the ".terraform" directory:: + +``` +ls .terraform/providers/registry.terraform.io/hashicorp +``` + +This hidden directory is where all modules and plugins are stored. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-init-provider/check-workstation b/instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-init-provider/check-workstation rename to instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/configure-remote-state/setup-workstation b/instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/setup-workstation old mode 100644 new mode 100755 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/configure-remote-state/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-init-provider/solve-workstation b/instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-init-provider/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/05-terraform-init-provider/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/06-provider-quiz/assignment.md b/instruqt-tracks/terraform-intro-gcp/06-provider-quiz/assignment.md new file mode 100755 index 00000000..f3b96a29 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/06-provider-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: provider-quiz +id: vbzfisfntndh +type: quiz +title: "\U0001F4DD Quiz 1 - Providers and Modules" +teaser: | + A quiz about Terraform init +notes: +- type: text + contents: | + It's quiz time! +answers: +- In the /tmp directory +- In the user's home directory +- In the .terraform directory +- None of the above +solution: +- 2 +difficulty: basic +timelimit: 10000 +--- +Where does Terraform store its modules and providers? diff --git a/instruqt-tracks/terraform-intro-gcp/07-terraform-validate/assignment.md b/instruqt-tracks/terraform-intro-gcp/07-terraform-validate/assignment.md new file mode 100755 index 00000000..9ef95a16 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/07-terraform-validate/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-validate +id: wpomfkdruvrh +type: challenge +title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code" +teaser: | + Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly. +notes: +- type: text + contents: Terraform has a built-in syntax checker. You can run it with the `terraform + validate` command. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Terraform comes with a built-in subcommand called *validate*. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly. + +Edit the main.tf file and remove the double quotes between `google_compute_network` and `hashicat` on line 15 of the file, keeping the space that was between them. Save the file. + +Validate your code: + +``` +terraform validate +``` + +Now put the double quotes back in line 15, save the file, and run the `validate` command again. This time you should pass the validation test. + +`terraform validate` is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-validate/check-workstation b/instruqt-tracks/terraform-intro-gcp/07-terraform-validate/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-validate/check-workstation rename to instruqt-tracks/terraform-intro-gcp/07-terraform-validate/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/fun-with-variables/setup-workstation b/instruqt-tracks/terraform-intro-gcp/07-terraform-validate/setup-workstation old mode 100644 new mode 100755 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/fun-with-variables/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/07-terraform-validate/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-validate/solve-workstation b/instruqt-tracks/terraform-intro-gcp/07-terraform-validate/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-validate/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/07-terraform-validate/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/08-terraform-plan/assignment.md b/instruqt-tracks/terraform-intro-gcp/08-terraform-plan/assignment.md new file mode 100755 index 00000000..7a6803a4 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/08-terraform-plan/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-plan +id: gzvxbsat7fvn +type: challenge +title: "\U0001F914 Terraform Plan - Dry Run Mode" +teaser: | + Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run `terraform plan` and view the output. +notes: +- type: text + contents: |- + `terraform plan` allows you to preview any changes to your environment in a safe way. + + This can help you identify any unexpected changes before you deploy them, not after they are already built. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Run the `terraform plan` command: + +``` +terraform plan +``` + +When you run this command Terraform will prompt you to enter the `prefix` variable. + +Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name. + +The prefix will become part of the name for our VPC network, subnet, and compute instance, as well as appear in the HashiCat application. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-plan/check-workstation b/instruqt-tracks/terraform-intro-gcp/08-terraform-plan/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-plan/check-workstation rename to instruqt-tracks/terraform-intro-gcp/08-terraform-plan/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/gcp-credentials/setup-workstation b/instruqt-tracks/terraform-intro-gcp/08-terraform-plan/setup-workstation old mode 100644 new mode 100755 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/gcp-credentials/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/08-terraform-plan/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-plan/solve-workstation b/instruqt-tracks/terraform-intro-gcp/08-terraform-plan/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-plan/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/08-terraform-plan/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/09-terraform-variables/assignment.md b/instruqt-tracks/terraform-intro-gcp/09-terraform-variables/assignment.md new file mode 100755 index 00000000..7dae9df8 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/09-terraform-variables/assignment.md @@ -0,0 +1,29 @@ +--- +slug: terraform-variables +id: kuax8jmre5nc +type: challenge +title: "\U0001F39B️ Working with Terraform Variables" +teaser: | + Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables. +notes: +- type: text + contents: The `terraform.tfvars` file is a convenient place for users to configure + their variables. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later. + +Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case). + +**Be sure to click the disk icon above the file to save your change!** + +Now run `terraform plan` again. This time you won't have to enter your prefix manually. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-variables/check-workstation b/instruqt-tracks/terraform-intro-gcp/09-terraform-variables/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-variables/check-workstation rename to instruqt-tracks/terraform-intro-gcp/09-terraform-variables/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/hello-terraform/setup-workstation b/instruqt-tracks/terraform-intro-gcp/09-terraform-variables/setup-workstation old mode 100644 new mode 100755 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/hello-terraform/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/09-terraform-variables/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-variables/solve-workstation b/instruqt-tracks/terraform-intro-gcp/09-terraform-variables/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-variables/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/09-terraform-variables/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/assignment.md b/instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/assignment.md new file mode 100755 index 00000000..8f5b8ee5 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/assignment.md @@ -0,0 +1,43 @@ +--- +slug: terraform-add-a-variable +id: kxgqco4wtufz +type: challenge +title: "\U0001F5FC Change Your Location" +teaser: | + Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable. +notes: +- type: text + contents: |- + You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file. + + In this challenge, you will pick the location where your GCP resources should be deployed. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set two more variables that will determine the location where your GCP infrastructure will be deployed. + +First run another plan so you'll be able to compare what happens after you change the location. + +``` +terraform plan +``` + +Choose a GCP region near you but different from the default one which is "us-central1". Add `region` and `zone` variables to your "terraform.tfvars" file, setting them to your desired region and one of its zones. + +See this [page](https://cloud.google.com/compute/docs/regions-zones) for a list of regions and zones. For regions, strip off the `-a`, `-b`, or `-c` from the zones listed on that page. + +Choosing a region close to you can help improve speed and performance. + +**Be sure to click the disk icon above the file to save your change!** + +Once you've set your `region` and `zone` variables, try running `terraform plan` again. What's different this time? + +Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-add-a-variable/check-workstation b/instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-add-a-variable/check-workstation rename to instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-add-a-variable/setup-workstation b/instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-add-a-variable/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-add-a-variable/solve-workstation b/instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-add-a-variable/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/10-terraform-add-a-variable/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/11-variables-quiz/assignment.md b/instruqt-tracks/terraform-intro-gcp/11-variables-quiz/assignment.md new file mode 100755 index 00000000..3ecdad29 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/11-variables-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: variables-quiz +id: kzf8rq7yelxr +type: quiz +title: "\U0001F4DD Quiz 2 - Variables" +teaser: | + A quiz about Terraform variables +notes: +- type: text + contents: | + Another quiz, get ready! +answers: +- On the command line +- As environment variables +- In the variables.tf file +- In the terraform.tfvars file +solution: +- 2 +difficulty: basic +timelimit: 10000 +--- +Where are terraform variables usually *declared*? diff --git a/instruqt-tracks/terraform-intro-gcp/12-tf-graph/assignment.md b/instruqt-tracks/terraform-intro-gcp/12-tf-graph/assignment.md new file mode 100755 index 00000000..149f1633 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/12-tf-graph/assignment.md @@ -0,0 +1,46 @@ +--- +slug: tf-graph +id: qyfat6fbn9oy +type: challenge +title: "\U0001F4C8 Terraform Graph" +teaser: | + Terraform creates a graph of all the infrastructure defined in your code. +notes: +- type: text + contents: Terraform Graph can provide a visual representation of all your infrastructure. + This is handy for finding dependency issues or resources that will be affected + by a change. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Terraform Graph + type: service + hostname: workstation + port: 5000 +difficulty: basic +timelimit: 10000 +--- +Try running the `terraform graph` command: + +``` +terraform graph +``` + +This generates code that can be used to create a visual map of your infrastructure. The graph data is in [DOT graph description language format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). There are several graphing tools you can use to visualize this data, including the free Blast Radius tool. You can learn more about Blast Radius here: + +https://28mm.github.io/blast-radius-docs/ + +Start up a Blast Radius server with the following command: + +``` +blast-radius --serve . +``` + +Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon in Instruqt, which is directly to the right of the **Terraform Graph** tab and looks like a circular arrow. + +Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. + +**NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. + +Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph/check-workstation b/instruqt-tracks/terraform-intro-gcp/12-tf-graph/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph/check-workstation rename to instruqt-tracks/terraform-intro-gcp/12-tf-graph/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph/cleanup-workstation b/instruqt-tracks/terraform-intro-gcp/12-tf-graph/cleanup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph/cleanup-workstation rename to instruqt-tracks/terraform-intro-gcp/12-tf-graph/cleanup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-code/setup-workstation b/instruqt-tracks/terraform-intro-gcp/12-tf-graph/setup-workstation old mode 100755 new mode 100644 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-code/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/12-tf-graph/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph/solve-workstation b/instruqt-tracks/terraform-intro-gcp/12-tf-graph/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/12-tf-graph/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/13-tf-apply/assignment.md b/instruqt-tracks/terraform-intro-gcp/13-tf-apply/assignment.md new file mode 100755 index 00000000..4e5bfa55 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/13-tf-apply/assignment.md @@ -0,0 +1,43 @@ +--- +slug: tf-apply +id: yimyuso20nfh +type: challenge +title: "\U0001F468‍\U0001F4BB Terraform Plan and Apply" +teaser: | + The `terraform plan` command can be run anytime to get a preview of changes that Terraform might make. When you run Terraform apply these changes are implemented, and Terraform builds, updates, or destroys resources. +notes: +- type: text + contents: |- + By default, the `terraform apply` command runs a Terraform plan to show you what changes it wants to make. + + Terraform maps out all the changes it needs to make before applying them. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Now that we've configured our required prefix variable we can apply our Terraform configuration. + +Run the `terraform plan` command first to see what will happen: + +``` +terraform plan +``` + +Confirm the proper prefix is displayed in the plan output. Look for **# google_compute_network.hashicat** and find the output next to **+ name**. + +Then run `terraform apply` and watch your resources being built. + +``` +terraform apply +``` + +You'll need to enter **yes** when Terraform prompts you with the "Do you want to perform these actions?" question. + +Right now our code only defines a VPC network. We'll be building upon this starting point in the next challenge. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/tf-apply/check-workstation b/instruqt-tracks/terraform-intro-gcp/13-tf-apply/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-apply/check-workstation rename to instruqt-tracks/terraform-intro-gcp/13-tf-apply/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-destroy/setup-workstation b/instruqt-tracks/terraform-intro-gcp/13-tf-apply/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-destroy/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/13-tf-apply/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-apply/solve-workstation b/instruqt-tracks/terraform-intro-gcp/13-tf-apply/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-apply/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/13-tf-apply/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/assignment.md b/instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/assignment.md new file mode 100755 index 00000000..45344c52 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/assignment.md @@ -0,0 +1,43 @@ +--- +slug: tf-plan-again +id: sluciwzl49xm +type: challenge +title: "\U0001F469‍\U0001F4BB Test and Repair" +teaser: | + Terraform is idempotent. Each resource in your code will be examined, and if it already exists Terraform will leave it alone. +notes: +- type: text + contents: |- + Terraform is an *idempotent* application. + + Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. + + https://en.wikipedia.org/wiki/Idempotence +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Try running `terraform plan` again and see what happens: + +``` +terraform plan +``` + +Since your VPC network has already been built, Terraform will report that there are no changes required. + +This is normal and expected. + +Now try running another apply: + +``` +terraform apply +``` + +Terraform checks each resource to ensure it is in the proper state. It will not re-create your VPC network if it is already provisioned correctly. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/tf-plan-again/check-workstation b/instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-plan-again/check-workstation rename to instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-plan-again/setup-workstation b/instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-plan-again/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-plan-again/solve-workstation b/instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-plan-again/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/14-tf-plan-again/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/15-change-prefix/assignment.md b/instruqt-tracks/terraform-intro-gcp/15-change-prefix/assignment.md new file mode 100755 index 00000000..05036748 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/15-change-prefix/assignment.md @@ -0,0 +1,35 @@ +--- +slug: change-prefix +id: yjsglftylvrr +type: challenge +title: "\U0001F6EB Change Your Prefix" +teaser: | + When your Terraform code changes, your infrastructure will be modified to match the updated code. Terraform is a declarative language. +notes: +- type: text + contents: |- + Terraform can create, destroy, update in place, or destroy and re-create your infrastructure. Some types of resources can be updated without deleting them. Major changes usually require a teardown and rebuild. + + Terraform always tries to match the current infrastructure to what has been defined in your code. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Edit the `terraform.tfvars` file to change your prefix. You could simply add a number to the end if you like. Or change it to something entirely new. + +Save the `terraform.tfvars` file and run your apply command again. + +``` +terraform apply +``` + +Type "yes" when prompted. + +Observe the output. What happened? \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/change-prefix/check-workstation b/instruqt-tracks/terraform-intro-gcp/15-change-prefix/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/change-prefix/check-workstation rename to instruqt-tracks/terraform-intro-gcp/15-change-prefix/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-init-provider/setup-workstation b/instruqt-tracks/terraform-intro-gcp/15-change-prefix/setup-workstation old mode 100755 new mode 100644 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-init-provider/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/15-change-prefix/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/change-prefix/solve-workstation b/instruqt-tracks/terraform-intro-gcp/15-change-prefix/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/change-prefix/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/15-change-prefix/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/assignment.md b/instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/assignment.md new file mode 100755 index 00000000..7de6a03e --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/assignment.md @@ -0,0 +1,32 @@ +--- +slug: add-virtual-network +id: 3hezzcpy2grz +type: challenge +title: "\U0001F5A7 Add a Virtual Network" +teaser: | + Terraform resources are like building blocks. You can continue adding more blocks until your infrastructure reaches the desired state. +notes: +- type: text + contents: Terraform code can be built incrementally, one or two resources at a time. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Open the **main.tf** file again and uncomment the next resource block in the file. The type of resource is **google_compute_subnetwork** and it is named **hashicat**. + +Uncomment the code by removing the `#` characters from the beginning of each line. Be sure to save the file. + +Now run `terraform plan` and observe the results. + +Look at the **network** parameter inside the google_compute_subnetwork resource. See how it points back at the first resource in the file? The subnet resource inherits settings from the VPC network. + +Terraform can map out the complex web of dependencies between hundreds of interconnected resources. + +Finally, create your Virtual Network. Run `terraform apply` and answer "yes" when prompted. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/add-virtual-network/check-workstation b/instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/add-virtual-network/check-workstation rename to instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-plan/setup-workstation b/instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/setup-workstation old mode 100755 new mode 100644 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-plan/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/add-virtual-network/solve-workstation b/instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/add-virtual-network/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/16-add-virtual-network/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/17-complete-the-build/assignment.md b/instruqt-tracks/terraform-intro-gcp/17-complete-the-build/assignment.md new file mode 100755 index 00000000..abd3f1d0 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/17-complete-the-build/assignment.md @@ -0,0 +1,39 @@ +--- +slug: complete-the-build +id: uakhtx5pzoum +type: challenge +title: "\U0001F3D7️ Complete the Build" +teaser: | + Terraform code can stand up everything from a GCP project, to virtual networks, to VMs and containers. +notes: +- type: text + contents: The `-auto-approve` flag can be used to override the "Are you sure?" questions + that appear before an apply or destroy. Use with caution! +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +We've uncommented the rest of the Terraform code in the **main.tf** file for you. Run a `terraform plan` to see what will be built: + +``` +terraform plan +``` + +Now run an apply to build the HashiCat application: + +``` +terraform apply -auto-approve +``` + +It can take up to five minutes for the application to finish deploying. You will know it is complete when you see the Terraform output with your application URL at the end of the run. + +If the application won't load just run `terraform apply` again. This will attempt to reinstall the webserver and start your application if it's not running. + +Open your web application in a new browser tab by clicking on the URL in the `catapp_url` output. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/complete-the-build/check-workstation b/instruqt-tracks/terraform-intro-gcp/17-complete-the-build/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/complete-the-build/check-workstation rename to instruqt-tracks/terraform-intro-gcp/17-complete-the-build/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/complete-the-build/setup-workstation b/instruqt-tracks/terraform-intro-gcp/17-complete-the-build/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/complete-the-build/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/17-complete-the-build/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/complete-the-build/solve-workstation b/instruqt-tracks/terraform-intro-gcp/17-complete-the-build/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/complete-the-build/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/17-complete-the-build/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/assignment.md b/instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/assignment.md new file mode 100755 index 00000000..8e581cac --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/assignment.md @@ -0,0 +1,34 @@ +--- +slug: tf-graph-again +id: v2zbg7zfapfo +type: challenge +title: "\U0001F4C8 Terraform Graph" +teaser: | + Revisit graph to see what has changed. +notes: +- type: text + contents: Let's revisit our graph to see what has changed. +tabs: +- title: Command Line + type: terminal + hostname: workstation +- title: Terraform Graph + type: service + hostname: workstation + port: 5000 +difficulty: basic +timelimit: 10000 +--- +Start up a Blast Radius server with the following command: + +``` +blast-radius --serve . +``` + +Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon in Instruqt, which is directly to the right of the **Terraform Graph** tab and looks like a circular arrow. + +Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. + +**NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. + +Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-code/check-workstation b/instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-code/check-workstation rename to instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-validate/setup-workstation b/instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/setup-workstation old mode 100755 new mode 100644 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-validate/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/fun-with-variables/solve-workstation b/instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/fun-with-variables/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/18-tf-graph-again/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/19-terraform-apply-quiz/assignment.md b/instruqt-tracks/terraform-intro-gcp/19-terraform-apply-quiz/assignment.md new file mode 100755 index 00000000..b091748f --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/19-terraform-apply-quiz/assignment.md @@ -0,0 +1,22 @@ +--- +slug: terraform-apply-quiz +id: x5nbcusy5g6g +type: quiz +title: "\U0001F4DD Quiz 3 - Terraform Apply" +teaser: | + What happens when you run `terraform apply` without a plan file? +notes: +- type: text + contents: | + It's quiz time! +answers: +- Terraform runs without any plan +- Terraform reads the previous plan and then applies it +- Terraform runs a new plan right before the apply +- None of the above +solution: +- 2 +difficulty: basic +timelimit: 10000 +--- +What happens when you run `terraform apply` without specifying a plan file? diff --git a/instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/assignment.md b/instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/assignment.md new file mode 100755 index 00000000..8e12ffcc --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/assignment.md @@ -0,0 +1,59 @@ +--- +slug: use-a-provisioner +id: 75ne46lncukj +type: challenge +title: "\U0001F6E0️ Use a Provisioner" +teaser: | + Terraform works great with many different provisioning tools including Chef, Puppet, Ansible, Bash, and Powershell. +notes: +- type: text + contents: Terraform provisioners run once at creation time. They do not run on subsequent + applies, except in special circumstances. (Like this training lab...) +- type: text + contents: We've made some special adjustments to force the provisioner to run every + time you type terraform apply. This is so you can practice playing with provisioners + without destroying and recreating your virtual machine every time you make a change. +- type: text + contents: |- + ``` + ______________________ + < Cows love Terraform! > + ---------------------- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || || + ============================= + ``` +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Open the `main.tf` file on the "Code Editor" tab. Scroll down until you find the `remote-exec` provisioner block. + +Add the following two lines at the end of the inline list of commands: + +``` +"sudo apt -y install cowsay", +"cowsay Mooooooooooo!", +``` + +After copying them into your buffer, it will be easier to paste them if you hide the assignment by clicking the ">" icon . Click it again to redisplay the assignment. Be sure to save the file. + +This might be a good time to use the `terraform fmt` command to line up the commands nicely. + +Now apply your changes: + +``` +terraform apply -auto-approve +``` + +Scroll back through the log output. You should see an ASCII art cow saying "Moooooooo!" \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/use-a-provisioner/check-workstation b/instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/use-a-provisioner/check-workstation rename to instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-variables/setup-workstation b/instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/setup-workstation old mode 100755 new mode 100644 similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-variables/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/use-a-provisioner/solve-workstation b/instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/use-a-provisioner/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/20-use-a-provisioner/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/21-add-an-output/assignment.md b/instruqt-tracks/terraform-intro-gcp/21-add-an-output/assignment.md new file mode 100755 index 00000000..15af4d9a --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/21-add-an-output/assignment.md @@ -0,0 +1,55 @@ +--- +slug: add-an-output +id: ci9mcysfqxga +type: challenge +title: "\U0001F5A8️ Add an Output" +teaser: | + Outputs are used to convey useful information such as IP addresses, application URLs or other useful data. +notes: +- type: text + contents: You can mix plain text along with Terraform data in your outputs. Outputs + can be used to convey useful information to your users at the end of a run. +- type: text + contents: The `terraform refresh` command will sync your state file with what exists + in your infrastructure. A refresh command will not change your infrastructure. +- type: text + contents: The `terraform output` command can be run any time you want to see your + Terraform outputs again. Run `terraform output ` to view a single + output. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Open the **outputs.tf** file on the "Code Editor" tab. Note the catapp_url output in the file. + +Add a second output for the `network_ip` of your web server. It's going to look a lot like the first output but will instead output the internal IP address instead of the external one. + +Name your output `catapp_ip`. + +You may refer to the docs page to see what types of outputs are valid: + +[Terraform GCP Docs - Click Here](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#attributes-reference) +[Terraform Outputs Docs - Click Here](https://www.terraform.io/docs/configuration/outputs.html) + +Be sure to save the changes to the **outputs.tf** file. + +Run the Terraform refresh command to view your new output: + +``` +terraform refresh +``` + +You can run the Terraform output command to view all your outputs: + +``` +terraform output +``` + +Unfortunately, you cannot use the URL with the internal IP to access the web app since your browser is not within the internal GCP network. But you can use the public URL shown in the `catapp_url` output. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/add-an-output/check-workstation b/instruqt-tracks/terraform-intro-gcp/21-add-an-output/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/add-an-output/check-workstation rename to instruqt-tracks/terraform-intro-gcp/21-add-an-output/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-apply/setup-workstation b/instruqt-tracks/terraform-intro-gcp/21-add-an-output/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-apply/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/21-add-an-output/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/add-an-output/solve-workstation b/instruqt-tracks/terraform-intro-gcp/21-add-an-output/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/add-an-output/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/21-add-an-output/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/assignment.md b/instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/assignment.md new file mode 100755 index 00000000..91ed2282 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/assignment.md @@ -0,0 +1,65 @@ +--- +slug: fun-with-variables +id: eohaq0hbcfbw +type: challenge +title: "\U0001F436 Fun With Variables" +teaser: | + Variables give the consumers of your Terraform code an easy way to customize their infrastructure. +notes: +- type: text + contents: |- + Terraform variables have five levels of precedence. 1=highest 5=lowest: + + 1. Command line flag - run as a command line switch + 1. Configuration file - set in your terraform.tfvars file + 1. Environment variable - part of your shell environment + 1. Default Config - default value in variables.tf + 1. User manual entry - if not specified, prompt the user for entry +- type: text + contents: |- + Here are some other fun placeholder sites you can try with the **placeholder** variable: + + placedog.net
+ placebear.com
+ www.fillmurray.com
+ www.placecage.com
+ placebeard.it
+ loremflickr.com
+ baconmockup.com
+ placeimg.com
+tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +There are several ways to configure Terraform variables. So far we've been using the `terraform.tfvars` file to set our variables. Try re-deploying your application with different **height** and **width** variables on the command line. Reload the webapp after each apply to observe any changes. + +``` +terraform apply -auto-approve -var height=600 -var width=800 +``` + +Next try setting an environment variable that Terraform can read. Run this command to set the placeholder variable: + +``` +export TF_VAR_placeholder=placedog.net +``` + +Run another `apply` command: +``` +terraform apply -auto-approve +``` + +Now try it again with the same variable set differently on the command line: +``` +terraform apply -auto-approve -var placeholder=placebear.com +``` + +Which variable took precedence? Why? + +See this [doc](https://www.terraform.io/docs/configuration/variables.html#variable-definition-precedence) if you're unsure. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/configure-remote-state/check-workstation b/instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/configure-remote-state/check-workstation rename to instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph-again/setup-workstation b/instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph-again/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-cloud-setup/solve-workstation b/instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-cloud-setup/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/22-fun-with-variables/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/23-terraform-variables-quiz/assignment.md b/instruqt-tracks/terraform-intro-gcp/23-terraform-variables-quiz/assignment.md new file mode 100755 index 00000000..d6bd56dd --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/23-terraform-variables-quiz/assignment.md @@ -0,0 +1,20 @@ +--- +slug: terraform-variables-quiz +id: 7gyk9wzbzado +type: quiz +title: "\U0001F4DD Quiz 4 - Terraform Variables" +teaser: | + How do Terraform variables get set or overridden? +notes: +- type: text + contents: | + Get ready for another quiz... +answers: +- The environment variable +- The tfvars config file +solution: +- 1 +difficulty: basic +timelimit: 10000 +--- +You have the same variable set in a *.tfvars file and as an environment variable. Which one takes precedence? diff --git a/instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/assignment.md b/instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/assignment.md new file mode 100755 index 00000000..b9933114 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/assignment.md @@ -0,0 +1,38 @@ +--- +slug: hcp-terraform-setup +id: usdxwvxm4qbo +type: challenge +title: ☁️ HCP Terraform Setup +teaser: | + HCP Terraform offers unlimited free Terraform state storage for users. Safeguard your state files by storing them remotely in HCP Terraform. +notes: +- type: text + contents: HCP Terraform remote state storage is free for all users. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +During this challenge and the next one, you'll use the remote state feature of HCP Terraform to store your state file in the cloud. In order to do this you'll need a HCP Terraform account. Click on the URL below and sign up for a free account if you don't have one already: + +https://app.terraform.io/signup/account + +If you already have an account you can simply sign in with your existing credentials. + +Once you're signed into HCP Terraform create a new organization called YOURNAME-training. Replace YOURNAME with your own name or other text. + +Next you'll be prompted to create a workspace. You can skip the VCS integration step by clicking the "CLI-driven workflow" panel. Name your workspace **hashicat-gcp**. + +**Note:** If you already have a **hashicat-gcp** workspace, please delete the workspace by selecting the **Settings >> Destruction and Deletion** menu, clicking the "Delete from HCP Terraform" button, typing "hashicat-gcp" to confirm, and then clicking the "Delete workspace" button. Then re-create it as above. Doing this avoids possible problems with mis-matched state versions when executing local runs after having executed remote runs. This could happen if you played the [HCP Terraform with GCP](https://play.instruqt.com/hashicorp/tracks/terraform-cloud-gcp) track and then played this track. + +Run `terraform version` on the "Shell" tab and then set the **Terraform Version** to match on the workspace's **Settings >> General** settings page. + +Also, change the **Execution Mode** to **Local**. + +Be sure to save your settings by clicking the "Save settings" button at the bottom of the page! This will allow us to run Terraform commands from our workstation with local variables, which we'll do in the next challenge. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph-again/check-workstation b/instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph-again/check-workstation rename to instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-cloud-setup/setup-workstation b/instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-cloud-setup/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-code/solve-workstation b/instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-code/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/24-hcp-terraform-setup/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/assignment.md b/instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/assignment.md new file mode 100755 index 00000000..7ab63286 --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/assignment.md @@ -0,0 +1,57 @@ +--- +slug: configure-remote-state +id: lupzdaszexnz +type: challenge +title: "\U0001F39B️ Configure Remote State" +teaser: | + The terraform command line tool can store its state in HCP Terraform. All that is required is a user token. +notes: +- type: text + contents: |- + With *local* execution mode the Terraform commands and variables all remain + on your workstation. + + With *remote* execution mode Terraform runs in a HCP Terraform + container environment. All variables must be configured in the cloud environment with this method. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +- title: Credentials File + type: code + hostname: workstation + path: /root/.terraform.d/credentials.tfrc.json +difficulty: basic +timelimit: 10000 +--- +During this challenge we'll configure HCP Terraform as a remote state backend, and then migrate our existing state file to HCP Terraform. + +Edit the "remote_backend.tf" file and replace the YOURORGANIZATION and YOURWORKSPACE placeholders with your org name and workspace name. Be sure to save the file. + +Let's generate a new **user token** for use on your workstation. Visit the User Settings > Tokens page in HCP Terraform: + +https://app.terraform.io/app/settings/tokens + +Click on the **Create an API token** button. You can name the token whatever you like. Copy the entire token using your mouse or the small copy-paste icon. + +Back in the Instruqt track, you need to add your API token to a file called "credentials.tfrc.json". Select the "Credentials File" tab and open the `/root/.terraform.d/credentials.tfrc.json` file directly. + +Replace the part that says YOURTOKEN with what you copied from HCP Terraform. Be sure to save the file. + +Your token is now safely stored in the `/root/.terraform.d/credentials.tfrc.json` file. + +Now run `terraform init` to migrate your state to HCP Terraform. + +``` +terraform init +``` + +Type "yes" when it prompts you to migrate your state into HCP Terraform. + +Your state is now safely stored in HCP Terraform. You can verify this on the "States" tab of your workspace in the TFC UI. + +Run a `terraform apply -auto-approve` and watch your state file evolve with each change. You can browse through previous state files with the HCP Terraform UI. \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/fun-with-variables/check-workstation b/instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/fun-with-variables/check-workstation rename to instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph/setup-workstation b/instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/tf-graph-again/solve-workstation b/instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/tf-graph-again/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/25-configure-remote-state/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/assignment.md b/instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/assignment.md new file mode 100755 index 00000000..85f56e6a --- /dev/null +++ b/instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/assignment.md @@ -0,0 +1,35 @@ +--- +slug: terraform-destroy +id: qyylxg2s3kps +type: challenge +title: "\U0001F525 Terraform Destroy" +teaser: | + Terraform can build infrastructure and also destroy it when you are done using it. This helps control costs and reduce infrastructure sprawl. +notes: +- type: text + contents: |- + Terraform can destroy infrastructure as easily as it can build it. + + Use `terraform destroy` with caution. +tabs: +- title: Shell + type: terminal + hostname: workstation +- title: Code Editor + type: code + hostname: workstation + path: /root/hashicat-gcp +difficulty: basic +timelimit: 10000 +--- +Run the following command to destroy your infrastructure: + +``` +terraform destroy +``` + +You'll need to type "yes" when prompted to destroy your infrastructure. This is a safety feature to help prevent accidental deletion of important resources. + +Wait until the destroy action has completely finished before clicking on the **Check** button. + +Congratulations on completing the Intro to Terraform track! \ No newline at end of file diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-destroy/check-workstation b/instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/check-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-destroy/check-workstation rename to instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/check-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/use-a-provisioner/setup-workstation b/instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/setup-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/use-a-provisioner/setup-workstation rename to instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/setup-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/terraform-destroy/solve-workstation b/instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/solve-workstation similarity index 100% rename from instruqt-tracks/terraform-intro-gcp/terraform-destroy/solve-workstation rename to instruqt-tracks/terraform-intro-gcp/26-terraform-destroy/solve-workstation diff --git a/instruqt-tracks/terraform-intro-gcp/config.yml b/instruqt-tracks/terraform-intro-gcp/config.yml index b94a1f4d..52cef9d5 100644 --- a/instruqt-tracks/terraform-intro-gcp/config.yml +++ b/instruqt-tracks/terraform-intro-gcp/config.yml @@ -1,7 +1,7 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -version: "2" +version: "3" virtualmachines: - name: workstation image: instruqt-hashicorp/ubuntu-2004-base diff --git a/instruqt-tracks/terraform-intro-gcp/track.yml b/instruqt-tracks/terraform-intro-gcp/track.yml index 60683d34..00ace86f 100644 --- a/instruqt-tracks/terraform-intro-gcp/track.yml +++ b/instruqt-tracks/terraform-intro-gcp/track.yml @@ -1,9 +1,5 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -slug: terraform-intro-gcp -id: jlcgrqwafq5m -type: track +slug: wip-vcdl-846-terraform-intro-gcp +id: dx3wcf4lubqm title: Intro to Terraform on GCP teaser: | Provision the HashiCat application on GCP using Terraform. @@ -16,999 +12,20 @@ tags: - terraform - gcp - basics -owner: hashicorp +owner: hashicorp-field-ops developers: -- roger@hashicorp.com - sean.carolan@hashicorp.com -private: true -published: true +- roger@hashicorp.com +- syed.quadri@hashicorp.com show_timer: true -challenges: -- slug: setup-our-environment - id: 2by1ixywkvlq - type: challenge - title: "\U0001F3E1 Moving in - Explore Your Workspace" - teaser: | - Explore the Terraform code for the hashicat application. - notes: - - type: text - contents: | - Setting up your environment... - Keep an eye on the bottom right corner to know when you can get started. - - type: text - contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD, - Windows, Solaris and Linux. - - type: text - contents: The Terraform language is designed to be both human and machine-readable. - - type: text - contents: Most modern code editors support Terraform syntax highlighting. - assignment: |- - Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors. - - When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor! - - Throughout this track, please execute all commands on the "Shell" tab. - - Congratulations, you are ready to start working with Terraform on GCP. We'll use the hashicat-gcp example app in the rest of the challenges as you learn new Terraform skills. - - Click the **Check** button to continue. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: hello-terraform - id: ujyae3lfhqrv - type: challenge - title: "\U0001F44B Getting to Know Terraform" - teaser: | - Learn Terraform basics and command line syntax. - notes: - - type: text - contents: |- - Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation. - - It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html - - type: text - contents: |- - Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH. - - Check out this tutorial for step-by-step instructions: - - https://learn.hashicorp.com/terraform/getting-started/install.html - - We've pre-installed Terraform in your Instruqt lab environment for you. - assignment: |- - Let's start with some basic Terraform commands. - - Run the following commands on the "Shell" tab. - - Check the version of Terraform running on your machine: - ``` - terraform version - ``` - You can always get help if you're curious about command syntax: - ``` - terraform --help - ``` - Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation. - - Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: gcp-credentials - id: aqiamevzkfm8 - type: challenge - title: "\U0001F510 Connecting Terraform to GCP" - teaser: | - Connecting to GCP with Google Credentials. - notes: - - type: text - contents: Did you know HCL stands for "HashiCorp Configuration Language"? - assignment: |- - In order to authenticate to GCP and build resources, Terraform requires you to provide a set of credentials, backed by an appropriate IAM policy. - - For this training environment, we have prepared some temporary GCP credentials and stored them as an environment variable. Terraform will automatically read and use the environment variables that are configured in your shell environment. - - Run the following command on the "Shell" tab: - - ``` - echo $GOOGLE_CREDENTIALS | jq - ``` - - *Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: terraform-code - id: n0jlhcovbfvv - type: challenge - title: "\U0001F468‍\U0001F4BB What does Terraform code look like?" - teaser: | - The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure. - notes: - - type: text - contents: |- - Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`. - - By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files. - - You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`. - assignment: |- - We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files: - ``` - ls *.tf - ``` - - The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon. - - Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first: - - **main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.
- **variables.tf** - Use this file to define which variables will be available to your users.
- **outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run. - - Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: terraform-init-provider - id: wjpdqpbyj9kv - type: challenge - title: "\U0001F3E1 Terraform Init - Install the Providers" - teaser: | - Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers. - notes: - - type: text - contents: |- - The Terraform core program isn't very useful by itself. Terraform needs the help of a *provider* to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here: - - https://registry.terraform.io/browse/providers - - Today we'll be using a few different providers, but the main one is the *gcp* provider. - assignment: |- - We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track. - - Before we can do anything with Terraform we need to initialize our workspace. Run the following command on your "Shell" tab: - ``` - terraform init - ``` - - The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them. - - Run the following command to verify that the google provider was installed under the ".terraform" directory:: - - ``` - ls .terraform/providers/registry.terraform.io/hashicorp - ``` - - This hidden directory is where all modules and plugins are stored. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: provider-quiz - id: cvnkdjpuxdxr - type: quiz - title: "\U0001F4DD Quiz 1 - Providers and Modules" - teaser: | - A quiz about Terraform init - notes: - - type: text - contents: | - It's quiz time! - assignment: | - Where does Terraform store its modules and providers? - answers: - - In the /tmp directory - - In the user's home directory - - In the .terraform directory - - None of the above - solution: - - 2 - difficulty: basic - timelimit: 1000 -- slug: terraform-validate - id: jfruvky3rr2y - type: challenge - title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code" - teaser: | - Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly. - notes: - - type: text - contents: Terraform has a built-in syntax checker. You can run it with the `terraform - validate` command. - assignment: |- - Terraform comes with a built-in subcommand called *validate*. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly. - - Edit the main.tf file and remove the double quotes between `google_compute_network` and `hashicat` on line 15 of the file, keeping the space that was between them. Save the file. - - Validate your code: - - ``` - terraform validate - ``` - - Now put the double quotes back in line 15, save the file, and run the `validate` command again. This time you should pass the validation test. - - `terraform validate` is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: terraform-plan - id: jgsj1zpjytcg - type: challenge - title: "\U0001F914 Terraform Plan - Dry Run Mode" - teaser: | - Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run `terraform plan` and view the output. - notes: - - type: text - contents: |- - `terraform plan` allows you to preview any changes to your environment in a safe way. - - This can help you identify any unexpected changes before you deploy them, not after they are already built. - assignment: |- - Run the `terraform plan` command: - - ``` - terraform plan - ``` - - When you run this command Terraform will prompt you to enter the `prefix` variable. - - Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name. - - The prefix will become part of the name for our VPC network, subnet, and compute instance, as well as appear in the HashiCat application. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: terraform-variables - id: nqebldtwcv2o - type: challenge - title: "\U0001F39B️ Working with Terraform Variables" - teaser: | - Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables. - notes: - - type: text - contents: The `terraform.tfvars` file is a convenient place for users to configure - their variables. - assignment: |- - In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later. - - Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case). - - **Be sure to click the disk icon above the file to save your change!** - - Now run `terraform plan` again. This time you won't have to enter your prefix manually. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: terraform-add-a-variable - id: ntsoymyibxax - type: challenge - title: "\U0001F5FC Change Your Location" - teaser: | - Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable. - notes: - - type: text - contents: |- - You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file. - - In this challenge, you will pick the location where your GCP resources should be deployed. - assignment: |- - In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set two more variables that will determine the location where your GCP infrastructure will be deployed. - - First run another plan so you'll be able to compare what happens after you change the location. - - ``` - terraform plan - ``` - - Choose a GCP region near you but different from the default one which is "us-central1". Add `region` and `zone` variables to your "terraform.tfvars" file, setting them to your desired region and one of its zones. - - See this [page](https://cloud.google.com/compute/docs/regions-zones) for a list of regions and zones. For regions, strip off the `-a`, `-b`, or `-c` from the zones listed on that page. - - Choosing a region close to you can help improve speed and performance. - - **Be sure to click the disk icon above the file to save your change!** - - Once you've set your `region` and `zone` variables, try running `terraform plan` again. What's different this time? - - Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: variables-quiz - id: si44uxopl7q9 - type: quiz - title: "\U0001F4DD Quiz 2 - Variables" - teaser: | - A quiz about Terraform variables - notes: - - type: text - contents: | - Another quiz, get ready! - assignment: | - Where are terraform variables usually *declared*? - answers: - - On the command line - - As environment variables - - In the variables.tf file - - In the terraform.tfvars file - solution: - - 2 - difficulty: basic - timelimit: 1000 -- slug: tf-graph - id: aizuszmflj8e - type: challenge - title: "\U0001F4C8 Terraform Graph" - teaser: | - Terraform creates a graph of all the infrastructure defined in your code. - notes: - - type: text - contents: Terraform Graph can provide a visual representation of all your infrastructure. - This is handy for finding dependency issues or resources that will be affected - by a change. - assignment: |- - Try running the `terraform graph` command: - - ``` - terraform graph - ``` - - This generates code that can be used to create a visual map of your infrastructure. The graph data is in [DOT graph description language format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). There are several graphing tools you can use to visualize this data, including the free Blast Radius tool. You can learn more about Blast Radius here: - - https://28mm.github.io/blast-radius-docs/ - - Start up a Blast Radius server with the following command: - - ``` - blast-radius --serve . - ``` - - Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon in Instruqt, which is directly to the right of the **Terraform Graph** tab and looks like a circular arrow. - - Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. - - **NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. - - Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Terraform Graph - type: service - hostname: workstation - port: 5000 - difficulty: basic - timelimit: 1000 -- slug: tf-apply - id: hj4n4xlzba0z - type: challenge - title: "\U0001F468‍\U0001F4BB Terraform Plan and Apply" - teaser: | - The `terraform plan` command can be run anytime to get a preview of changes that Terraform might make. When you run Terraform apply these changes are implemented, and Terraform builds, updates, or destroys resources. - notes: - - type: text - contents: |- - By default, the `terraform apply` command runs a Terraform plan to show you what changes it wants to make. - - Terraform maps out all the changes it needs to make before applying them. - assignment: |- - Now that we've configured our required prefix variable we can apply our Terraform configuration. - - Run the `terraform plan` command first to see what will happen: - - ``` - terraform plan - ``` - - Confirm the proper prefix is displayed in the plan output. Look for **# google_compute_network.hashicat** and find the output next to **+ name**. - - Then run `terraform apply` and watch your resources being built. - - ``` - terraform apply - ``` - - You'll need to enter **yes** when Terraform prompts you with the "Do you want to perform these actions?" question. - - Right now our code only defines a VPC network. We'll be building upon this starting point in the next challenge. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: tf-plan-again - id: ucnyob8rynoh - type: challenge - title: "\U0001F469‍\U0001F4BB Test and Repair" - teaser: | - Terraform is idempotent. Each resource in your code will be examined, and if it already exists Terraform will leave it alone. - notes: - - type: text - contents: |- - Terraform is an *idempotent* application. - - Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. - - https://en.wikipedia.org/wiki/Idempotence - assignment: |- - Try running `terraform plan` again and see what happens: - - ``` - terraform plan - ``` - - Since your VPC network has already been built, Terraform will report that there are no changes required. - - This is normal and expected. - - Now try running another apply: - - ``` - terraform apply - ``` - - Terraform checks each resource to ensure it is in the proper state. It will not re-create your VPC network if it is already provisioned correctly. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: change-prefix - id: jhwduo9xyaim - type: challenge - title: "\U0001F6EB Change Your Prefix" - teaser: | - When your Terraform code changes, your infrastructure will be modified to match the updated code. Terraform is a declarative language. - notes: - - type: text - contents: |- - Terraform can create, destroy, update in place, or destroy and re-create your infrastructure. Some types of resources can be updated without deleting them. Major changes usually require a teardown and rebuild. - - Terraform always tries to match the current infrastructure to what has been defined in your code. - assignment: |- - Edit the `terraform.tfvars` file to change your prefix. You could simply add a number to the end if you like. Or change it to something entirely new. - - Save the `terraform.tfvars` file and run your apply command again. - - ``` - terraform apply - ``` - - Type "yes" when prompted. - - Observe the output. What happened? - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: add-virtual-network - id: lcox1xsz1v99 - type: challenge - title: "\U0001F5A7 Add a Virtual Network" - teaser: | - Terraform resources are like building blocks. You can continue adding more blocks until your infrastructure reaches the desired state. - notes: - - type: text - contents: Terraform code can be built incrementally, one or two resources at a - time. - assignment: |- - Open the **main.tf** file again and uncomment the next resource block in the file. The type of resource is **google_compute_subnetwork** and it is named **hashicat**. - - Uncomment the code by removing the `#` characters from the beginning of each line. Be sure to save the file. - - Now run `terraform plan` and observe the results. - - Look at the **network** parameter inside the google_compute_subnetwork resource. See how it points back at the first resource in the file? The subnet resource inherits settings from the VPC network. - - Terraform can map out the complex web of dependencies between hundreds of interconnected resources. - - Finally, create your Virtual Network. Run `terraform apply` and answer "yes" when prompted. - - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: complete-the-build - id: 0bfucmxeywzx - type: challenge - title: "\U0001F3D7️ Complete the Build" - teaser: | - Terraform code can stand up everything from a GCP project, to virtual networks, to VMs and containers. - notes: - - type: text - contents: The `-auto-approve` flag can be used to override the "Are you sure?" - questions that appear before an apply or destroy. Use with caution! - assignment: |- - We've uncommented the rest of the Terraform code in the **main.tf** file for you. Run a `terraform plan` to see what will be built: - - ``` - terraform plan - ``` - - Now run an apply to build the HashiCat application: - - ``` - terraform apply -auto-approve - ``` - - It can take up to five minutes for the application to finish deploying. You will know it is complete when you see the Terraform output with your application URL at the end of the run. - - If the application won't load just run `terraform apply` again. This will attempt to reinstall the webserver and start your application if it's not running. - - Open your web application in a new browser tab by clicking on the URL in the `catapp_url` output. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: tf-graph-again - id: hjugxwezxsv4 - type: challenge - title: "\U0001F4C8 Terraform Graph" - teaser: | - Revisit graph to see what has changed. - notes: - - type: text - contents: Let's revisit our graph to see what has changed. - assignment: |- - Start up a Blast Radius server with the following command: - - ``` - blast-radius --serve . - ``` - - Now switch to the **Terraform Graph** tab to view the infrastructure graph. If the web page is blank, you may need to click the refresh icon in Instruqt, which is directly to the right of the **Terraform Graph** tab and looks like a circular arrow. - - Explore the Terraform graph for your infrastructure. Dependencies are automatically mapped out for you. This graph was generated using the free Blast Radius tool. - - **NOTE:** Due to a known bug you may not be able to drag and zoom the graph. The main point of this exercise is to see how terraform maps out complex infrastructure. So don't worry if your graph doesn't show color. - - Terraform uses this graph to determine which resources can be built in parallel for maximum efficiency. - tabs: - - title: Command Line - type: terminal - hostname: workstation - - title: Terraform Graph - type: service - hostname: workstation - port: 5000 - difficulty: basic - timelimit: 1000 -- slug: terraform-apply-quiz - id: rxaawyzm8ayn - type: quiz - title: "\U0001F4DD Quiz 3 - Terraform Apply" - teaser: | - What happens when you run `terraform apply` without a plan file? - notes: - - type: text - contents: | - It's quiz time! - assignment: | - What happens when you run `terraform apply` without specifying a plan file? - answers: - - Terraform runs without any plan - - Terraform reads the previous plan and then applies it - - Terraform runs a new plan right before the apply - - None of the above - solution: - - 2 - difficulty: basic - timelimit: 1000 -- slug: use-a-provisioner - id: hlgek4qt03mp - type: challenge - title: "\U0001F6E0️ Use a Provisioner" - teaser: | - Terraform works great with many different provisioning tools including Chef, Puppet, Ansible, Bash, and Powershell. - notes: - - type: text - contents: Terraform provisioners run once at creation time. They do not run on - subsequent applies, except in special circumstances. (Like this training lab...) - - type: text - contents: We've made some special adjustments to force the provisioner to run - every time you type terraform apply. This is so you can practice playing with - provisioners without destroying and recreating your virtual machine every time - you make a change. - - type: text - contents: |- - ``` - ______________________ - < Cows love Terraform! > - ---------------------- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || - ============================= - ``` - assignment: |- - Open the `main.tf` file on the "Code Editor" tab. Scroll down until you find the `remote-exec` provisioner block. - - Add the following two lines at the end of the inline list of commands: - - ``` - "sudo apt -y install cowsay", - "cowsay Mooooooooooo!", - ``` - - After copying them into your buffer, it will be easier to paste them if you hide the assignment by clicking the ">" icon . Click it again to redisplay the assignment. Be sure to save the file. - - This might be a good time to use the `terraform fmt` command to line up the commands nicely. - - Now apply your changes: - - ``` - terraform apply -auto-approve - ``` - - Scroll back through the log output. You should see an ASCII art cow saying "Moooooooo!" - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: add-an-output - id: yvzuy76snmcy - type: challenge - title: "\U0001F5A8️ Add an Output" - teaser: | - Outputs are used to convey useful information such as IP addresses, application URLs or other useful data. - notes: - - type: text - contents: You can mix plain text along with Terraform data in your outputs. Outputs - can be used to convey useful information to your users at the end of a run. - - type: text - contents: The `terraform refresh` command will sync your state file with what - exists in your infrastructure. A refresh command will not change your infrastructure. - - type: text - contents: The `terraform output` command can be run any time you want to see your - Terraform outputs again. Run `terraform output ` to view a single - output. - assignment: |- - Open the **outputs.tf** file on the "Code Editor" tab. Note the catapp_url output in the file. - - Add a second output for the `network_ip` of your web server. It's going to look a lot like the first output but will instead output the internal IP address instead of the external one. - - Name your output `catapp_ip`. - - You may refer to the docs page to see what types of outputs are valid: - - [Terraform GCP Docs - Click Here](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#attributes-reference) - [Terraform Outputs Docs - Click Here](https://www.terraform.io/docs/configuration/outputs.html) - - Be sure to save the changes to the **outputs.tf** file. - - Run the Terraform refresh command to view your new output: - - ``` - terraform refresh - ``` - - You can run the Terraform output command to view all your outputs: - - ``` - terraform output - ``` - - Unfortunately, you cannot use the URL with the internal IP to access the web app since your browser is not within the internal GCP network. But you can use the public URL shown in the `catapp_url` output. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: fun-with-variables - id: li0hxrvnfqsz - type: challenge - title: "\U0001F436 Fun With Variables" - teaser: | - Variables give the consumers of your Terraform code an easy way to customize their infrastructure. - notes: - - type: text - contents: |- - Terraform variables have five levels of precedence. 1=highest 5=lowest: - - 1. Command line flag - run as a command line switch - 1. Configuration file - set in your terraform.tfvars file - 1. Environment variable - part of your shell environment - 1. Default Config - default value in variables.tf - 1. User manual entry - if not specified, prompt the user for entry - - type: text - contents: |- - Here are some other fun placeholder sites you can try with the **placeholder** variable: - - placedog.net
- placebear.com
- www.fillmurray.com
- www.placecage.com
- placebeard.it
- loremflickr.com
- baconmockup.com
- placeimg.com
- assignment: |- - There are several ways to configure Terraform variables. So far we've been using the `terraform.tfvars` file to set our variables. Try re-deploying your application with different **height** and **width** variables on the command line. Reload the webapp after each apply to observe any changes. - - ``` - terraform apply -auto-approve -var height=600 -var width=800 - ``` - - Next try setting an environment variable that Terraform can read. Run this command to set the placeholder variable: - - ``` - export TF_VAR_placeholder=placedog.net - ``` - - Run another `apply` command: - ``` - terraform apply -auto-approve - ``` - - Now try it again with the same variable set differently on the command line: - ``` - terraform apply -auto-approve -var placeholder=placebear.com - ``` - - Which variable took precedence? Why? - - See this [doc](https://www.terraform.io/docs/configuration/variables.html#variable-definition-precedence) if you're unsure. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: terraform-variables-quiz - id: f8uc690aj7ma - type: quiz - title: "\U0001F4DD Quiz 4 - Terraform Variables" - teaser: | - How do Terraform variables get set or overridden? - notes: - - type: text - contents: | - Get ready for another quiz... - assignment: | - You have the same variable set in a *.tfvars file and as an environment variable. Which one takes precedence? - answers: - - The environment variable - - The tfvars config file - solution: - - 1 - difficulty: basic - timelimit: 1000 -- slug: hcp-terraform-setup - id: ybvvptd2fxpo - type: challenge - title: ☁️ HCP Terraform Setup - teaser: | - HCP Terraform offers unlimited free Terraform state storage for users. Safeguard your state files by storing them remotely in HCP Terraform. - notes: - - type: text - contents: HCP Terraform remote state storage is free for all users. - assignment: |- - During this challenge and the next one, you'll use the remote state feature of HCP Terraform to store your state file in the cloud. In order to do this you'll need a HCP Terraform account. Click on the URL below and sign up for a free account if you don't have one already: - - https://app.terraform.io/signup/account - - If you already have an account you can simply sign in with your existing credentials. - - Once you're signed into HCP Terraform create a new organization called YOURNAME-training. Replace YOURNAME with your own name or other text. - - Next you'll be prompted to create a workspace. You can skip the VCS integration step by clicking the "CLI-driven workflow" panel. Name your workspace **hashicat-gcp**. - - **Note:** If you already have a **hashicat-gcp** workspace, please delete the workspace by selecting the **Settings >> Destruction and Deletion** menu, clicking the "Delete from HCP Terraform" button, typing "hashicat-gcp" to confirm, and then clicking the "Delete workspace" button. Then re-create it as above. Doing this avoids possible problems with mis-matched state versions when executing local runs after having executed remote runs. This could happen if you played the [HCP Terraform with GCP](https://play.instruqt.com/hashicorp/tracks/terraform-cloud-gcp) track and then played this track. - - Run `terraform version` on the "Shell" tab and then set the **Terraform Version** to match on the workspace's **Settings >> General** settings page. - - Also, change the **Execution Mode** to **Local**. - - Be sure to save your settings by clicking the "Save settings" button at the bottom of the page! This will allow us to run Terraform commands from our workstation with local variables, which we'll do in the next challenge. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -- slug: configure-remote-state - id: ej7eai7iueyh - type: challenge - title: "\U0001F39B️ Configure Remote State" - teaser: | - The terraform command line tool can store its state in HCP Terraform. All that is required is a user token. - notes: - - type: text - contents: |- - With *local* execution mode the Terraform commands and variables all remain - on your workstation. - - With *remote* execution mode Terraform runs in a HCP Terraform - container environment. All variables must be configured in the cloud environment with this method. - assignment: |- - During this challenge we'll configure HCP Terraform as a remote state backend, and then migrate our existing state file to HCP Terraform. - - Edit the "remote_backend.tf" file and replace the YOURORGANIZATION and YOURWORKSPACE placeholders with your org name and workspace name. Be sure to save the file. - - Let's generate a new **user token** for use on your workstation. Visit the User Settings > Tokens page in HCP Terraform: - - https://app.terraform.io/app/settings/tokens - - Click on the **Create an API token** button. You can name the token whatever you like. Copy the entire token using your mouse or the small copy-paste icon. - - Back in the Instruqt track, you need to add your API token to a file called "credentials.tfrc.json". Select the "Credentials File" tab and open the `/root/.terraform.d/credentials.tfrc.json` file directly. - - Replace the part that says YOURTOKEN with what you copied from HCP Terraform. Be sure to save the file. - - Your token is now safely stored in the `/root/.terraform.d/credentials.tfrc.json` file. - - Now run `terraform init` to migrate your state to HCP Terraform. - - ``` - terraform init - ``` - - Type "yes" when it prompts you to migrate your state into HCP Terraform. - - Your state is now safely stored in HCP Terraform. You can verify this on the "States" tab of your workspace in the TFC UI. - - Run a `terraform apply -auto-approve` and watch your state file evolve with each change. You can browse through previous state files with the HCP Terraform UI. - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - - title: Credentials File - type: code - hostname: workstation - path: /root/.terraform.d/credentials.tfrc.json - difficulty: basic - timelimit: 1000 -- slug: terraform-destroy - id: yzz4r4uxn31i - type: challenge - title: "\U0001F525 Terraform Destroy" - teaser: | - Terraform can build infrastructure and also destroy it when you are done using it. This helps control costs and reduce infrastructure sprawl. - notes: - - type: text - contents: |- - Terraform can destroy infrastructure as easily as it can build it. - - Use `terraform destroy` with caution. - assignment: |- - Run the following command to destroy your infrastructure: - - ``` - terraform destroy - ``` - - You'll need to type "yes" when prompted to destroy your infrastructure. This is a safety feature to help prevent accidental deletion of important resources. - - Wait until the destroy action has completely finished before clicking on the **Check** button. - - Congratulations on completing the Intro to Terraform track! - tabs: - - title: Shell - type: terminal - hostname: workstation - - title: Code Editor - type: code - hostname: workstation - path: /root/hashicat-gcp - difficulty: basic - timelimit: 1000 -checksum: "3454967643602368276" +idle_timeout: 7200 +timelimit: 14400 +lab_config: + overlay: false + width: 33 + position: right + sidebar_enabled: true + feedback_recap_enabled: true + loadingMessages: true + hideStopButton: false +checksum: "13556230776911275731"