Skip to content

snowplow-devops/terraform-provider-redash

Repository files navigation

Redash Terraform Provider

Actions Status Go Report Card Release License

Overview

Terraform provider for managing Redash configurations.

Quick start

Assuming git is installed:

 host> git clone https://github.com/snowplow-devops/terraform-provider-redash
 host> cd terraform-provider-redash
 host> make test
 host> make

To remove all build files:

 host> make clean

To format the golang code in the source directory:

 host> make format

Note: Always run format before submitting any code.

Note: The make test command also generates a code coverage file which can be found at build/coverage/coverage.html.

Installation

First download the pre-compiled binary for your platform from the release assets at the following links or generate the binaries locally using the provided make command:

https://github.com/snowplow-devops/terraform-provider-redash/releases/latest

From here you will need to move the binary into your Terraform plugins directory - depending on your platform / installation this might change but generally speaking they are located at:

  • Darwin & Linux: ~/.terraform.d/plugins
  • Windows: %APPDATA%\terraform.d\plugins

How to use?

Setting up the provider

To actually start tracking Snowplow events from Terraform you will need to configure the provider and a resource:

Before using the provider, you will need an environment variable set with your personal API Key (which can be found in your Redash profile)

$ export REDASH_API_KEY="<YourPersonalAPIKeyHere>"
# Minimal configuration
provider "redash" {
  redash_uri = "https://com.acme.redash"
}

With the provider configured, we can now use data sources and manage resources.

Users

data "redash_user" "rrunner" {
  id = 1
}

resource "redash_user" "wcoyote" {
  name   = "Wile E. Coyote"
  email  = "[email protected]"
  groups = [32,1]
}

Groups

data "redash_group" "geniuses" {
  id = 35
}

resource "redash_group" "runners" {
  name = "Beep Beep"
}

Data Sources

Please note that the list of required/accepted options varies wildly by type. This is entirely dependent on the Redash installation that you are connecting to. For a detailed list of types and options, you can GET from the /api/data_sources/types endpoint on your Redash instance.

data "redash_data_source" "acme_corp" {
  id = 123
}

resource "redash_data_source" "acme_corp" {
   name = "ACME Corporation Product Database"
   type = "redshift"

   options {
     host     = "newproducts.acme.com"
     port     = 5439
     dbname   = "products"
     user     = "wcoyote"
     password = "eth3LbeRt"
    }
}

resource "redash_group_data_source_attachment" "wcoyote_acme" {
  group_id       = redash_group.geniuses.id
  data_source_id = redash_data_source.acme_corp.id
}

For more detailed documentation, please see the Terraform Provider documentaton at https://registry.terraform.io/providers/snowplow-devops/redash/latest

Publishing

This is handled through CI/CD on Github Actions. However all binaries will be generated by using the make command for local publishing.

Copyright and license

The Terraform Redash Provider is copyright 2019-2020 Snowplow Analytics Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.