diff --git a/README.md b/README.md index ef994618..9f08a59d 100644 --- a/README.md +++ b/README.md @@ -146,13 +146,14 @@ This diagram shows the namespaces used in the cluster and the services deployed ## Useful tools - [tfenv](https://github.com/tfutils/tfenv) - tool for managing different versions of terraform; the required version can be specified directly as an argument or via `.terraform-version` +- [tgenv](https://github.com/cunymatthieu/tgenv) - tool for managing different versions of terragrunt; the required version can be specified directly as an argument or via `.terragrunt-version` - [terraform](https://www.terraform.io/) - terraform itself, our main development tool: `tfenv install` - [awscli](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) - console utility to work with AWS API - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - conssole utility to work with Kubernetes API - [kubectx + kubens](https://github.com/ahmetb/kubectx) - power tools for kubectl help you switch between Kubernetes clusters and namespaces - [helm](https://helm.sh/docs/intro/install/) - tool to create application packages and deploy them into k8s - [helmfile](https://github.com/roboll/helmfile) - "docker compose" for helm -- [terragrunt](https://terragrunt.gruntwork.io/) - small terraform wrapper providing DRY approach in some cases +- [terragrunt](https://terragrunt.gruntwork.io/) - small terraform wrapper providing DRY approach in some cases: `tgenv install` - [awsudo](https://github.com/meltwater/awsudo) - simple console utility that allows running awscli commands assuming specific roles - [aws-vault](https://github.com/99designs/aws-vault) - tool for securely managing AWS keys and running console commands - [aws-mfa](https://github.com/broamski/aws-mfa) - utility for automating the reception of temporary STS tockens when MFA is enabled @@ -349,6 +350,9 @@ Details can be found [here](https://www.terraform.io/docs/cli/run/index.html) ### terragrunt +* Terragrunt version: `0.29.2` +> Terragrunt version pinned in `terragrunt.hcl` file. + We've also used `terragrunt` to simplify s3 bucket creation and terraform backend configuration. All you need to do is to set s3 bucket name in the `TF_REMOTE_STATE_BUCKET` env variable and run terragrunt command in the `terraform/` directory: ```bash @@ -359,6 +363,43 @@ We've also used `terragrunt` to simplify s3 bucket creation and terraform backen By running this `terragrunt` will create s3 bucket, configure terraform backend and then will run `terraform init` and `terraform apply` in layer-1 and layer-2 sequentially. +#### Apply infrastructure by layers with `terragrunt` + +Go to layer folder `terraform/layer1-aws/` or `terraform/layer2-k8s/` and run this command: + +``` +terragrunt apply +``` + +> The `layer2-k8s` has a dependence on `layer1-aws`. + +#### Target apply by `terragrunt` + +Go to layer folder `terraform/layer1-aws/` or `terraform/layer2-k8s/` and run this command: + +``` +terragrunt apply -target=module.eks +``` + +> The `-target` is formed from the following parts `resource type` and `resource name`. +> For example: `-target=module.eks`, `-target=helm_release.loki_stack` + +#### Destroy infrastructure by `terragrunt` + +To destroy both layers, run this command from `terraform/` folder: + +``` +terragrant run-all destroy +``` + +To destroy `layer2-k8s`, run this command from `terraform/layare2-k8s` folder: + +``` +terragrunt destroy +``` + +> The `layer2-k8s` has dependence from `layer1-aws` and when you destroy `layer1-aws`, `layer2-k8s` destroyed automatically. + ## What to do after deployment After applying this configuration, you will get the infrastructure described and outlined at the beginning of the document. In AWS and within the EKS cluster, the basic resources and services necessary for the operation of the EKS k8s cluster will be created. diff --git a/terraform/.terragrunt-version b/terraform/.terragrunt-version new file mode 100644 index 00000000..20f06870 --- /dev/null +++ b/terraform/.terragrunt-version @@ -0,0 +1 @@ +0.29.2 diff --git a/terraform/layer2-k8s/templates/cert-manager-values.yaml b/terraform/layer2-k8s/templates/cert-manager-values.yaml index 7cefbedd..c2190061 100644 --- a/terraform/layer2-k8s/templates/cert-manager-values.yaml +++ b/terraform/layer2-k8s/templates/cert-manager-values.yaml @@ -14,7 +14,7 @@ affinity: - matchExpressions: - key: node.kubernetes.io/lifecycle operator: In - values: + values: - ondemand cainjector: diff --git a/terraform/terragrunt.hcl b/terraform/terragrunt.hcl index 3295300d..187d8e7c 100644 --- a/terraform/terragrunt.hcl +++ b/terraform/terragrunt.hcl @@ -22,3 +22,6 @@ remote_state { encrypt = true } } + +terragrunt_version_constraint = "0.29.2" +