Skip to content

Templates / Terraform / GitLab managed state - How to use

The following info was pulled from latest release v0.3.2.

How to use

For more info on how this release was built, see README.

Start a new project

mkdir new-project
cd new-project
git init

Unpack a v0.3.2 template, with an Alpine devcontainer

curl https://gitlab.com/api/v4/projects/40970709/packages/generic/templates/0.3.2/tf-starter-kit_alpine_0.3.2.tar.gz | tar zx

Or with a Debian devcontainer

curl https://gitlab.com/api/v4/projects/40970709/packages/generic/templates/0.3.2/tf-starter-kit_debian_0.3.2.tar.gz | tar zx

Commit (using a multi-line git commit message)

git add .
git commit -F- <<EOF
Initial commit using template tf-starter-kit_debian_0.3.2

See here for more info on the template:
https://gitlab.com/geekstuff.dev/templates/terraform/gitlab-managed-state/-/releases/v0.3.2
EOF

Startup Devcontainer using VSCode

code -n .

Set a few variables for your project

  • Upon devcontainer start, a terminall will open with help instructions.
  • Run easy make command to see the few variables that needs to be to set and where to set them.
make check.vars

Note: When you set a variable and save a file, press enter in the terminal for the environment to reload itself and update the list of variables to set.

Leverage one of the included templates

  • Simple Terraform templates are included in the starter kit.
  • tf-test deploys a TF state but does not create anything. Comes with a gitlab-ci template with review + prod environments.
  • tf-test-vault works like tf-test but additionally uses Hashicorp Vault to login using JWT, fetch credentials and encrypt + decrypt plan file using transit key.
  • tf-vault-setup-manual is meant to run manually by maintainers + vault admins. It uses Terraform to configure the Vault resource needs for tf-test-vault.
  • All templates are also setup to run a dev environment, by relying on docker containers built with all (and only) the tools needed to run this specific project, and in which VSCode starts itself with specific extensions and configuration, all isolated in a container.
  • More details on how to use the templates in templates/README.md

To update a project already using a template

  • Search and replace all instances of previous tag to new tag v0.3.2
  • In VSCode, F1, search and run "Rebuild Container"
  • In your integrated terminal, run make template.diff to view the differences
  • Integrate the changes that makes sense manually (for now)
Propose changes to this page