Skip to content

Commit

Permalink
Merge pull request #165 from mckornfield/solr-install
Browse files Browse the repository at this point in the history
Add solr helm terraform deployment
  • Loading branch information
dadiorchen authored May 30, 2023
2 parents 27228c7 + ff139c6 commit 597010f
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api_gateway/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
1. install terraform `brew install terraform`
1. set up access to s3/spaces
1. create access key in control panel, note key id and access key
2. update ~/.netrc to hold access like with a line like `sfo2.digitaloceanspaces.com spaces login KEY_ID password ACCESS_KEY`
2. update ~/.netrc to hold access like with a line like `machine sfo2.digitaloceanspaces.com login KEY_ID password ACCESS_KEY`
1. load keys by running `source setup_keys.sh`
1. `terraform init` get ready to run terraform
1. `terraform plan` to see changes that will be applied
Expand Down
9 changes: 9 additions & 0 deletions scripts/export_do_tf_tokens.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

my_env=${1:?Environment is required}
line=$(grep "digitalocean.${my_env}.treetracker.org" ~/.netrc)
export DIGITALOCEAN_TOKEN=$(echo $line | awk '{print $6}')

netrc_string=$(grep "sfo2.${my_env}.digitaloceanspaces.com" ~/.netrc)
export AWS_ACCESS_KEY_ID=$(echo $netrc_string | awk '{print $4}')
export AWS_SECRET_ACCESS_KEY=$(echo $netrc_string | awk '{print $6}')
3 changes: 3 additions & 0 deletions solr/cleanup_clusterroles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
kubectl delete clusterrole solr-operator-role solr-operator-zookeeper-operator
kubectl delete clusterrolebinding solr-operator-rolebinding solr-operator-zookeeper-operator
17 changes: 17 additions & 0 deletions solr/dev/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-dev-terraform"
key = "terraform-solr.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions solr/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "solr" {
source = "../solr_chart"
cluster_name = "dev-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions solr/dev/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
17 changes: 17 additions & 0 deletions solr/prod/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-test-terraform"
key = "terraform-solr.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions solr/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "solr" {
source = "../solr_chart"
cluster_name = "prod-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions solr/prod/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
49 changes: 49 additions & 0 deletions solr/solr_chart/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
data "digitalocean_kubernetes_cluster" "dev" {
name = var.cluster_name
}

provider "helm" {
kubernetes {
host = data.digitalocean_kubernetes_cluster.dev.endpoint
token = data.digitalocean_kubernetes_cluster.dev.kube_config[0].token
cluster_ca_certificate = base64decode(
data.digitalocean_kubernetes_cluster.dev.kube_config[0].cluster_ca_certificate
)
}
}

locals {
solr_version = "0.7.0"
}
resource "helm_release" "solr_operator" {
name = "solr-operator"
repository = "https://solr.apache.org/charts"
chart = "solr-operator"
version = local.solr_version
namespace = "solr"
create_namespace = true


values = [
"${file("${path.module}/solr-operator-values.yaml")}",
var.solr_operator_values_file
]

}


resource "helm_release" "solr" {
name = "solr"
repository = "https://solr.apache.org/charts"
chart = "solr"
version = local.solr_version
namespace = "solr"
create_namespace = true


values = [
"${file("${path.module}/solr-values.yaml")}",
var.solr_values_file
]

}
10 changes: 10 additions & 0 deletions solr/solr_chart/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
3 changes: 3 additions & 0 deletions solr/solr_chart/solr-operator-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zookeeper-operator:
crd:
create: true
Empty file.
13 changes: 13 additions & 0 deletions solr/solr_chart/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "cluster_name" {
type = string
}

variable "solr_operator_values_file" {
type = string
default = ""
}

variable "solr_values_file" {
type = string
default = ""
}
17 changes: 17 additions & 0 deletions solr/test/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-test-terraform"
key = "terraform-solr.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions solr/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "solr" {
source = "../solr_chart"
cluster_name = "test-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions solr/test/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}

0 comments on commit 597010f

Please sign in to comment.