Giter Club home page Giter Club logo

terraform-databricks-aws-workspace's Introduction

โ—๏ธ Important

๐Ÿ‘‰ This Terraform module assumes you have access to: https://accounts.cloud.databricks.com

๐Ÿ‘‰ Databricks account username: databricks_account_username

๐Ÿ‘‰ Databricks account password: databricks_account_password

๐Ÿ‘‰ Databricks account id, databricks_account_id can be found on the top right corner of the page, once you're logged in.

๐Ÿ‘‰ Part 2: Terraform module for Databricks Workspace management


Databricks deployment

Versions

  • Module tested for Terraform 1.0.1.
  • databrickslabs/databricks provider version 0.3.5
  • AWS provider version 3.47.
  • main branch: Provider versions not pinned to keep up with Terraform releases.
  • tags releases: Tags are pinned with versions (use ).

Usage

Option 1:

terrafrom init
terraform plan -var='teamid=tryme' -var='prjid=project1'
terraform apply -var='teamid=tryme' -var='prjid=project1'
terraform destroy -var='teamid=tryme' -var='prjid=project1'

Note: With this option please take care of remote state storage

Option 2:

Recommended method (stores remote state in S3 using prjid and teamid to create directory structure):

  • Create python 3.6+ virtual environment
python3 -m venv <venv name>
  • Install package:
pip install tfremote --upgrade
  • Set below environment variables:
export TF_AWS_BUCKET=<remote state bucket name>
export TF_AWS_BUCKET_REGION=us-west-2
export TF_AWS_PROFILE=<profile from ~/.ws/credentials>

or

  • Set below environment variables:
export TF_AWS_BUCKET=<remote state bucket name>
export TF_AWS_BUCKET_REGION=us-west-2
export AWS_ACCESS_KEY_ID=<aws_access_key_id>
export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
  • Update main.tf file with required values.

  • Run and verify the output before deploying:

tf -c=aws plan -var='teamid=foo' -var='prjid=bar'
  • Run below to deploy:
tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
  • Run below to destroy:
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'

NOTE:

Databricks workspace creation with new role

module "databricks_workspace" {
  source = "git::[email protected]:tomarv2/terraform-databricks-aws-workspace.git"

  # NOTE: One of the below is required:
  # - 'profile_for_iam' - for IAM creation (if none is provided 'default' is used)
  # - 'existing_role_name'
  profile_for_iam             = "iam-admin"
  aws_region                  = "us-east-2"
  databricks_account_username = "[email protected]"
  databricks_account_password = "sample123!"
  databricks_account_id       = "1234567-1234-1234-1234-1234567"
  # -----------------------------------------
  # Do not change the teamid, prjid once set.
  teamid = var.teamid
  prjid  = var.prjid
}

Databricks workspace creation with existing role

module "databricks_workspace" {
  source = "git::[email protected]:tomarv2/terraform-databricks-aws-workspace.git"

  # NOTE: One of the below is required:
  # - 'profile_for_iam' - for IAM creation (if none is provided 'default' is used)
  # - 'existing_role_name'
  existing_role_arn          = "arn:aws:iam::123456789012:role/demo-role"
  aws_region                  = "us-east-2"
  databricks_account_username = "[email protected]"
  databricks_account_password = "sample123!"
  databricks_account_id       = "1234567-1234-1234-1234-1234567"
  # -----------------------------------------
  # Do not change the teamid, prjid once set.
  teamid = var.teamid
  prjid  = var.prjid
}

Please refer to examples directory link for references.

Coming up:

Troubleshooting:

IAM policy error

If you notice below error:

Error: MALFORMED_REQUEST: Failed credentials validation checks: Spot Cancellation, Create Placement Group, Delete Tags, Describe Availability Zones, Describe instances, Describe Instance Status, Describe Placement Group, Describe Route Tables, Describe Security Groups, Describe Spot Instances, Describe Spot Price History, Describe Subnets, Describe Volumes, Describe Vpcs, Request Spot Instances
  • Try creating workspace from UI:

create_workspace_error

  • Verify if the role and policy exists (assume role should allow external id)

iam_role_trust_error

Requirements

Name Version
terraform >= 1.0.1
aws ~> 3.47
databricks 0.3.5
random ~> 3.1
time ~> 0.7

Providers

Name Version
aws 3.38.0
databricks 0.3.3
databricks.created_workspace 0.3.3
databricks.mws 0.3.3
random 3.1.0
time 0.7.1

Modules

Name Source Version
iam_policies git::[email protected]:tomarv2/terraform-aws-iam-policies.git v0.0.4
iam_role git::[email protected]:tomarv2/terraform-aws-iam-role.git//modules/iam_role_external v0.0.4
s3 git::[email protected]:tomarv2/terraform-aws-s3.git v0.0.3
vpc git::[email protected]:tomarv2/terraform-aws-vpc.git v0.0.2

Resources

Name Type
aws_s3_bucket_policy.root_bucket_policy resource
databricks_mws_credentials.this resource
databricks_mws_networks.this resource
databricks_mws_storage_configurations.this resource
databricks_mws_workspaces.this resource
databricks_token.pat resource
random_string.naming resource
time_sleep.wait resource
databricks_aws_assume_role_policy.this data source
databricks_aws_bucket_policy.this data source
databricks_aws_crossaccount_policy.cross_account_iam_policy data source

Inputs

Name Description Type Default Required
aws_region default aws region string "us-west-2" no
databricks_account_id External ID provided by third party. string n/a yes
databricks_account_password databricks account password string n/a yes
databricks_account_username databricks account username string n/a yes
existing_role_name If you want to use existing role name, else a new role will be created string null no
prjid (Required) Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply' string n/a yes
profile_for_iam profile to use for IAM string null no
profile_to_use Getting values from ~/.aws/credentials string "default" no
teamid (Required) Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply' string n/a yes

Outputs

Name Description
databricks_credentials_id databricks credentials id
databricks_deployment_name databricks deployment name
databricks_host databricks hostname
databricks_mws_credentials_id databricks mws credentials id
databricks_mws_network_id databricks mws network id
databricks_mws_storage_bucket_name databricks mws storage bucket name
databricks_mws_storage_id databricks mws storage id
iam_role_arn iam role arn
inline_policy_id inline policy id
pat_token_duration databricks pat
s3_bucket_arn s3 bucket arn
s3_bucket_id s3 bucket id
s3_bucket_name s3 bucket name
storage_configuration_id databricks storage configuration id
vpc_id vpc id
workspace_url databricks workspace url

terraform-databricks-aws-workspace's People

Contributors

tomarv2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.