Skip to content

svalabs/terraform-provider-forgejo

Repository files navigation

Terraform Provider for Forgejo

This repository contains a Terraform provider for Forgejo — self-hosted lightweight software forge.

Contents

The Forgejo Terraform Provider allows managing resources within Forgejo. It is in an early stage and currently provides the following...

Resources:

Data Sources:

Using the Provider

Import the provider into your Terraform configuration:

terraform {
  required_providers {
    forgejo = {
      source = "svalabs/forgejo"
      version = "~> 0.1.0"
    }
  }
}

There are two methods for authenticating to the Forgejo API: using an API token, or with username and password.

It is recommended to supply an API token to authenticate with a given Forgejo host:

provider "forgejo" {
  host      = "http://localhost:3000"
  api_token = "1234567890abcdefghijklmnopqrstuvwxyz1234"
  # ...or use the FORGEJO_API_TOKEN environment variable
}

Alternatively, supply username and password to authenticate:

provider "forgejo" {
  host     = "http://localhost:3000"
  username = "admin"
  password = "passw0rd"
  # ...or use the FORGEJO_USERNAME / FORGEJO_PASSWORD environment variables
}

A personal repository can be created like so:

resource "forgejo_repository" "example" {
  name        = "new_personal_repo"
  description = "Purely for testing..."
}

A user repository can be created like so (requires administrative privileges):

resource "forgejo_user" "owner" {
  login = "new_user"
}

resource "forgejo_repository" "example" {
  owner       = forgejo_user.owner.login
  name        = "new_user_repo"
  description = "Purely for testing..."
}

An organization repository can be created like so:

resource "forgejo_organization" "owner" {
  name = "new_org"
}

resource "forgejo_repository" "example" {
  owner       = forgejo_organization.owner.name
  name        = "new_org_repo"
  description = "Purely for testing..."
}

These examples create repositories with most attributes set to their default values. However, many settings can be customized:

resource "forgejo_repository" "example" {
  owner          = forgejo_organization.owner.name
  name           = "new_org_repo"
  description    = "Purely for testing..."
  private        = true
  default_branch = "dev"
  auto_init      = true
  trust_model    = "collaborator"

  internal_tracker = {
    enable_time_tracker                   = false
    allow_only_contributors_to_track_time = false
    enable_issue_dependencies             = false
  }
}

Refer to the examples/ directory for more usage examples.

Developing & Contributing to the Provider

The CONTRIBUTING.md file is a basic outline on how to build and develop the provider.

Copyright and License

Copyright (c) 2024 SVA System Vertrieb Alexander GmbH.

Released under the terms of the Mozilla Public License (MPL-2.0).