Skip to content

Latest commit

 

History

History
223 lines (159 loc) · 5.57 KB

README.md

File metadata and controls

223 lines (159 loc) · 5.57 KB

Redash Terraform Provider

Actions Status Go Report Card Release License

Overview

Terraform provider for managing Redash configurations.

Quick start

Assuming git is installed:

$ git clone https://github.com/digitalpoetry/terraform-provider-redash
$ cd terraform-provider-redash
$ make test
$ make

To remove all build files:

$ make clean

To format the golang code in the source directory:

$ 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/digitalpoetry/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

# Minimal configuration
provider "redash" {
  redash_uri = "https://redash.exmaple.com"
  api_key    = "<YourPersonalAPIKeyHere>"
}

To avoid exposing your secret API key in code you can, preferrably, set it as a value of an environment variable named REDASH_API_KEY. The API key can be found on your Redash profile page.

$ export REDASH_API_KEY="<YourPersonalAPIKeyHere>"

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  = "wcoyote@acme.com"
  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
}

Queries

data "redash_query" "my_query" {
  id = 1
}

resource "redash_query" "my_query" {
  name           = "My Query"
  data_source_id = redash_data_source.acme_corp.id
  query          = "SELECT 1 + 1"
  description    = "A query like no other"
}

Dashboards

data "redash_dashboard" "existing_dashboard" {
  slug = "my-dashboard"
}

resource "redash_dashboard" "my_dashboard" {
  name = "My dashboard"
}

Visualizations

data "redash_visualization" "this" {
  query_id         = 1
  visualization_id = 7
}

resource "redash_visualization" "table" {
  query_id = 1
  name     = "Results table"
  type     = "TABLE"
}

Widgets

data "redash_widget" "this" {
  id             = 27
  dashboard_slug = "service-slos"
}

resource "redash_widget" "text_widget" {
  dashboard_slug = redash_dashboard.this.slug
  text           = "Welcome to my dashboard"
}

resource "redash_widget" "visualization_widget" {
  dashboard_slug   = redash_dashboard.this.slug
  visualization_id = 1
}

For more detailed documentation, please see the Terraform Provider documentaton at https://registry.terraform.io/providers/digitalpoetry/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 was forked from snowplow-devops/terraform-provider-redash.

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.