|
| 1 | +--- |
| 2 | +title: Explaining the Makefile in your repository |
| 3 | +sidebar_label: Makefile Lifecycle |
| 4 | +sidebar_position: 2 |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | +The [Makefile] shipped with your repository drives the creation of your infrastructure, it defines the order of execution in its `apply` make target. |
| 9 | + |
| 10 | +The [Makefile] is idempotent by design, meaning when it runs it will attempt to reach the same final state every time. Therefore if the script determines a resource has previously been created it will skip the creation when run again, meaning `make apply` can be re-run from inside your project after the initial setup when you ran `zero apply`. You may want to use one of the specific targets below though. For example, if you made a change to your staging infrastructure Terraform you could just run `make apply-env`. |
| 11 | + |
| 12 | +See more about the [Terraform workflow guide][terraform-workflow] how to manage your infrastructure as code. |
| 13 | + |
| 14 | +## Targets Explained |
| 15 | +Some of the steps are used for initializing the infrastructure, and some steps can also be used for updating and maintaining the infrastructure. |
| 16 | + |
| 17 | +All the targets can be run with the environment variable `ENVIRONMENT=<prod|stage>` to target the corresponding environment, which defaults to `stage` |
| 18 | + |
| 19 | +## Helpful targets for day-to-day use |
| 20 | + |
| 21 | +### `apply-shared-env` |
| 22 | +Runs `terraform apply` in your `terraform/environments/shared` directory. This terraform is responsible for resources shared between both staging/production. For example, IAM users and groups. |
| 23 | +### `apply-env` |
| 24 | +Runs `terraform apply` in your `terraform/environments/<env>` directory. This terraform represents the infrastructure resources in your AWS account: VPC, S3 buckets, EKS cluster, RDS database, etc. |
| 25 | +### `apply-k8s-utils` |
| 26 | +Runs `terraform apply` in your `kubernetes/terraform/environments/<env>` directory. This terraform represents the resources in your Kubernetes cluster, such as `cert-manager`, `external-dns`, Wireguard VPN, Nginx Ingress Controller, and other tools inside your cluster. |
| 27 | +### `update-k8s-conf` |
| 28 | +This updates your Kubernetes config by assuming the IAM role `admin-role`, allowing you to connect to your cluster using `kubectl` with administrator access. You can also assume other roles by providing the `ROLE` environment variable. Other default roles created are `developer` and `operator`. |
| 29 | + |
| 30 | +## Others |
| 31 | +The rest of the targets are mostly used for one-time operations, either for setup or teardown. The teardown commands are mostly for testing, as they will destroy your infrastructure, so be careful not to run them by accident. |
| 32 | + |
| 33 | +### `apply-remote-state` |
| 34 | +Sets up up your Terraform remote backend in an S3 bucket. All the other Terraform uses the remote backend to store their state files. The makefile will only run this step once per environment. |
| 35 | + |
| 36 | +### `apply-secrets` |
| 37 | +One-time setup of secrets for infrastructure. This make target also removes the local terraform state immediately after running. The makefile will only run this step once per environment. |
| 38 | + |
| 39 | +### `pre-k8s` |
| 40 | +Scripts to create resources required for subsequent steps. For example: creating a VPN private key, a database user, and JWKS keys for the user auth components. |
| 41 | + |
| 42 | +### `post-apply-setup` |
| 43 | +Scripts to create resources required for subsequent steps, for example creating a database user for your application and setting up the dev environment. |
| 44 | + |
| 45 | +### `teardown*` |
| 46 | +Mostly for development and testing, the teardown process follows a specific order, the reverse of how the resources were created. Much of it is non-reversible. Please see your repository's [Teardown] section for more information |
| 47 | + |
| 48 | + |
| 49 | +[makefile]: https://github.com/commitdev/zero-aws-eks-stack/blob/main/templates/Makefile |
| 50 | +[teardown]: https://github.com/commitdev/zero-aws-eks-stack/tree/main/templates#teardown |
| 51 | +[terraform-workflow]: ../guides/managing-terraform#managing-your-terraform |
0 commit comments