[go: up one dir, main page]

Skip to content

Advanced TF Concepts from the book 'Terraform: Up and Running'

License

Notifications You must be signed in to change notification settings

Ujstor/aws-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform: Up & Running Code

This repo contains my code implementation for the book Terraform: Up and Running

Packer

To build the Amazon Machine Image (AMI):

packer build webserver.json

Local k8s cluster:

k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker.

k3d cluster create terraform \
  --servers 3 \
  --agents 3 \
  -p "80:80@loadbalancer" \
  -p "443:443@loadbalancer" \
  --k3s-node-label "type=control@server:0,1,2" \
  --k3s-node-label "type=worker@agent:0,1,2"

For local testing with k3d, comment out the 'loadbalancer' form in the service object.

  spec {
    # type = "LoadBalancer"
    port {
      port        = var.ingress_port
      target_port = var.container_port
      protocol    = "TCP"
    }
    selector = local.pod_labels
  }

kubectl AWS

aws eks update-kubeconfig --region <REGION> --name <EKS_CLUSTER_NAME>

Terratest

cd modules/test
go test -v -timeout 30m
go test -v -timeout 30m -run TestHelloWorldAppExample
go test -v -timeout 30m -parallel 2

Integration tests

For testing multiple modules in the staging environment, extract the state S3 config into a separate file. This will prevent overwriting the state file and can be used manually:

terraform init -backend-config=backend.hcl

Run the integration tests:

go test -v -timeout 30m -run TestHelloWorldAppStage

If Stagins is implemented, exclude steps for the Stages:

SKIP_teardown_db=true \
SKIP_teardown_app=true \
SKIP_deploy_db=true \
SKIP_deploy_app=true \
SKIP_validate_app=true \
go test -v -timeout 30m -run TestHelloWorldAppStage

Integration tests in Stages

SKIP_teardown_db=true \
SKIP_teardown_app=true \
go test -timeout 30m -run TestHelloWorldAppStageWithStages
SKIP_teardown_db=true \
SKIP_teardown_app=true \
SKIP_deploy_db=true \
go test -timeout 30m -run TestHelloWorldAppStageWithStages

clean up

SKIP_deploy_db=true \
SKIP_deploy_app=true \
SKIP_validate_app=true \
go test -timeout 30m -run TestHelloWorldAppStageWithStages

License

This code is released under the MIT License.

About

Advanced TF Concepts from the book 'Terraform: Up and Running'

Resources

License

Stars

Watchers

Forks