Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ujstor/aws-terraform
Advanced TF Concepts from the book 'Terraform: Up and Running'
https://github.com/ujstor/aws-terraform
Last synced: about 1 month ago
JSON representation
Advanced TF Concepts from the book 'Terraform: Up and Running'
- Host: GitHub
- URL: https://github.com/ujstor/aws-terraform
- Owner: Ujstor
- License: mit
- Created: 2024-05-26T19:55:15.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-06-30T01:39:46.000Z (6 months ago)
- Last Synced: 2024-07-01T15:20:03.718Z (6 months ago)
- Language: HCL
- Homepage:
- Size: 142 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Terraform: Up & Running Code
This repo contains my code implementation for the book *[Terraform: Up and Running](http://www.terraformupandrunning.com)*
## Packer
To build the Amazon Machine Image (AMI):
```bash
packer build webserver.json
```## Local k8s cluster:
[k3d](https://k3d.io/v5.6.3/usage/configfile/) is a lightweight wrapper to run [k3s](https://k3s.io/) (Rancher Lab’s minimal Kubernetes distribution) in docker.```bash
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.
```terraform
spec {
# type = "LoadBalancer"
port {
port = var.ingress_port
target_port = var.container_port
protocol = "TCP"
}
selector = local.pod_labels
}
```## kubectl AWS
```bash
aws eks update-kubeconfig --region --name
```## Terratest
```bash
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:```bash
terraform init -backend-config=backend.hcl
```Run the integration tests:
```bash
go test -v -timeout 30m -run TestHelloWorldAppStage
```
If Stagins is implemented, exclude steps for the Stages:```bash
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```bash
SKIP_teardown_db=true \
SKIP_teardown_app=true \
go test -timeout 30m -run TestHelloWorldAppStageWithStages
``````bash
SKIP_teardown_db=true \
SKIP_teardown_app=true \
SKIP_deploy_db=true \
go test -timeout 30m -run TestHelloWorldAppStageWithStages
```clean up
```bash
SKIP_deploy_db=true \
SKIP_deploy_app=true \
SKIP_validate_app=true \
go test -timeout 30m -run TestHelloWorldAppStageWithStages
```
## LicenseThis code is released under the MIT License.