Scalr / terraform-provider-scalr

Terraform Provider to manage Scalr TACO
Mozilla Public License 2.0
19 stars 11 forks source link

Terraform provider for Scalr

Build status Coverage status

The Scalr Terraform provider can be used to manage the components within the Scalr IaCP. This will allow you to automate the creation of workspaces, variables, VCS providers and much more.

Using the provider

Requirements

Follow the instructions on the official documentation page to learn how to use it.

Developing the provider

Requirements

Setup

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.19+ is required).

Clone the repository:

$ git clone git@github.com:Scalr/terraform-provider-scalr

Enter the provider directory and build the provider:

$ cd $GOPATH/src/github.com/Scalr/terraform-provider-scalr
$ make build

If you are on macOS and wish to cross-compile the provider for GNU/Linux you can use make build-linux instead. Note that the behaviour of the linker has changed in Go 1.15. If you are not using the makefile to build you will need to update your build flags to match it.

You should have the terraform-provider-scalr binary in your current working directory.

Running

Tag current commit with some valid semantic version (7.7.7 for example) or use VER variable as an argument for make. Create a terraform configuration file (main.tf) with following content:

provider scalr {}

terraform {
    required_providers {
        scalr = {
            source = "registry.scalr.io/scalr/scalr"
            version = "7.7.7"
        }
    }
}

Export SCALR_HOSTNAME and SCALR_TOKEN environment variables. Execute VER=7.7.7 make install. This will build the provider binary and install it to the user's provider directory (see GNUMakefile). The terraform init now will find the correct provider version.

Debugging provider

Start provider process by your IDE or debugger with -debug flag set.

./terraform-provider-scalr -debug=true

It will print output like the following:

Provider started, to attach Terraform set the TF_REATTACH_PROVIDERS env var:

        TF_REATTACH_PROVIDERS='{"registry.scalr.io/scalr/scalr":{"Protocol":"grpc","Pid":30636,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/8g/knswsjzs623b63ln4m9wxf180000gn/T/plugin4288941537"}}}'

Either export it, or prefix every Terraform command with it.

For more info refer to the documentation.

Using a local copy of go-scalr

This provider uses go-scalr to call the Scalr API.

For development purposes you can make the provider use your local copy of go-scalr like this:

go mod edit -replace github.com/scalr/go-scalr=/Users/<username>/Projects/scalr/go-scalr # this should be your path

Remember to remove this link before committing:

go mod edit -dropreplace github.com/scalr/go-scalr

To update the go-scalr version:

go get github.com/scalr/go-scalr@master

Testing

Unit tests

$ make test

Acceptance tests

You will need to set up the environment variables for your Scalr installation. For example:

export SCALR_HOSTNAME=abcdef.scalr.com
export SCALR_TOKEN=.....

You can run the acceptance tests like this:

make testacc

If you want to run one or more specific tests you can pass the targets as an environment variable:

TESTARGS="-run TestAccScalrWorkspace_basic TestAccScalrWorkspace_update" make testacc

CI

Acceptance tests

The required parameters for creating a container will be determined automatically based on existing branches and pull requests in other repositories. No more need to add [API_BRANCH]