INFRA-794 | Deepak Jain| adding elastic module

This commit is contained in:
Deepak Jain
2021-07-21 21:16:53 +05:30
parent cf2280ce86
commit 94cef116a5
10 changed files with 415 additions and 58 deletions

File diff suppressed because one or more lines are too long

17
main.go
View File

@@ -125,6 +125,23 @@ func main() {
return nil
},
},
{
Name: "redis",
Usage: "Provision elastic cache instance",
Action: func(c *cli.Context) error {
manifest, err := parseManifest(c.String("manifest"))
if err != nil {
log.Fatalf("\nErr: %v", err)
return err
}
err = provisionResource("elasticCache", "elastic-cache-tf", manifest, c.Bool("template-only"), c.Bool("plan"))
if err != nil {
log.Fatalf("\nErr: %v", err)
return err
}
return nil
},
},
{
Name: "iam-roles",
Usage: "Provision iam service roles",

View File

@@ -116,3 +116,10 @@ func TestTemplates_AwsRole_CompareWithOutput(t *testing.T) {
t.Error(err)
}
}
func TestTemplates_ElasticCache_CompareWithOutput(t *testing.T) {
err := CompareResourceWithOutput("elastic-cache-tf", "elasticCache")
if err != nil {
t.Error(err)
}
}

View File

@@ -80,11 +80,16 @@
}
}]
}
]
],
"elasticCache": {
"awsInstanceClass": "cache.t3.small",
"instanceName": "smaple-redis-cache",
"MultiAZ": true
}
},
"team": {
"name": "Infra"
},
"name": "foo",
"infraVertical": "lending"
}
}

View File

@@ -0,0 +1,18 @@
#!/bin/sh
set -e
additional_terraform_options=""
terraform_action=${1:-apply}
if [ $terraform_action == "apply" ];then
additional_terraform_options="${additional_terraform_options} -auto-approve"
fi
terraform init
terraform workspace select {{ .ExtraResources.Workspace }} || terraform workspace new {{ .ExtraResources.Workspace }}
if [ $terraform_action == "plan" ];then
terraform $terraform_action $additional_terraform_options
else
terraform $terraform_action $additional_terraform_options
fi

View File

@@ -0,0 +1,34 @@
terraform {
backend "s3" {
bucket = "navi-bank-terraform-command-state"
region = "ap-south-1"
key = "elastic-cache"
workspace_key_prefix = "elastic-cache-states/{{ .InfraVertical }}/{{ .ExtraResources.Environment }}/{{ .ExtraResources.ElasticCache.InstanceName }}"
profile = "cmd"
acl = "bucket-owner-full-control"
}
}
module "elastic_cache" {
source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/elastic-cache-module.git"
environment = {{ .ExtraResources.Environment | quote }}
name_prefix = {{ .ExtraResources.ElasticCache.InstanceName | quote }}
infra_vertical = {{ .InfraVertical | quote }}
team = {{ .Team.Name | quote }}
tags = {
Team = {{ .Team.Name | quote }}
Owner = {{ .Team.Owner | quote }}
Environment = {{ .ExtraResources.Environment | quote }}
Name = {{ .Name | quote}}
}
node_type = {{ .ExtraResources.ElasticCache.AwsInstanceClass | quote }}
apply_immediately = {{ .ExtraResources.ElasticCache.ApplyImmediately }}
{{- if .ExtraResources.ElasticCache.MultiAZ }}
automatic_failover_enabled = true
number_cache_clusters = 2
{{- else }}
number_cache_clusters = 1
{{- end }}
}

View File

@@ -0,0 +1,18 @@
#!/bin/sh
set -e
additional_terraform_options=""
terraform_action=${1:-apply}
if [ $terraform_action == "apply" ];then
additional_terraform_options="${additional_terraform_options} -auto-approve"
fi
terraform init
terraform workspace select nonprod.np.navi-tech.in || terraform workspace new nonprod.np.navi-tech.in
if [ $terraform_action == "plan" ];then
terraform $terraform_action $additional_terraform_options
else
terraform $terraform_action $additional_terraform_options
fi

View File

@@ -0,0 +1,30 @@
terraform {
backend "s3" {
bucket = "navi-bank-terraform-command-state"
region = "ap-south-1"
key = "elastic-cache"
workspace_key_prefix = "elastic-cache-states/lending/dev/smaple-redis-cache"
profile = "cmd"
acl = "bucket-owner-full-control"
}
}
module "elastic_cache" {
source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/elastic-cache-module.git"
environment = "dev"
name_prefix = "smaple-redis-cache"
infra_vertical = "lending"
team = "Infra"
tags = {
Team = "Infra"
Owner = "medici"
Environment = "dev"
Name = "foo"
}
node_type = "cache.t3.small"
apply_immediately = false
automatic_failover_enabled = true
number_cache_clusters = 2
}

View File

@@ -65,7 +65,12 @@
}
}]
}
]
],
"elasticCache": {
"awsInstanceClass": "cache.t3.small",
"instanceName": "smaple-redis-cache",
"MultiAZ": true
}
},
"team": {
"name": "Infra"

View File

@@ -4,8 +4,8 @@ const DeploymentNameSuffix = "navi-service"
const DefaultInfraVertical = "lending"
const DefaultOwner = "medici"
type Deployment struct{
Namespace string `json:namespace`
type Deployment struct {
Namespace string `json:namespace`
}
type Manifest struct {
@@ -21,11 +21,13 @@ type Manifest struct {
type ExtraResources struct {
//TODO: Remove environment from ExtraResources once all apps have migrated to new schema
Environment string `json:"environment"`
Workspace string `json:"workspace"`
Database *Database `json:"database"`
ServiceRole *ServiceRole `json:"aws_access"`
S3Buckets []S3Bucket `json:"s3_buckets"`
Environment string `json:"environment"`
Workspace string `json:"workspace"`
Database *Database `json:"database"`
// TBD: remove undersocre from json key. to keep naming conventions same across board
ServiceRole *ServiceRole `json:"aws_access"`
S3Buckets []S3Bucket `json:"s3_buckets"`
ElasticCache *ElasticCache `json:"elasticCache"`
}
//We provide defaults in respective terraforms instead of here to keep all values at one place
@@ -55,6 +57,14 @@ type Database struct {
StorageEncrypted bool `json:"storageEncrypted"`
KmsKeyId string `json:"kmsKeyId"`
}
type ElasticCache struct {
AwsInstanceClass string `json:"awsInstanceClass"`
InstanceName string `json:"instanceName" valid:"required"`
MultiAZ bool `json:"multiAZ"`
ApplyImmediately bool `json:"applyImmediately"`
}
type Parameter struct {
Name string `json:"name" valid:"required"`
Value string `json:"value" valid:"required"`