From f21f709b51a973630560b2ae5992bff8664d27be Mon Sep 17 00:00:00 2001 From: sid palas Date: Sun, 27 Jun 2021 13:41:03 -0700 Subject: [PATCH] Updates during testing of TF 1.0.1 --- .github/workflows/terraform.yml | 2 +- 03-basics/aws-backend/README.md | 8 +--- .../aws-backend/import-bootstrap/main.tf | 47 ------------------- 03-basics/aws-backend/{bootstrap => }/main.tf | 10 ++-- 06-organization-and-modules/web-app/main.tf | 16 +++++-- 08-testing/tests/terratest/README.md | 6 +++ .../tests/terratest/hello_world_test.go | 2 +- README.md | 2 +- 8 files changed, 29 insertions(+), 64 deletions(-) delete mode 100644 03-basics/aws-backend/import-bootstrap/main.tf rename 03-basics/aws-backend/{bootstrap => }/main.tf (64%) create mode 100644 08-testing/tests/terratest/README.md diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 6738c20..2e77594 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -25,7 +25,7 @@ jobs: - name: Setup Terraform uses: hashicorp/setup-terraform@v1 with: - terraform_version: 0.15.4 + terraform_version: 1.0.1 - name: Terraform Format id: fmt diff --git a/03-basics/aws-backend/README.md b/03-basics/aws-backend/README.md index 340feed..425ae5b 100644 --- a/03-basics/aws-backend/README.md +++ b/03-basics/aws-backend/README.md @@ -1,11 +1,7 @@ Steps to initialize backend in AWS and manage it with Terraform: 1) Use config from `bootstrap` (init, plan, apply) to provision s3 bucket and dynamoDB table with local state -2) copy state file into import-bootstrap - 1) cp terraform.tfstate ../import-bootstrap -3) Initialize within `import-bootstrap` using `terraform init` -4) Uncomment out s3 backend provider: - +2) Uncomment the remote backend configuration ``` backend "s3" { bucket = "devops-directive-tf-state" @@ -16,7 +12,7 @@ Steps to initialize backend in AWS and manage it with Terraform: } ``` -4) Reinitialize with `terraform init`: +1) Reinitialize with `terraform init`: ``` Do you want to copy existing state to the new backend? diff --git a/03-basics/aws-backend/import-bootstrap/main.tf b/03-basics/aws-backend/import-bootstrap/main.tf deleted file mode 100644 index 492cd89..0000000 --- a/03-basics/aws-backend/import-bootstrap/main.tf +++ /dev/null @@ -1,47 +0,0 @@ -terraform { - ### UNCOMMENT THIS AFTER INITIALIZNG ### - # backend "s3" { - # bucket = "devops-directive-tf-state" - # key = "03-basics/import-bootstrap/terraform.tfstate" - # region = "us-east-1" - # dynamodb_table = "terraform-state-locking" - # encrypt = true - # } - - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 3.0" - } - } -} - -provider "aws" { - region = "us-east-1" -} - -resource "aws_s3_bucket" "terraform_state" { - bucket = "devops-directive-tf-state" - force_destroy = true - versioning { - enabled = true - } - - server_side_encryption_configuration { - rule { - apply_server_side_encryption_by_default { - sse_algorithm = "AES256" - } - } - } -} - -resource "aws_dynamodb_table" "terraform_locks" { - name = "terraform-state-locking" - billing_mode = "PAY_PER_REQUEST" - hash_key = "LockID" - attribute { - name = "LockID" - type = "S" - } -} diff --git a/03-basics/aws-backend/bootstrap/main.tf b/03-basics/aws-backend/main.tf similarity index 64% rename from 03-basics/aws-backend/bootstrap/main.tf rename to 03-basics/aws-backend/main.tf index 5706a84..f58b42a 100644 --- a/03-basics/aws-backend/bootstrap/main.tf +++ b/03-basics/aws-backend/main.tf @@ -1,7 +1,11 @@ terraform { - # THIS BACKEND CONFIG GETS UNCOMMENTED IN IMPORT-BOOTSTRAP + ############################################################# + ## AFTER RUNNING TERRAFORM APPLY (WITH LOCAL BACKEND) + ## YOU WILL UNCOMMENT THIS CODE THEN RERUN TERRAFORM INIT + ## TO SWITCH FROM LOCAL BACKEND TO REMOTE AWS BACKEND + ############################################################# # backend "s3" { - # bucket = "devops-directive-tf-state" + # bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME # key = "03-basics/import-bootstrap/terraform.tfstate" # region = "us-east-1" # dynamodb_table = "terraform-state-locking" @@ -21,7 +25,7 @@ provider "aws" { } resource "aws_s3_bucket" "terraform_state" { - bucket = "devops-directive-tf-state" + bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME force_destroy = true versioning { enabled = true diff --git a/06-organization-and-modules/web-app/main.tf b/06-organization-and-modules/web-app/main.tf index 80c62d9..73461d1 100644 --- a/06-organization-and-modules/web-app/main.tf +++ b/06-organization-and-modules/web-app/main.tf @@ -21,8 +21,14 @@ provider "aws" { region = "us-east-1" } -variable "db_pass" { - description = "password for database" +variable "db_pass_1" { + description = "password for database #2" + type = string + sensitive = true +} + +variable "db_pass_2" { + description = "password for database #2" type = string sensitive = true } @@ -39,7 +45,7 @@ module "web_app_1" { create_dns_zone = true db_name = "webapp1db" db_user = "foo" - db_pass = var.db_pass + db_pass = var.db_pass_1 } module "web_app_2" { @@ -53,6 +59,6 @@ module "web_app_2" { instance_type = "t2.small" create_dns_zone = true db_name = "webapp2db" - db_user = "foo" - db_pass = var.db_pass + db_user = "bar" + db_pass = var.db_pass_2 } diff --git a/08-testing/tests/terratest/README.md b/08-testing/tests/terratest/README.md new file mode 100644 index 0000000..a95187b --- /dev/null +++ b/08-testing/tests/terratest/README.md @@ -0,0 +1,6 @@ +How to run this test? + +Build, then run... + +`go test -v timeout 10m` + diff --git a/08-testing/tests/terratest/hello_world_test.go b/08-testing/tests/terratest/hello_world_test.go index 13317dd..ca2887c 100644 --- a/08-testing/tests/terratest/hello_world_test.go +++ b/08-testing/tests/terratest/hello_world_test.go @@ -23,7 +23,7 @@ func TestTerraformHelloWorldExample(t *testing.T) { instanceURL := terraform.Output(t, terraformOptions, "url") tlsConfig := tls.Config{} maxRetries := 30 - timeBetweenRetries := 5 * time.Second + timeBetweenRetries := 10 * time.Second http_helper.HttpGetWithRetryWithCustomValidation( t, instanceURL, &tlsConfig, maxRetries, timeBetweenRetries, validate, diff --git a/README.md b/README.md index 7e0499e..8f030be 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Introduces the concepts of variables which enable Terraform configurations to be ## 05 - Language Features -Describes additional features of the Hashicorp Programming Language. +Describes additional features of the Hashicorp Configuration Language (HCL). ## 06 - Organization and Modules