diff --git a/terraform/README.md b/terraform/README.md index 1ebd835..8eac2f6 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -7,6 +7,20 @@ description: | Terraform is an infrastructure as code (IaC) tool that allows you to build, change, and version infrastructure safely and efficiently. --- +To update or switch versions, run `webi terraform@stable` (or `@v1.6.1`, +`@beta`, etc). + +### Files + +These are the files / directories that are created and/or modified with this +install: + +```text +~/.config/envman/PATH.env +~/.local/bin/terraform +/main.tf +``` + ## Cheat Sheet > With HashiCorp Terraform, provisioning and security can be automated based on @@ -14,14 +28,14 @@ description: | > shared, managed, and executed within a workflow that is consistent across all > infrastructure. -### Defining infrastructure state +### How to Define Infrastructure State Create configurations that provide an outline for Terraform to provision your -target infrastructure. E.g., +target infrastructure. For example: + +`main.tf`: ```tf -# main.tf - terraform { required_providers { docker = { @@ -52,43 +66,56 @@ resource "docker_container" "nginx" { } ``` -### Initializing Terraform +### How to Initialize Terraform Terraform needs to install provider-specific plugins, generate lockfiles, etc. before you can begin provisioning. -`terraform init` +```sh +terraform init +``` You should only need to run this on new configurations, or other configurations checked-out from version control. -### Checking your configuration +### How to Lint / Check / Validate your Config To check you have a valid configuration -`terraform validate` +```sh +terraform validate +``` To format your configuration files -`terraform fmt` +```sh +terraform fmt +``` -### Provisioning resources +### How to Provision Resources -You can generate an execution plan before commiting to provisioning real +You can generate an execution plan before committing to provisioning real resources. This command allows you to see exactly what Terraform will do when running the next command. -`terraform plan` +```sh +terraform plan +``` -**Then, to apply your configurations and provision infrastructure resources.** +Then, **to apply your configurations and provision infrastructure** resources: -`terraform apply` +```sh +terraform apply +``` -To automatically accept all user prompts when running this command +Use `-auto-approve` to automatically accept all user prompts (non-interactive, +batch mode): -`terraform apply -auto-approve` +```sh +terraform apply -auto-approve +``` -### Execution plans +### How to Execute Plans Execution plans generated by `terraform plan` also act as the _last working state of your infrastructure_. You may wish to save the generated `.tfstate` @@ -96,4 +123,6 @@ file so that you may re-provision these resources reliably. You can pass in the execution plan to `terraform apply` (example): -`terraform apply -auto-approve main.tf` +```sh +terraform apply -auto-approve ./main.tf +``` diff --git a/terraform/install.sh b/terraform/install.sh index 54e4e4f..4a68d6b 100644 --- a/terraform/install.sh +++ b/terraform/install.sh @@ -7,19 +7,25 @@ pkg_cmd_name="terraform" WEBI_SINGLE=true pkg_get_current_version() { + # 'terraform -v' has output in this format: + # Terraform v1.6.1 + # on linux_amd64 + # This trims it down to just the version number: + # 1.6.1 terraform -v 2> /dev/null | head -n 1 | - cut -d 'v' -f 2 + cut -d' ' -f2 | + cut -c2- } pkg_install() { - # $HOME/.local/bin/opt/terraform-v1.3.2/bin + # $HOME/.local/bin/opt/terraform-v1.6.1/bin mkdir -p "$pkg_src_bin" - # mv ./terraform* "$HOME/.local/opt/terraform-v1.3.2/bin/terraform" + # mv ./terraform* "$HOME/.local/opt/terraform-v1.6.1/bin/terraform" mv ./"$pkg_cmd_name"* "$pkg_src_cmd" - # chmod a+x "$HOME/.local/opt/terraform-v1.3.2/bin/terraform" + # chmod a+x "$HOME/.local/opt/terraform-v1.6.1/bin/terraform" chmod a+x "$pkg_src_cmd" } @@ -27,6 +33,6 @@ pkg_link() { # rm -f "$HOME/.local/bin/terraform" rm -f "$pkg_dst_cmd" - # ln -s "$HOME/.local/opt/terraform-v1.3.2/bin/terraform" "$HOME/.local/bin/terraform" + # ln -s "$HOME/.local/opt/terraform-v1.6.1/bin/terraform" "$HOME/.local/bin/terraform" ln -s "$pkg_src_cmd" "$pkg_dst_cmd" }