Skip to content

Commit

Permalink
Streamline staging and production deployment config
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagojsag authored and yulia-bel committed Nov 21, 2022
1 parent a641053 commit 860441f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 61 deletions.
22 changes: 6 additions & 16 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
- Terraform + Terragrunt
- Kubectl

## Geo data seeding

For both scenarios, be sure to set the corresponding variable back to `false` and run `terragrunt apply` to destroy
the import servers, which are powerful and expensive.

### For production or staging

- On the `kubernetes` TF project, set `load_fresh_data_staging` or `load_fresh_data_prod` to true
- Run `terragrunt apply`

### For other envs

- On the `kubernetes` TF project, set `load_fresh_data` to true on the nested value inside the `environments` variable.
See the `enviorment` module definition in the root `main.tf` file for info - look into the `for_each` default value.
- Run `terragrunt apply`

## Deploying new environments

The infrastructure is deployed using Terraform, and set up in a way that makes it very easy to deploy new, independent
Expand Down Expand Up @@ -73,3 +57,9 @@ The `value` in the key-value pair is an object with a set of properties, all of
as part of the initial data import process. Defaults to `["seed-data"]`
- `image_tag`: tag of the different docker images to pull from the container registry. Does not apply to the Redis
image. Defaults to the same value as `key`.

### Handling production and staging

The production and staging environments are always deployed, even if they are not declared in the `environments` variable.
However, if you'd like to customize their behavior (for example, reload fresh data), you can explicitly add them to the
`environments` variable, and specify your custom values for each configuration, as you would for any other env.
20 changes: 9 additions & 11 deletions infrastructure/kubernetes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ terraform {

data "terraform_remote_state" "core" {
backend = "s3"
config = {
config = {
bucket = var.tf_state_bucket
region = var.aws_region
key = "core.tfstate"
Expand All @@ -36,18 +36,16 @@ resource "github_actions_secret" "mapbox_api_token_secret" {

module "environment" {
for_each = merge(var.environments, {
staging = {
load_fresh_data = var.load_fresh_data_staging
data_import_arguments = var.data_import_arguments_staging
staging = merge({
load_fresh_data = false
data_import_arguments = ["seed-data"]
image_tag = "staging"
api_env_vars = lookup(lookup(var.environments, "staging", {}), "api_env_vars", [])
},
production = {
load_fresh_data = var.load_fresh_data_prod
data_import_arguments = var.data_import_arguments_prod
}, lookup(var.environments, "staging", {})),
production = merge({
load_fresh_data = false
data_import_arguments = ["seed-data"]
image_tag = "main"
api_env_vars = lookup(lookup(var.environments, "production", {}), "api_env_vars", [])
}
}, lookup(var.environments, "production", {})),
})
source = "./modules/env"

Expand Down
24 changes: 0 additions & 24 deletions infrastructure/kubernetes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ variable "environments" {
description = "A list of environments"
}

variable "load_fresh_data_staging" {
type = bool
default = false
description = "If a new data import should be triggered for the staging app. Clears the current database."
}

variable "load_fresh_data_prod" {
type = bool
default = false
description = "If a new data import should be triggered for the production app. Clears the current database."
}

variable "data_import_arguments_prod" {
type = list(string)
default = ["seed-data"]
description = "Arguments to pass to the initial data import process for the production cluster"
}

variable "data_import_arguments_staging" {
type = list(string)
default = ["seed-data"]
description = "Arguments to pass to the initial data import process for the staging cluster"
}

variable "data_s3_access_key" {
type = string
sensitive = true
Expand Down
16 changes: 6 additions & 10 deletions infrastructure/kubernetes/vars/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
tf_state_bucket = "landgriffon-tf-state"
environment = "dev"
allowed_account_id = "622152552144"
domain = "landgriffon.com"
load_fresh_data_staging = false
load_fresh_data_prod = false
data_import_arguments_prod = ["seed-data"]
data_import_arguments_staging = ["seed-data"]
repo_name = "landgriffon"
tf_state_bucket = "landgriffon-tf-state"
environment = "dev"
allowed_account_id = "622152552144"
domain = "landgriffon.com"
repo_name = "landgriffon"

environments = {
dev : {},
test : {},
vcf : {},
tetrapack : {},
demo: {}
demo : {}
}

0 comments on commit 860441f

Please sign in to comment.