Skip to content

twentyfourg/terraform-provider-dev24g

Repository files navigation

24G Terraform Bitbucket Provider

Requirements

  • Terraform 0.12.x
  • Go 1.11 (to build the provider plugin)

In order to authenticate with Bitbucket, an App Password must be created (Personal Settings > App Passwords). Give it all permissions as it is still scoped to the permissions of your account.

The following environment variables are required:

export BITBUCKET_USERNAME=<bitbucket username>
export BITBUCKET_PASSWORD=<bitbucket app password>

Building and Installing The Provider

Clone repository to: $GOPATH/src/github.com/twentyfourg/terraform-provider-dev24g

$ export GOPATH=$HOME/go
$ mkdir -p $GOPATH/src/github.com/twentyfourg; cd $GOPATH/src/github.com/twentyfourg
$ git clone [email protected]:twentyfourg/terraform-provider-dev24g.git

Enter the provider directory and build the provider. go install puts the new binary into $HOME/go/bin.

$ cd $GOPATH/src/src/github.com/twentyfourg/terraform-provider-dev24g
$ go install

Copy installed provider into the terraform plugins directory

mkdir -p $HOME/.terraform.d/plugins/
cp $GOPATH/bin/terraform-provider-dev24g $HOME/.terraform.d/plugins

Using the provider

# Configure the Provider
provider "dev24g" {
  workspace = "24g"
}

data "dev24g_bitbucket_repository" "api" {
  name      = "796-4-1-vxp-api"
}

resource "dev24g_bitbucket_deployment" "evan" {
  name       = "evan"
  stage      = "Test"
  repository = "${data.dev24g_bitbucket_repository.api.workspace}/${data.dev24g_bitbucket_repository.api.name}"
}

resource "dev24g_bitbucket_deployment_variable" "foobar" {
  key        = "foo"
  value      = "bar"
  secured    = false
  deployment = dev24g_bitbucket_deployment.evan.id
}

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.11+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

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

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

In order to test the provider, you can simply run make test.

$ make test