INFRA-794 | Deepak Jain| adding elastic module
This commit is contained in:
File diff suppressed because one or more lines are too long
17
main.go
17
main.go
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +80,16 @@
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"elasticCache": {
|
||||
"awsInstanceClass": "cache.t3.small",
|
||||
"instanceName": "smaple-redis-cache",
|
||||
"MultiAZ": true
|
||||
}
|
||||
},
|
||||
"team": {
|
||||
"name": "Infra"
|
||||
},
|
||||
"name": "foo",
|
||||
"infraVertical": "lending"
|
||||
}
|
||||
}
|
||||
|
||||
18
templates/elastic-cache-tf/deploy.sh
Normal file
18
templates/elastic-cache-tf/deploy.sh
Normal 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
|
||||
34
templates/elastic-cache-tf/main.tf
Normal file
34
templates/elastic-cache-tf/main.tf
Normal 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 }}
|
||||
}
|
||||
18
testdata/m1_basic/expected_output/elastic-cache-tf/deploy.sh
vendored
Executable file
18
testdata/m1_basic/expected_output/elastic-cache-tf/deploy.sh
vendored
Executable 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
|
||||
30
testdata/m1_basic/expected_output/elastic-cache-tf/main.tf
vendored
Executable file
30
testdata/m1_basic/expected_output/elastic-cache-tf/main.tf
vendored
Executable 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
|
||||
}
|
||||
7
testdata/m1_basic/sample_infra_manifest.json
vendored
7
testdata/m1_basic/sample_infra_manifest.json
vendored
@@ -65,7 +65,12 @@
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"elasticCache": {
|
||||
"awsInstanceClass": "cache.t3.small",
|
||||
"instanceName": "smaple-redis-cache",
|
||||
"MultiAZ": true
|
||||
}
|
||||
},
|
||||
"team": {
|
||||
"name": "Infra"
|
||||
|
||||
24
types.go
24
types.go
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user