Skip to content

phasehq/terraform-provider-phase

Repository files navigation

Terraform Provider for Phase

This Terraform provider allows you to manage secrets in Phase from your Terraform configurations.

Usage

To use the latest version of the provider in your Terraform configuration, add the following terraform block:

terraform {
  required_providers {
    phase = {
      source  = "phasehq/phase"
      version = "0.1.1" // replace with latest version
    }
  }
}

# Configure the Phase Provider
provider "phase" {
  phase_token = "pss_service:v1:..." # or "pss_user:v1:..." // A Phase Service Token or a Phase User Token (PAT)
}

# Retrieve all secrets under a specific path
data "phase_secrets" "all" {
  env    = "development"
  app_id = "your-app-id"
  path   = "/"
}

# Retrieve a specific secret
output "secret_keys" {
  value = data.phase_secrets.all.secrets["STRIPE_KEY"]
  sensitive = true
}

// Fetch all secrets
# Use secrets
output "all_secret_keys" {
  value = data.phase_secrets.all.secrets
}

See the Phase Provider documentation for all the available options and data sources.

Requirements

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go build command:
     go build -o terraform-provider-phase

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).

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

To generate or update documentation, run go generate.

  1. Create a local plugin directory for Terraform:

    mkdir -p ~/.terraform.d/plugins/registry.terraform.io/phasehq/phase/0.1.0/$(go env GOOS)_$(go env GOARCH)
  2. Move the compiled binary to the plugin directory:

    mv terraform-provider-phase ~/.terraform.d/plugins/registry.terraform.io/phasehq/phase/0.1.0/$(go env GOOS)_$(go env GOARCH)
  3. In your Terraform configuration, specify the local version:

    terraform {
      required_providers {
        phase = {
          source  = "registry.terraform.io/phasehq/phase"
          version = "0.1.0"
        }
      }
    }
  4. Initialize terraform

    terraform init
    
  5. Run terraform plan

    terraform plan
    
  6. Initialize terraform

    terraform apply
    

License

This provider is distributed under the MIT License.