mirror of
https://github.com/sidpalas/devops-directive-terraform-course.git
synced 2025-12-11 13:21:14 +00:00
Updates during testing of TF 1.0.1
This commit is contained in:
2
.github/workflows/terraform.yml
vendored
2
.github/workflows/terraform.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
|||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
uses: hashicorp/setup-terraform@v1
|
uses: hashicorp/setup-terraform@v1
|
||||||
with:
|
with:
|
||||||
terraform_version: 0.15.4
|
terraform_version: 1.0.1
|
||||||
|
|
||||||
- name: Terraform Format
|
- name: Terraform Format
|
||||||
id: fmt
|
id: fmt
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
Steps to initialize backend in AWS and manage it with Terraform:
|
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
|
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
|
2) Uncomment the remote backend configuration
|
||||||
1) cp terraform.tfstate ../import-bootstrap
|
|
||||||
3) Initialize within `import-bootstrap` using `terraform init`
|
|
||||||
4) Uncomment out s3 backend provider:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
backend "s3" {
|
backend "s3" {
|
||||||
bucket = "devops-directive-tf-state"
|
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?
|
Do you want to copy existing state to the new backend?
|
||||||
|
|||||||
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
terraform {
|
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" {
|
# backend "s3" {
|
||||||
# bucket = "devops-directive-tf-state"
|
# bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME
|
||||||
# key = "03-basics/import-bootstrap/terraform.tfstate"
|
# key = "03-basics/import-bootstrap/terraform.tfstate"
|
||||||
# region = "us-east-1"
|
# region = "us-east-1"
|
||||||
# dynamodb_table = "terraform-state-locking"
|
# dynamodb_table = "terraform-state-locking"
|
||||||
@@ -21,7 +25,7 @@ provider "aws" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_s3_bucket" "terraform_state" {
|
resource "aws_s3_bucket" "terraform_state" {
|
||||||
bucket = "devops-directive-tf-state"
|
bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME
|
||||||
force_destroy = true
|
force_destroy = true
|
||||||
versioning {
|
versioning {
|
||||||
enabled = true
|
enabled = true
|
||||||
@@ -21,8 +21,14 @@ provider "aws" {
|
|||||||
region = "us-east-1"
|
region = "us-east-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "db_pass" {
|
variable "db_pass_1" {
|
||||||
description = "password for database"
|
description = "password for database #2"
|
||||||
|
type = string
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "db_pass_2" {
|
||||||
|
description = "password for database #2"
|
||||||
type = string
|
type = string
|
||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
@@ -39,7 +45,7 @@ module "web_app_1" {
|
|||||||
create_dns_zone = true
|
create_dns_zone = true
|
||||||
db_name = "webapp1db"
|
db_name = "webapp1db"
|
||||||
db_user = "foo"
|
db_user = "foo"
|
||||||
db_pass = var.db_pass
|
db_pass = var.db_pass_1
|
||||||
}
|
}
|
||||||
|
|
||||||
module "web_app_2" {
|
module "web_app_2" {
|
||||||
@@ -53,6 +59,6 @@ module "web_app_2" {
|
|||||||
instance_type = "t2.small"
|
instance_type = "t2.small"
|
||||||
create_dns_zone = true
|
create_dns_zone = true
|
||||||
db_name = "webapp2db"
|
db_name = "webapp2db"
|
||||||
db_user = "foo"
|
db_user = "bar"
|
||||||
db_pass = var.db_pass
|
db_pass = var.db_pass_2
|
||||||
}
|
}
|
||||||
|
|||||||
6
08-testing/tests/terratest/README.md
Normal file
6
08-testing/tests/terratest/README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
How to run this test?
|
||||||
|
|
||||||
|
Build, then run...
|
||||||
|
|
||||||
|
`go test -v timeout 10m`
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ func TestTerraformHelloWorldExample(t *testing.T) {
|
|||||||
instanceURL := terraform.Output(t, terraformOptions, "url")
|
instanceURL := terraform.Output(t, terraformOptions, "url")
|
||||||
tlsConfig := tls.Config{}
|
tlsConfig := tls.Config{}
|
||||||
maxRetries := 30
|
maxRetries := 30
|
||||||
timeBetweenRetries := 5 * time.Second
|
timeBetweenRetries := 10 * time.Second
|
||||||
|
|
||||||
http_helper.HttpGetWithRetryWithCustomValidation(
|
http_helper.HttpGetWithRetryWithCustomValidation(
|
||||||
t, instanceURL, &tlsConfig, maxRetries, timeBetweenRetries, validate,
|
t, instanceURL, &tlsConfig, maxRetries, timeBetweenRetries, validate,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Introduces the concepts of variables which enable Terraform configurations to be
|
|||||||
|
|
||||||
## 05 - Language Features
|
## 05 - Language Features
|
||||||
|
|
||||||
Describes additional features of the Hashicorp Programming Language.
|
Describes additional features of the Hashicorp Configuration Language (HCL).
|
||||||
|
|
||||||
## 06 - Organization and Modules
|
## 06 - Organization and Modules
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user