Skip to content

Commit

Permalink
preserving initial nuki before upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Aug 5, 2020
1 parent 9c998e6 commit a752d91
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 172 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,55 @@ By walking through the steps in the CLI, users should be able to fully customize
cloud provider. Configuration settings are self-documented in the CLI or can be done manually by editing the
deployment files per the architecture described below.

## Deployment Process



### Run File, Deployment ID, and Remote State

We order the deployment file names and remote state path per the following convetion.

| Num | Name | Description | Example |
|:---|:---|:-----|:---|
| 1 | Namespace | The namespace, ie the chain | polkadot |
| 2 | Network Name | The name of the network | kusama |
| 3 | Environment | The environment of deployment | prod |
| 4 | Provider | The cloud provider | aws |
| 5 | Region | Region to deploy into | us-east-1 |
| 6 | Stack | The type of stack to deploy | validator|
| 7 | Deployment ID | Identifier for unique deployment | 1 |

We then will rely on this hierarchy in the remote state and deployment file.

**Run File:**

`run.yaml` An inherited file closest to the stack being deployed.
```yaml
namespace: "polkadot"
network_name: "kusama"
environment: "dev"
provider: "aws"
region: "us-east-1"
stack: "validator-simple"
deployment_id: 1 # Something to discriminate between deployments - ie blue/green
```
**Deployment File:**
`terragrunt-harmony/deployments/harmony.mainnet.prod.aws.us-east-1.validator.1.yaml`

Deployment files are created locally by the nukikata CLI in the `deployments` directory and are referenced in each
deployment run via the `run.yaml` which references the deployment file.


**Remote State:**

`s3://.../<bucket>/harmony/mainnet/prod/aws/us-east-1/validator/1/terraform.tfstate`

The remote state bucket and path are created and managed for you by terragrunt. This is where the state of all the
deployments is kept and can be referenced in subsequent deployments.



### How it works

This reference architecture is built with `terragrunt`, a wrapper to terraform, which under the hood calls Ansible
Expand Down
2 changes: 1 addition & 1 deletion polkadot/api/aws/network/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include {
}

locals {
vars = read_terragrunt_config(find_in_parent_folders("variables.hcl")).locals
vars = read_terragrunt_config(find_in_parent_folders("common.hcl")).locals
}

inputs = {
Expand Down
11 changes: 0 additions & 11 deletions polkadot/api/aws/secrets.yaml.example

This file was deleted.

62 changes: 42 additions & 20 deletions polkadot/api/aws/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
locals {
vars = read_terragrunt_config(find_in_parent_folders("${get_parent_terragrunt_dir()}/variables.hcl"))
}

remote_state {
backend = "s3"
config = {
encrypt = true
region = local.vars.locals.remote_state_region
key = "${local.vars.locals.remote_state_path}/${path_relative_to_include()}/terraform.tfstate"
bucket = "terraform-states-${get_aws_account_id()}"
dynamodb_table = "terraform-locks-${get_aws_account_id()}"
}
vars = read_terragrunt_config(find_in_parent_folders("${get_parent_terragrunt_dir()}/common.hcl")).locals

generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
// run = yamldecode(file(find_in_parent_folders("run.yaml")))
// settings = yamldecode(file(find_in_parent_folders("settings.yaml")))
//
// # Imports
// versions = yamldecode(file("versions.yaml"))[local.run.environment]
// secrets = yamldecode(file(find_in_parent_folders("secrets.yaml")))
// deployment_id_order = local.settings.deployment_id_order
// deployment_id = join(".", [ for i in local.deployment_id_order : lookup(local.run, i)])
// deployment_vars = yamldecode(file("${find_in_parent_folders("deployments")}/${local.deployment_id}.yaml"))
//
// # Labels
// id_label_order = local.settings.id_label_order
// id = join("-", [ for i in local.id_label_order : lookup(local.run, i)])
// name_label_order = local.settings.name_label_order
// name = join("", [ for i in local.name_label_order : title(lookup(local.run, i))])
// tags = { for t in local.remote_state_path_order : t => lookup(local.run, t) }
//
// # Remote State
// remote_state_path_order = local.settings.remote_state_path_order
// remote_state_path = join("/", [ for i in local.remote_state_path_order : lookup(local.run, i)])
}

inputs = merge(
local.vars.locals,
local.vars.locals.secrets,
local.vars.locals.deployment_vars,
local.vars,
local.vars.run,
local.vars.secrets,
local.vars.deployment_vars,
)

generate "provider" {
path = "provider.tf"
if_exists = "skip"
contents =<<-EOF
provider "aws" {
region = "${local.vars.locals.region}"
region = "${local.vars.run.region}"
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
Expand All @@ -41,3 +47,19 @@ provider "cloudflare" {
}
EOF
}

remote_state {
backend = "s3"
config = {
encrypt = true
region = "us-east-1"
key = "${local.vars.remote_state_path}/${path_relative_to_include()}/terraform.tfstate"
bucket = "terraform-states-${get_aws_account_id()}"
dynamodb_table = "terraform-locks-${get_aws_account_id()}"
}

generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
}
83 changes: 22 additions & 61 deletions polkadot/api/aws/variables.hcl
Original file line number Diff line number Diff line change
@@ -1,67 +1,28 @@
locals {
######################
# Deployment Variables
######################
namespace = "polkadot"
stack = "api"
provider = "aws"
network_name = "kusama"
environment = "dev"
region = "eu-north-1"

deployment_map = {
namespace = local.namespace
stack = local.stack
provider = local.provider
network_name = local.network_name
environment = local.environment
region = local.region
}

remote_state_region = "us-east-1"

###################
# Environment Logic
###################
env_vars = {
dev = {}
test = {}
stage = {}
prod = {}
}[local.environment]

deployment_id_label_order = ["namespace", "stack", "network_name", "environment","provider", "region"]
deployment_id = join(".", [ for i in local.deployment_id_label_order : lookup(local.label_map, i)])
deployment_vars = yamldecode(file("${find_in_parent_folders("deployments")}/${local.deployment_id}.yaml"))
run = yamldecode(file(find_in_parent_folders("run.yaml")))
settings = yamldecode(file(find_in_parent_folders("settings.yaml")))

# Imports
versions = yamldecode(file("${get_parent_terragrunt_dir()}/versions.yaml"))[local.environment]
versions = yamldecode(file("versions.yaml"))[local.run.environment]
secrets = yamldecode(file(find_in_parent_folders("secrets.yaml")))
deployment_id_order = local.settings.deployment_id_order
deployment_id = join(".", [ for i in local.deployment_id_order : lookup(local.run, i)])
deployment_vars = yamldecode(file("${find_in_parent_folders("deployments")}/${local.deployment_id}.yaml"))

###################
# Label Boilerplate
###################
label_map = {
namespace = local.namespace
stack = local.stack
provider = local.provider
network_name = local.network_name
environment = local.environment
region = local.region
global = "global"
}

remote_state_path_label_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_label_order : lookup(local.label_map, i)])

global_remote_state_path_label_order = ["namespace", "stack", "provider", "network_name", "environment", "global"]
global_remote_state_path = join("/", [ for i in local.global_remote_state_path_label_order : lookup(local.label_map, i)])

id_label_order = ["namespace", "stack", "network_name", "environment"]
id = join("-", [ for i in local.id_label_order : lookup(local.label_map, i)])

name_label_order = ["stack", "network_name"]
name = join("", [ for i in local.name_label_order : title(lookup(local.label_map, i))])

tags = { for t in local.remote_state_path_label_order : t => lookup(local.label_map, t) }
# Labels
id_label_order = local.settings.id_label_order
id = join("-", [ for i in local.id_label_order : lookup(local.run, i)])
name_label_order = local.settings.name_label_order
name = join("", [ for i in local.name_label_order : title(lookup(local.run, i))])
tags = { for t in local.remote_state_path_order : t => lookup(local.run, t) }

# Remote State
remote_state_path_order = local.settings.remote_state_path_order
remote_state_path = join("/", [ for i in local.remote_state_path_order : lookup(local.run, i)])

// versions = {
// dev = {
// asg = "master"
// }
// }
}
6 changes: 3 additions & 3 deletions polkadot/api/azure/variables.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ locals {
region = local.region
}

remote_state_path_label_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_label_order : lookup(local.label_map, i)])
remote_state_path_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_order : lookup(local.label_map, i)])

id_label_order = ["namespace", "stack", "network_name", "environment"]
id = join("-", [ for i in local.id_label_order : lookup(local.label_map, i)])

name_label_order = ["stack", "network_name"]
name = join("", [ for i in local.name_label_order : title(lookup(local.label_map, i))])

tags = { for t in local.remote_state_path_label_order : t => lookup(local.label_map, t) }
tags = { for t in local.remote_state_path_order : t => lookup(local.label_map, t) }
}
6 changes: 3 additions & 3 deletions polkadot/api/do/variables.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ locals {
region = local.region
}

remote_state_path_label_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_label_order : lookup(local.label_map, i)])
remote_state_path_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_order : lookup(local.label_map, i)])

id_label_order = ["namespace", "stack", "network_name", "environment"]
id = join("-", [ for i in local.id_label_order : lookup(local.label_map, i)])

name_label_order = ["stack", "network_name"]
name = join("", [ for i in local.name_label_order : title(lookup(local.label_map, i))])

tags = { for t in local.remote_state_path_label_order : t => lookup(local.label_map, t) }
tags = { for t in local.remote_state_path_order : t => lookup(local.label_map, t) }
}
6 changes: 3 additions & 3 deletions polkadot/api/gcp/variables.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ locals {
region = local.region
}

remote_state_path_label_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_label_order : lookup(local.label_map, i)])
remote_state_path_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_order : lookup(local.label_map, i)])

id_label_order = ["namespace", "stack", "network_name", "environment"]
global_id = join("-", [ for i in local.id_label_order : lookup(local.label_map, i)])
Expand All @@ -54,5 +54,5 @@ locals {
short_id_label_order = ["stack", "network_name", "environment"]
global_short_id = join("-", [ for i in local.short_id_label_order : lower(lookup(local.label_map, i))])

tags = { for t in local.remote_state_path_label_order : t => lookup(local.label_map, t) }
tags = { for t in local.remote_state_path_order : t => lookup(local.label_map, t) }
}
6 changes: 3 additions & 3 deletions polkadot/api/gcp/variables2.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ locals {
# Label Boilerplate
###################

remote_state_path_label_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_label_order : lookup(local.deployment_map, i)])
remote_state_path_order = ["namespace", "stack", "provider", "network_name", "environment", "region"]
remote_state_path = join("/", [ for i in local.remote_state_path_order : lookup(local.deployment_map, i)])

id_label_order = ["namespace", "stack", "network_name", "environment"]
global_id = join("-", [ for i in local.id_label_order : lookup(local.deployment_map, i)])
Expand All @@ -55,5 +55,5 @@ locals {
short_id_label_order = ["stack", "network_name", "environment"]
global_short_id = join("-", [ for i in local.short_id_label_order : lower(lookup(local.deployment_map, i))])

tags = { for t in local.remote_state_path_label_order : t => lookup(local.deployment_map, t) }
tags = { for t in local.remote_state_path_order : t => lookup(local.deployment_map, t) }
}
48 changes: 48 additions & 0 deletions polkadot/nuki.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Stack
stack:
type: select
message: What type of stack do you want to run?
choices:
- validator-simple: Super simple validator
- validator: Advanced validator
- api-simple: Super simple private API endpoint
- api: Advanced API clusters
- monitor: Network monitoring tools

# Namespace
namespace:
type: input
message: What do you want to call your namespace?
default: harmony

# Network Name
network_name:
type: select
message: What network do you want to run on?
choices:
- testnet: Testnet
- mainnet: Mainnet

# Environment
environment:
type: select
message: What type of environment do you want to create?
choices:
- dev
- test
- stage
- prod

# Deployment ID
deployment_id:
type: input
message: What deployment id do you want to make?
default: 1

stack_call_:
type: nukikata
chdir: "{{ nuki.stack }}"
existing_context: "{{ nuki }}"

# SSH Profiles

7 changes: 7 additions & 0 deletions run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace: "polkadot"
network_name: "kusama"
environment: "dev"
provider: "aws"
region: "eu-north-1"
stack: "api"
deployment_id: 1
Loading

0 comments on commit a752d91

Please sign in to comment.