Skip to content

Commit

Permalink
Added organization level support to terraform spectrocloud module.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Oct 4, 2021
1 parent a9430d3 commit bd35584
Show file tree
Hide file tree
Showing 24 changed files with 480 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions deploy/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions deploy/mod_spectro_org.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*module "fetcher_accounts" {
source = "../modules/fetcher"
rsubfolder = local.accounts_folder
rprefix = "account-"
}*/

locals {
accounts_folder = "./"
accounts_params = { ACCOUNT_DEV_NAME = "ehs-dev-030", ACCOUNT_PROD_NAME = "ehs-stg-004" }

bsls_folder = "./"
bsl_params = { BSL_NAME = "ehs-org-dev-storage-203" }

profiles_folder = "./config/profile-2.0"
profile_params = {
SPECTRO_REPO_URL = "https://registry.spectrocloud.com",
REPO_URL = "593235963820.dkr.ecr.us-west-2.amazonaws.com",

OIDC_CLIENT_ID = "5ajs8pq0gatbgpjejld96fldrn",
OIDC_ISSUER_URL = "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_ajvPoziaS",

RABBITMQ_PACK_VERSION = "8.15.2",

string = "$${string}",

ADDON_SPECTRO_REPO_URL = "https://addon-registry.gehc.spectrocloud.com",
}

projects_folder = "./config/project-2.0"
projects_params = {}

}

module "SpectroOrg" {
source = "../"
sc_host = "api.dev.spectrocloud.com" #e.g: api.spectrocloud.com (for SaaS)
sc_username = "[email protected]" #e.g: [email protected]
sc_password = "welcome2Spectro1!" #e.g: supereSecure1!
sc_project_name = "Default" #e.g: Default

/*accounts = tomap({
for k, v in module.fetcher_accounts.object_files :
k => yamldecode(templatefile(join("", [local.accounts_folder, "/${k}"]), local.accounts_params))
})*/

accounts = tomap({
for k, v in toset([
"config/account-2.0/account-aws-1.yaml",
"config/account-2.0/account-aws-2.yaml",
]) :
k => yamldecode(templatefile(join("", [local.accounts_folder, "/${k}"]), local.accounts_params))
})

bsls = tomap({
for k, v in toset([
"config/bsl-2.0/bsl-s3-1.yaml",
]) :
k => yamldecode(templatefile(join("", [local.bsls_folder, "/${k}"]), local.bsl_params))
})

profiles = tomap({
for k, v in toset([
"profile-infra-EHS20RC1_Base_Infra_Org.yaml",
"profile-addon-EHS20RC1_Pre-Reqs-Org.yaml",
]) :
k => yamldecode(templatefile(join("", [local.profiles_folder, "/${k}"]), local.profile_params))
})

projects = tomap({
for k, v in toset([
"project-developer-abc.yaml",
"project-developer-arun.yaml",
"project-developer-def.yaml",
"project-providence-004.yaml"
]) :
k => yamldecode(templatefile(join("", [local.projects_folder, "/${k}"]), local.projects_params))
})

}
34 changes: 34 additions & 0 deletions deploy/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.1"
source = "spectrocloud/spectrocloud"
}
}
}

variable "sc_host" {
description = "Spectro Cloud Endpoint"
default = "api.spectrocloud.com"
}

variable "sc_username" {
description = "Spectro Cloud Username"
}

variable "sc_password" {
description = "Spectro Cloud Password"
sensitive = true
}

variable "sc_project_name" {
description = "Spectro Cloud Project (e.g: Default)"
default = "Default"
}

provider "spectrocloud" {
host = var.sc_host
username = var.sc_username
password = var.sc_password
project_name = var.sc_project_name
}
5 changes: 5 additions & 0 deletions deploy/terraform.template.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Spectro Cloud credentials
sc_host = "{enter Spectro Cloud API endpoint}" #e.g: api.spectrocloud.com (for SaaS)
sc_username = "{enter Spectro Cloud username}" #e.g: [email protected]
sc_password = "{enter Spectro Cloud password}" #e.g: supereSecure1!
sc_project_name = "{enter Spectro Cloud project Name}" #e.g: Default
22 changes: 22 additions & 0 deletions deploy/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Spectro Cloud credentials
sc_host = "api.dev.spectrocloud.com" #e.g: api.spectrocloud.com (for SaaS)
sc_username = "[email protected]" #e.g: [email protected]
sc_password = "welcome2Spectro1!" #e.g: supereSecure1!
sc_project_name = "Default" #e.g: Default

# AWS Cloud Account credentials
# Ensure minimum AWS account permissions:
# https://docs.spectrocloud.com/clusters/?clusterType=aws_cluster#awscloudaccountpermissions
aws_access_key = "AKIATD5NORWYBOSHBQE4"
aws_secret_key = "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"

# Existing SSH Key in AWS
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
aws_ssh_key_name = "spectro2020" #e.g: default

# Enter the AWS Region and AZ for cluster resources
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions
aws_region = "us-west-2" #e.g: us-west-2
aws_region_az = "us-west-2a" #e.g: us-west-2a

cluster_files = ["./config/cluster-eks-test.yaml"]
34 changes: 34 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
terraform {
required_providers {
spectrocloud = {
version = ">= 0.1"
source = "spectrocloud/spectrocloud"
}
}
}

variable "sc_host" {
description = "Spectro Cloud Endpoint"
default = "api.spectrocloud.com"
}

variable "sc_username" {
description = "Spectro Cloud Username"
}

variable "sc_password" {
description = "Spectro Cloud Password"
sensitive = true
}

variable "sc_project_name" {
description = "Spectro Cloud Project (e.g: Default)"
default = "Default"
}

provider "spectrocloud" {
host = var.sc_host
username = var.sc_username
password = var.sc_password
project_name = var.sc_project_name
}
32 changes: 32 additions & 0 deletions modules/fetch_replace/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
locals {

fileset_root = "./"#join("", [path.module, "/"])
fileset_subfolder = join("", [local.fileset_root, var.rsubfolder])

param_files = fileset(local.fileset_subfolder, "param-*.yaml")
params = {
for k in local.param_files :
trimsuffix(k, ".yaml") => yamldecode(file(join("", [var.rsubfolder, "/${k}"])))
}

all_params = flatten(
[
for k, v in local.params : v
]
)

all_params_map = zipmap(
flatten(
[for item in local.all_params : keys(item)]
),
flatten(
[for item in local.all_params : values(item)]
)
)

object_files = fileset(local.fileset_subfolder, join("", [var.rprefix, "*.yaml"]))

all_objects = tomap({
for k, v in local.object_files : k => yamldecode(templatefile(join("", [var.rsubfolder, "/${k}"]), local.all_params_map))
})
}
15 changes: 15 additions & 0 deletions modules/fetch_replace/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "all_objects" {
value = local.all_objects
}

output "object_files" {
value = local.object_files
}

output "all_files" {
value = local.all_objects
}

output "all_params" {
value = local.all_objects
}
9 changes: 9 additions & 0 deletions modules/fetch_replace/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "rsubfolder" {
type = string
default = "config/profile-2.0"
}

variable "rprefix" {
type = string
default = "infra-"
}
28 changes: 28 additions & 0 deletions modules/fetcher/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
locals {

fileset_root = "./"#join("", [path.module, "/"])
fileset_subfolder = join("", [local.fileset_root, var.rsubfolder])

param_files = fileset(local.fileset_subfolder, "param-*.yaml")
params = {
for k in local.param_files :
trimsuffix(k, ".yaml") => yamldecode(file(join("", [var.rsubfolder, "/${k}"])))
}

all_params = flatten(
[
for k, v in local.params : v
]
)

all_params_map = zipmap(
flatten(
[for item in local.all_params : keys(item)]
),
flatten(
[for item in local.all_params : values(item)]
)
)

object_files = fileset(local.fileset_subfolder, join("", [var.rprefix, "*.yaml"]))
}
3 changes: 3 additions & 0 deletions modules/fetcher/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "object_files" {
value = local.object_files
}
9 changes: 9 additions & 0 deletions modules/fetcher/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "rsubfolder" {
type = string
default = "config/profile-2.0"
}

variable "rprefix" {
type = string
default = "infra-"
}
5 changes: 5 additions & 0 deletions modules/replacer/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
locals {
all_objects_params_replaced = tomap({
for k, v in var.objects : k => yamldecode(templatefile(v, var.params))
})
}
3 changes: 3 additions & 0 deletions modules/replacer/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "all_objects_params_replaced" {
value = local.all_objects_params_replaced
}
9 changes: 9 additions & 0 deletions modules/replacer/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "objects" {
type = list(any)
default = []
}

variable "params" {
type = map
default = {}
}
8 changes: 8 additions & 0 deletions spectro-account.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "spectrocloud_cloudaccount_aws" "account" {
for_each = var.accounts

type = "sts"
name = each.value.name
arn = each.value.arn
external_id = each.value.external_id
}
13 changes: 13 additions & 0 deletions spectro-backup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "spectrocloud_backup_storage_location" "bsl" {
for_each = var.bsls

name = each.value.name
is_default = false
region = each.value.region
bucket_name = each.value.bucket_name
s3 {
credential_type = "sts"
arn = each.value.arn
external_id = each.value.external_id
}
}
Loading

0 comments on commit bd35584

Please sign in to comment.