All Projects → frankfarrell → terraform-provider-redshift

frankfarrell / terraform-provider-redshift

Licence: MIT License
Provider for AWS Redshift entities, eg Users, Groups, Permissions, Schemas, Databases

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
HCL
1544 projects
Makefile
30231 projects

Projects that are alternatives of or similar to terraform-provider-redshift

terraform-provider-dockermachine
Docker machine provider for Terraform
Stars: ✭ 20 (-56.52%)
Mutual labels:  terraform-provider
go-graylog
Graylog API client for Go and terraform provider for Graylog
Stars: ✭ 45 (-2.17%)
Mutual labels:  terraform-provider
terraform-provider-opennebula
Terraform provider for OpenNebula
Stars: ✭ 38 (-17.39%)
Mutual labels:  terraform-provider
jobAnalytics and search
JobAnalytics system consumes data from multiple sources and provides valuable information to both job hunters and recruiters.
Stars: ✭ 25 (-45.65%)
Mutual labels:  redshift
terraform-provider-statuscake
Terraform StatusCake provider.
Stars: ✭ 26 (-43.48%)
Mutual labels:  terraform-provider
terraform-provider-influxdb
Terraform InfluxDB provider
Stars: ✭ 19 (-58.7%)
Mutual labels:  terraform-provider
terraform-provider-testing
An experimental Terraform provider to assist in writing tests for Terraform modules
Stars: ✭ 59 (+28.26%)
Mutual labels:  terraform-provider
terraform-provider-vix
VMware VIX provider for Terraform
Stars: ✭ 96 (+108.7%)
Mutual labels:  terraform-provider
terraform-provider-k8s
Kubernetes Terraform provider with support for raw manifests
Stars: ✭ 129 (+180.43%)
Mutual labels:  terraform-provider
terraform-provider-ovirt
Terraform provider for oVirt 4.x
Stars: ✭ 125 (+171.74%)
Mutual labels:  terraform-provider
terraform-provider-jxadmin
A Jenkins X provider for terraform
Stars: ✭ 14 (-69.57%)
Mutual labels:  terraform-provider
terraform-provider-launchdarkly
Terraform LaunchDarkly provider
Stars: ✭ 16 (-65.22%)
Mutual labels:  terraform-provider
terraform-provider-citrixadc
Terraform Custom Provider for Citrix ADC (formerly Citrix NetScaler)
Stars: ✭ 89 (+93.48%)
Mutual labels:  terraform-provider
terraform-provider-junos
Terraform's provider for Junos devices
Stars: ✭ 44 (-4.35%)
Mutual labels:  terraform-provider
terraform-provider-elasticstack
Terraform provider for Elastic Stack
Stars: ✭ 61 (+32.61%)
Mutual labels:  terraform-provider
terraform-provider-dns
Supports DNS updates (RFC 2136) and can optionally be configured with secret key based transaction authentication (RFC 2845).
Stars: ✭ 75 (+63.04%)
Mutual labels:  terraform-provider
snowplow-rdb-loader
Stores Snowplow enriched events in Redshift
Stars: ✭ 21 (-54.35%)
Mutual labels:  redshift
terraform-provider-logzio
Terraform provider for logz.io alerts, endpoints and users
Stars: ✭ 18 (-60.87%)
Mutual labels:  terraform-provider
terraform-provider-panos
Terraform Panos provider
Stars: ✭ 56 (+21.74%)
Mutual labels:  terraform-provider
terraform-provider-inwx
terraform provider for INWX
Stars: ✭ 23 (-50%)
Mutual labels:  terraform-provider

Terraform Redshift Provider

Codacy Badge Build Status Gitter chat

Manage Redshift users, groups, privileges, databases and schemas. It runs the SQL queries necessary to manage these (CREATE USER, DELETE DATABASE etc) in transactions, and also reads the state from the tables that store this state, eg pg_user_info, pg_group etc. The underlying tables are more or less equivalent to the postgres tables, but some tables are not accessible in Redshift.

Currently supports users, groups, schemas and databases. You can set privileges for groups on schemas. Per user schema privileges will be added at a later date.

Note that schemas are the lowest level of granularity here, tables should be created by some other tool, for instance flyway.

Get it:

Download for amd64 (for other architectures and OSes you can build from source as descibed below)

Add to terraform plugins directory: https://www.terraform.io/docs/configuration/providers.html#third-party-plugins

You wll need to run terraform init to download install the plugin from here

Examples:

Provider configuration

provider redshift {
  "url" = "localhost",
  user = "testroot",
  password = "Rootpass123",
  database = "dev"
}

Creating an admin user who is in a group and who owns a new database, with a password that expires

# Create a user
resource "redshift_user" "testuser"{
  "username" = "testusernew" # User name are not immutable. 
  # Terraform can't read passwords, so if the user changes their password it will not be picked up. One caveat is that when the user name is changed, the password is reset to this value
  "password" = "Testpass123" # You can pass an md5 encryted password here by prefixing the hash with md5
  "valid_until" = "2018-10-30" # See below for an example with 'password_disabled'
  "connection_limit" = "4"
  "createdb" = true
  "syslog_access" = "UNRESTRICTED"
  "superuser" = true
}

# Add the user to a new group
resource "redshift_group" "testgroup" {
  "group_name" = "testgroup" # Group names are not immutable
  "users" = ["${redshift_user.testuser.id}"] # A list of user ids as output by terraform (from the pg_user_info table), not a list of usernames (they are not immnutable)
}

# Create a schema
resource "redshift_schema" "testschema" {
  "schema_name" = "testschema", # Schema names are not immutable
  "owner" ="${redshift_user.testuser.id}", # This defaults to the current user (eg as specified in the provider config) if empty
  "cascade_on_delete" = true
}

# Give that group select, insert and references privileges on that schema
resource "redshift_group_schema_privilege" "testgroup_testchema_privileges" {
  "schema_id" = "${redshift_schema.testschema.id}" # Id rather than group name
  "group_id" = "${redshift_group.testgroup.id}" # Id rather than group name
  "select" = true
  "insert" = true
  "update" = false
  "references" = true
  "delete" = false # False values are optional
}

You can only create resources in the db configured in the provider block. Since you cannot configure providers with the output of resources, if you want to create a db and configure resources you will need to configure it through a terraform_remote_state data provider. Even if you specifiy the name directly rather than as a variable, since providers are configured before resources you will need to have them in separate projects.

# First file:

resource "redshift_database" "testdb" {
  "database_name" = "testdb", # This isn't immutable
  "owner" ="${redshift_user.testuser.id}",
  "connection_limit" = "4"
}

output "testdb_name" {
  value = "${redshift_database.testdb.database_name}"
}

# Second file: 

data "terraform_remote_state" "redshift" {
  backend = "s3"
  config {
    bucket = "somebucket"
    key = "somekey"
    region = "us-east-1"
  }
}

provider redshift {
  "url" = "localhost",
  user = "testroot",
  password = "Rootpass123",
  database = "${data.terraform_remote_state.redshift.testdb_name}"
}

Creating a user who can only connect using IAM Credentials as described here

resource "redshift_user" "testuser"{
  "username" = "testusernew",
  "password_disabled" = true # No need to specify a pasword is this is true
  "connection_limit" = "1"
}

Things to note

Limitations

For authoritative limitations, please see the Redshift documentations.

  1. You cannot delete the database you are currently connected to.
  2. You cannot set table specific privileges since this provider is table agnostic (for now, if you think it would be feasible to manage tables let me know)
  3. On importing a user, it is impossible to read the password (or even the md hash of the password, since Redshift restricts access to pg_shadow)

I usually connect through an ssh tunnel, what do I do?

The easiest thing is probably to update your hosts file so that the url resolves to localhost

Contributing:

Prequisites to development

  1. Go installed
  2. Terraform installed locally

Building:

  1. Run go build -o terraform-provider-redshift_v0.0.1_x4.exe. You will need to tweak this with GOOS and GOARCH if you are planning to build it for different OSes and architectures
  2. Add to terraform plugins directory: https://www.terraform.io/docs/configuration/providers.html#third-party-plugins

You can debug crudely by setting the TF_LOG env variable to DEBUG. Eg

$ TF_LOG=DEBUG terraform apply

TODO

  1. Database property for Schema
  2. Schema privileges on a per user basis
  3. Add privileges for languages and functions
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].