Skip to content

pactflow/terraform-provider-pact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pact Broker - Terraform Provider

Terraform Provider for Pact Broker and Pactflow.

Build Status Coverage Status Go Report Card GoDoc slack

Introduction

Example:

terraform {
  required_providers {
    pact = {
      source = "pactflow/pact"
      version = "0.1.2" # check the version
    }
  }
}

variable "token" {
  type = string
}

provider "pact" {
  # For the OSS Broker
  # host = "http://localhost"
  # basic_auth_username = "pact_broker"
  # basic_auth_password = "pact_broker"

  # For a Pactflow Broker
  host = "https://mybroker.pact.dius.com.au"
  access_token = var.token
}

# Create a Pacticipant for our Product API
resource "pact_application" "product_api" {
  name = "product_api"
  repository_url = "github.com/foo/product_api"
}

# Create a Pacticipant for our Ecommerce Website
resource "pact_application" "ecommerce_web" {
  name = "ecommerce_web"
  repository_url = "github.com/foo/ecommerce_web"
}

# Create a secret
resource "pact_secret" "ci_token" {
  name = "CIToken"
  description = "Jenkins token for Pactflow"
  value = "my super secret value"
}

# Create a webhook to trigger a build when a contract changes
# Uses the Jenkins token from above
resource "pact_webhook" "product_api_changed" {
  description = "Trigger build when a contract changes between ecommerce_web and product_api"
  webhook_provider = {
    name = "product_api"
  }
  webhook_consumer = {
    name = "ecommerce_web"
  }
  request {
    url = "https://foo.com/some/endpoint"
    method = "POST"
    headers = {
      "Content-Type" = "application/json",
      "Authoriation" = "Bearer $${user.CIToken}"
    }
    body = <<EOF
{
  "pact": "$${pactbroker.pactUrl}"
}
EOF
  }

  events = ["contract_content_changed", "contract_published"]
  depends_on = [pact_application.product_api, pact_application.ecommerce_web, pact_secret.ci_token]
}

# Create a user
resource "pact_user" "somebody" {
  name = "Tester McPerson"
  email = "[email protected]"
  active = true
}

# Assign admin role to user
resource "pact_role" "somebody_admin" {
  role = "administrator"
  user = pact_user.somebody.uuid
}

# Enable authentication via Github and Google
# NOTE: This only applies to customers on the legacy (Cognito)
#       authentication. see https://docs.pactflow.io/docs/authentication/main/
resource "pact_authentication" "authentication" {
  github_organizations = ["pactflow"]
  google_domains = ["pactflow.io"]
}

Installing

Download the latest release and install into your Terraform plugin directory.

Linux or Mac OSX

Run the following to have the provider installed for you automatically:

curl -fsSL https://raw.githubusercontent.com/pactflow/terraform/master/scripts/install.sh | bash

Windows

Dowload the plugin to %APPDATA%\terraform.d\plugins.

Installation notes

The pact provider is published to the Terraform module registry and may be installed via the standard mechanisms. See the documentation at https://registry.terraform.io/providers/pactflow/pact/latest.

Using the plugin

https://registry.terraform.io/providers/pactflow/pact/latest

Plugin Type Platform Support Description
Pact Provider Pact Broker + Pactflow Configures a target Pact Broker (such as a pactflow.io account)
Pacticipant Resource Pact Broker + Pactflow Create applications (known as Pacticipants)
Webhook Resource Pact Broker + Pactflow Configures a webhook to trigger on certain platform events
Secret Resource Pactflow Create an encrypted secret for use in Webhooks
API Token Resource Pactflow Manage Pactflow API Tokens
Users Resource Pactflow (cloud only) Manage Pactflow Users
Roles Resource Pactflow Manage Pactflow Roles
Teams Resource Pactflow Manage Pactflow Teams
Environments Resource Pact Broker + Pactflow Manage Environments
Authentication Settings Resource Pactflow (cloud only) Manage Pactflow Authentication (Github, Google etc.)

See our Docs folder for all plugins.

Importing Resources

All resources (except for Roles) support importing.

Developing

Requirements

Building locally

Note: This project uses Go Modules making it safe to work with it outside of your existing GOPATH. The instructions that follow assume a directory in your home directory outside of the standard GOPATH (e.g. $HOME/development/terraform-providers/).

To compile the provider, run make build. This will build the provider and put the provider binary in the ./bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-aws
...

Roadmap

Plan for the next few months:

  • Pacticipants
  • Webhooks
  • Secrets (Pactflow only)
  • Users (Pactflow only)
  • Teams (Pactflow only)
  • Assign users to teams (Pactflow only)
  • System Users (Pactflow only)
  • Custom role creation (Pactflow only)
  • Role assignment (Pactflow only)
  • Better error messages for HTTP / runtime failures
  • Acceptance tests
  • Pact tests
  • Better code coverage
  • Extract Client into separate SDK package
  • Publish 1.0.0

Want to see something else here? Have you say on our Pact Feature Request board.