Skip to content

opsgenie/terraform-provider-opsgenie

Repository files navigation

Terraform Provider

Development

Everything needed to start local development and testing of the Provider plugin

1. Requirements

  • Go 1.18 (or higher, to build the provider plugin)
  • Terraform 0.12.x (To test the plugin)

2. Development Setup

Cloning the project

export GOPATH="${GOPATH:=$HOME/go}"

mkdir -p "$GOPATH/src/github.com/opsgenie"

cd "$GOPATH/src/github.com/opsgenie"

git clone git@github.com:opsgenie/terraform-provider-opsgenie

3. Compiling The Provider

export GOPATH="${GOPATH:=$HOME/go}"
cd "$GOPATH/src/github.com/opsgenie"

# Compile all versions of the provider and install it in GOPATH.
make build

# Only compile the local executable version (Faster)
make dev

Running tests on the Provider

Run all local unit tests.

make test

4. Using the Compiled Provider

Configure Terraform to use the compiled provider.

This configuration makes use of the dev_overrides.

See the [Manual Setup][Manual Setup] for more details.

# Creates $HOME/.terraformrc
make setup

Manual setup

Click to expand
  1. Create the .terraformrc file on your in your home folder using touch ~/.terraformrc
  2. Configure dev_overrides in your ~/.terraformrc as show below:
    provider_installation {
      dev_overrides {
        # Remember to replace <home dir> with your username
        "opsgenie/opsgenie" = "/home/<home dir>/go/bin"
      }
      direct {}
    }
  3. Run make build

New OpsGenie Terraform project

  1. Create a basic terraform project locally with a main.tf file:

    terraform {
      required_providers {
        opsgenie = {
          source  = "opsgenie/opsgenie"
          version = ">=0.6.0" # version can be omitted
        }
      }
    }
    
    # Configure the Opsgenie Provider
    provider "opsgenie" {
      api_key = "<insert api_key>" # https://support.atlassian.com/opsgenie/docs/api-key-management/
      api_url = "api.opsgenie.com" # can be a stage instance url for devs
    }
    
    resource "opsgenie_team" {
      name        = "Dev-Provider test team"
      description = "New team made using in-development OpsGenie provider"
    }
  2. And, Add respective terraform change files which you want to apply on your OG instance

  3. Run respective terraform commands to test the provider as per your convenience Install the currently available provider with tf init terraform plan and terraform init will use providers from the configured paths in $HOME/.terraformrc terraform will output an error if no provider is found in the dev_overrides path. (make build)

Removing the 'dev_override' again

This allows you to use the normal release versions of the opsgenie/opsgenie provider.

Note Removes $HOME/.terraformrc

make clean