Skip to content


Gitlab logo

A remote repository acts as a backup for all your code and makes it much easier to setup continuous integration, CI (testing, linting etc). We'll use gitlab, although you could also use github.

Rather than creating the repository through gitlab's UI we'll use Terraform as setup previously. To do so we'll first need an access token. This token is a secret, and hence best placed in the infrastructure/ as so,

gitlab_token = "abc1234"

We can then instruct terraform to use the gitlab provider to create a gitlab project, called tozo (change as appropriate 😄), by adding the following to infrastructure/,

terraform {
  required_providers {
    gitlab = {
      source  = "gitlabhq/gitlab"
      version = ">=3.3.0"
  required_version = ">=0.14"

to configure terraform with gitlab, and then the following to infrastructure/,

variable "gitlab_token" {
  sensitive = true

provider "gitlab" {
  token = var.gitlab_token

resource "gitlab_project" "tozo" {
  name             = "tozo"
  visibility_level = "private"
  default_branch   = "main"

which you can then apply via following commands,

terraform init
terraform apply

Committing and pushing

Now we've run these commands we should encrypt the secrets and state as both have now changed,

ansible-vault encrypt
ansible-vault encrypt terraform.tfstate --output=terraform.tfstate.vault

which should result in these useful files in the repository,

├── backend
├── frontend
└── infrastructure
    ├── .gitignore
    ├── ansible.cfg
    ├── terraform.tfstate
    └── terraform.tfstate.vault

so lets commit those (excluding and terraform.tfstate) and push to the remote (with your namespace and project names),

git remote add origin
git push origin main