This repo contains my code implementation for the book Terraform: Up and Running
To build the Amazon Machine Image (AMI):
packer build webserver.json
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
}
aws eks update-kubeconfig --region <REGION> --name <EKS_CLUSTER_NAME>
cd modules/test
go test -v -timeout 30m
go test -v -timeout 30m -run TestHelloWorldAppExample
go test -v -timeout 30m -parallel 2
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
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
This code is released under the MIT License.