Skip to content

bytebase/terraform-provider-bytebase

Repository files navigation

Terraform Provider Bytebase

This repository is the Terraform provider for Bytebase. A typical setup involves teams using Cloud vendors' Terraform provider to provision database instances, followed by using Terraform Bytebase Provider to prepare those instances ready for application use.

Overview

Real world example

https://github.com/bytebase/terraform-example and https://tf.bytebase.com.

Usage

You can download this provider at registry.terraform.io.

Please follow Manage Bytebase with Terraform to use the provider.

Development

Prerequisites

If you have problems running terraform in MacOS with Apple Silicon, you can following https://stackoverflow.com/questions/66281882/how-can-i-get-terraform-init-to-run-on-my-apple-silicon-macbook-pro-for-the-go and use the tfenv.

Prepare Bytebase OpenAPI server

# clone Bytebase to get the OpenAPI server
git clone git@github.com:bytebase/bytebase.git

git clone git@github.com:bytebase/terraform-provider-bytebase.git
# start Bytebase OpenAPI server
cd bytebase
# check https://github.com/bytebase/bytebase for starting the Bytebase server.
air -c scripts/.air.toml

Build and test

# install the provider in your local machine
cd terraform-provider-bytebase && make install

# test
# Any BYTEBASE_SERVICE_ACCOUNT/BYTEBASE_SERVICE_KEY/BYTEBASE_URL value should work since the service is mocked
TF_ACC=1 BYTEBASE_SERVICE_ACCOUNT=test@service.bytebase.com BYTEBASE_SERVICE_KEY=test_secret BYTEBASE_URL=https://bytebase.example.com go test -v ./...

# initialize the terraform for your example
# you need to set the service_account and service_key to your own
cd examples/setup && terraform init

# check the changes
terraform plan

# apply the changes
terraform apply

# print outputs
terraform output

# delete test resources
terraform destory

Generate docs

This will generate the doc template in the docs folder

Check https://github.com/hashicorp/terraform-plugin-docs and hashicorp/terraform-plugin-docs#141 for details.

GOOS=darwin GOARCH=amd64 go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs --provider-name=terraform-provider-bytebase

Release

Follow this doc to publish the provider.

Note: We need to publish a new tag for a new version, the tag must be a valid Semantic Version preceded with a v (for example, v1.2.3). There must not be a branch name with the same name as the tag.

  1. Develop and merge the feature code.
  2. Create a new PR to update the version in ./VERSION
  3. After the version is updated, the action ./.github/workflows/release.yml will use the newest version x.y.z to create a new tag vx.y.z, then use the tag to create the release.