Terraform Examples

terraform {
  required_providers {
    gitlab = {
      source = "gitlabhq/gitlab"
      version = "3.5.0"
    }
    github = {
      source  = "integrations/github"
      version = "~> 4.0"
    }
  }

  backend "remote" {
    organization = "-- terraform.io organization --"
    token = "-- add here your terraform.io token --"
    workspaces {
      name = "-- terraform.io workspace name (directory/path, this is not the terraform workspace from code) --"
    }
  }

  required_version = ">= 0.14"
}

provider "gitlab" {
  token = var.gitlab_token
}
locals {
  repositories = [
    {
      name = "newsletter"
      description = "Newsletter simple system"
      archive_on_destroy = false
      is_private = false
    },
  ]
}

module "repositories" {
  source = "../_modules/github-repository" // custom, not shown here

  for_each = { for item in local.repositories: item.name => item }

  description = each.value.description
  name        = each.value.name

  is_private = try(each.value.is_private, true)
  has_issues = try(each.value.has_issues, false)
  has_downloads = try(each.value.has_downloads, false)
  has_projects = try(each.value.has_projects, false)
  has_wiki = try(each.value.has_wiki, false)
  delete_branch_on_merge = try(each.value.delete_branch_on_merge, true)
  archive_on_destroy = try(each.value.archive_on_destroy, true)

  topics = try(each.value.topics, [])
  archived = try(each.value.archived, false)
}

resource "github_repository" "this" {
  name        = var.name
  description = var.description

  visibility = var.is_private ? "private" : "public"

  has_issues    = var.has_issues
  has_downloads = var.has_downloads
  has_projects  = var.has_projects
  has_wiki      = var.has_wiki

  delete_branch_on_merge = var.delete_branch_on_merge

  archive_on_destroy = var.archive_on_destroy

  archived = var.archived

  topics = var.topics
}