From 32612088bb90412612e6392b7699d9c32fd3db63 Mon Sep 17 00:00:00 2001 From: anoop narang Date: Wed, 26 Feb 2020 12:55:57 +0530 Subject: [PATCH] [ch4240] | Anoop | Add team name as tag to database --- bindata.go | 56 ++++++++++++++++++++------------------ resource.go | 2 +- sample_infra_manifest.json | 3 ++ templates/rds-tf/deploy.sh | 2 +- templates/rds-tf/main.tf | 32 ++++++++++++---------- types.go | 5 ++++ 6 files changed, 57 insertions(+), 43 deletions(-) diff --git a/bindata.go b/bindata.go index d477108..935ca53 100644 --- a/bindata.go +++ b/bindata.go @@ -80,13 +80,13 @@ func (fi bindataFileInfo) Sys() interface{} { } var _bindataTemplatesRdstfDeploysh = []byte( - "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\xcc\x4b\x8e\xc2\x30\x0c\x80\xe1\xfd\x9c\xc2\xa3\x59\x37\x3d\xc1\x9c" + - "\x83\x65\xe4\x26\xa6\x44\x34\x89\x65\xbb\xad\x50\xdb\xbb\xb3\x41\x50\x01\x0b\xc4\xce\x8f\x5f\xdf\xdf\x6f\xdb\xa5" + - "\xd2\xea\xe9\xc7\x48\x04\x8f\x55\x32\xa4\x92\x6c\xb7\xce\x55\xce\xca\x18\x08\x94\x06\x0a\x06\xcb\x02\xee\x70\x3f" + - "\x6e\x1b\xac\x2b\xbc\xcb\x0b\xcd\x2f\xed\xce\x45\xe6\xe1\x02\x8d\xa1\xf4\x64\xff\xb9\xc6\x71\x20\x27\x51\x5d\x44" + - "\x43\x87\xb3\x7a\x1d\xbb\x42\xe6\x53\x54\x17\x6a\xce\x58\xa2\x67\x49\x13\x1a\xdd\x5e\x0a\x0d\x8e\x56\x1b\x64\x96" + - "\x3a\xd1\x27\xf8\x63\xf4\xa9\xa8\x61\x09\xf4\x35\xc2\x55\xad\x17\x52\x1f\xbb\x27\xe3\x1a\x00\x00\xff\xff\xb9\x7c" + - "\xda\xf4\x57\x01\x00\x00") + "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x8d\x41\x4e\xc4\x30\x0c\x45\xf7\x9c\xc2\x88\x75\xd3\x13\xb0\xe4\x02" + + "\x6c\x58\x46\x6e\x62\x4a\x44\x13\x47\xb6\xd3\x82\xda\xde\x9d\x0d\x9a\xa9\x46\x23\xcd\x68\x76\xb6\xfe\x7f\xef\xbf" + + "\x3c\xf7\x43\x2a\xbd\x7e\x3d\x19\x89\xe0\x27\x4b\x86\x54\x92\x1d\xde\x85\xe5\x5b\x2b\x06\x02\xa5\x89\x82\xc1\xba" + + "\x82\x7b\xfb\x31\xc1\x77\x52\x6e\x12\x48\xdd\xc7\xa9\xb3\xef\xb0\x6d\x70\x8d\x2e\xb4\xdc\x42\x0f\xab\x58\xeb\xf4" + + "\x0b\x9d\xa1\x8c\x64\xaf\x99\x63\x9b\xc8\x49\x54\x17\xd1\xd0\xe1\xa2\x5e\xdb\x50\xc8\x7c\x8a\xea\x02\xe7\x8c\x25" + + "\xfa\x2a\x69\x46\xa3\xff\x48\xa1\xc3\x66\xdc\x61\xad\xc2\x33\xdd\x23\x3f\x9f\x3e\x15\x35\x2c\x81\x1e\x96\x54\x56" + + "\x1b\x85\xd4\xc7\xe1\xc2\xf1\x17\x00\x00\xff\xff\x61\x91\x15\xf4\x75\x01\x00\x00") func bindataTemplatesRdstfDeployshBytes() ([]byte, error) { return bindataRead( @@ -105,10 +105,10 @@ func bindataTemplatesRdstfDeploysh() (*asset, error) { info := bindataFileInfo{ name: "templates/rds-tf/deploy.sh", - size: 343, + size: 373, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1578927242, 0), + modTime: time.Unix(1582701520, 0), } a := &asset{bytes: bytes, info: info} @@ -117,22 +117,24 @@ func bindataTemplatesRdstfDeploysh() (*asset, error) { } var _bindataTemplatesRdstfMaintf = []byte( - "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x53\x4d\x8f\x9b\x30\x10\xbd\xf3\x2b\x46\xb9\x9b\xa8\xea\x2d\xd2\x4a" + - "\xad\xba\xdb\x6a\x7b\xa8\x56\xea\xc7\x15\x19\x33\x10\x0b\x7b\x4c\x3c\x26\x34\xcb\xf2\xdf\x2b\x30\xd9\xc2\x26\x39" + - "\xac\x6f\xcc\xbc\x37\xef\x43\x22\xa0\xf7\xb2\x74\xde\x42\x9f\x00\xe4\x52\xd5\x48\x05\x6c\xf8\xe3\x66\x1a\x00\xe4" + - "\xad\xaa\x31\xc0\xfa\xdd\xc1\x86\xe4\x51\x8b\x5c\x52\x2d\x5e\x4f\x08\xe5\xac\x95\x54\x08\x0e\x32\xe0\x66\xa2\x7b" + - "\xac\xb4\xa3\x4b\xba\x6c\x04\xbb\x36\xec\xc5\x87\x88\xab\xf1\x04\x17\xef\x0e\x36\xbe\xe0\x08\xe8\x9c\xaf\xb9\x91" + - "\x0a\xb3\x1a\x4f\x59\xe3\xb1\xd4\x7f\x67\x40\xd4\xe3\x6d\xdf\x43\x7a\x2f\x83\xcc\x25\x63\xfa\x48\x1c\x24\x29\xfc" + - "\x21\x2d\xc2\x30\xc4\x23\x8d\x77\xa5\x36\x78\xa1\xa2\x6c\x11\x01\x52\x99\xab\x36\x62\x0b\xc2\x75\x84\x5e\x94\xad" + - "\x31\x42\x39\x0a\xde\x99\x91\x36\x24\x43\x92\x58\x57\xb4\x06\xa3\xe1\xa9\x3a\x76\xad\x57\xb8\xb8\x51\xe9\xb0\xdb" + - "\x31\xef\x77\xdb\x6d\xa5\xc3\xa7\x4a\x87\x7d\x9b\xa7\xca\x16\xe9\xd4\x65\x40\xb5\x4f\x35\x6d\xa7\x0f\x4d\xa5\x97" + - "\x5b\x5f\x70\x5a\xe9\x30\x6a\x20\x1d\xb5\x77\x64\x91\xc2\x74\x6d\xcc\xfa\xb0\x98\xbd\xc0\xa1\x75\x61\x4c\x9a\x00" + - "\xe8\x39\x7b\x46\x63\xf8\x08\xbe\x5e\xcc\x8a\xd6\x48\xe6\xce\xf9\xe2\xec\x78\x45\x7b\x3a\x2f\x57\x14\xd6\xcf\xb8" + - "\x2c\x6a\x45\xf9\xa9\x9f\xf1\x91\xbe\xe5\x11\xda\x32\xfa\x9b\xd0\xdf\xe3\x72\x71\x39\x01\x28\xe6\x1d\x5f\xc3\xdf" + - "\xe7\xa3\x7d\x86\x17\xb0\x2d\x87\x5f\xee\x3b\x3b\x9a\x79\x7d\x2f\x40\x97\x0b\xec\xe7\x8e\xcf\x99\xbf\x18\xc9\x1c" + - "\xed\xc8\x8e\xb3\xd7\x9e\xd4\x34\x7f\xa3\x71\xc1\x5b\x25\x1f\x65\xc6\x5f\xe5\x86\xe8\x13\x1f\xcc\x57\x69\xb5\x39" + - "\xcd\xdd\xf2\xc1\x64\x65\x1c\xbc\x6d\xf6\x3f\xf4\xbd\x0a\x0f\x54\x69\xc2\x3f\xe8\x59\xc7\xfc\xb3\x10\x4e\xf3\xec" + - "\x38\x2f\xae\x08\xae\x99\xb7\x74\x87\xe4\x5f\x00\x00\x00\xff\xff\xf5\xc3\xcf\xc3\x20\x04\x00\x00") + "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x53\x5d\x6b\xdb\x30\x14\x7d\xf7\xaf\xb8\xe4\x5d\x0e\x63\x6f\x85\xc2" + + "\xc6\x9a\x8d\xee\x61\x94\xad\xdb\xab\xb9\x96\xaf\x1d\x61\x7d\x24\xba\x72\xd2\x34\xcd\x7f\x1f\xb2\x9c\x2e\xc6\x69" + + "\x52\x98\xc0\x60\x5f\x9d\x73\xee\xb9\x47\x72\x20\xef\xb1\x76\xde\xc0\x3e\x03\x28\x51\xb6\x64\x2b\x98\xf1\xc7\x59" + + "\x5f\x00\x28\x3b\xd9\x52\x80\xf1\xba\x85\x99\xc5\x8d\x12\x25\xda\x56\xbc\x4a\x08\xe9\x8c\x41\x5b\x09\x0e\x18\x68" + + "\xd6\xd3\x3d\x35\xca\xd9\x29\x1d\x57\x82\x5d\x17\x96\xe2\x43\xc2\xb5\xb4\x83\xc9\xba\x85\x99\xaf\x38\x01\xb6\xce" + + "\xb7\xbc\x42\x49\x45\x4b\xbb\x62\xe5\xa9\x56\x4f\x03\x20\xf5\xe3\xf9\x7e\x0f\xf9\xe2\x29\x78\xfc\x49\xec\x3a\x2f" + + "\x89\xf3\x3b\x0c\x58\x22\x53\x7e\x6f\x39\xa0\x95\xf4\x03\x0d\xc1\xe1\x90\x34\x57\xde\xd5\x4a\xd3\xa4\xa9\x34\x55" + + "\x02\xa0\xd4\x67\x5d\xa5\x50\x84\xdb\x5a\xf2\xa2\xee\xb4\x16\xd2\xd9\xe0\x9d\x8e\xb4\x43\x76\xc8\x32\xe3\xaa\x4e" + + "\x53\xf2\xdf\x27\x99\x1c\x9d\x68\x34\x2a\xdc\xdc\x30\x2f\x6f\xe6\xf3\x46\x85\x4f\x8d\x0a\xcb\xae\xcc\xa5\xa9\xf2" + + "\x3e\xda\x40\x72\x99\x2b\x3b\xef\x3f\x94\xad\x3d\xce\x7d\xc5\x79\xa3\x42\xec\x41\x76\xa3\xbc\xb3\x86\x6c\xe8\xd5" + + "\xce\x8c\xbe\x38\x81\xbc\xc0\xba\x73\x21\x0e\x9e\x01\xa8\x21\x8a\xc2\xc6\x2c\xce\x72\xcf\xc7\x36\x52\x59\x21\xf3" + + "\xd6\xf9\xea\x38\xcf\x25\x95\x87\x23\x76\xa4\xc0\xea\x99\x4e\x53\xbd\xa4\xf0\x4b\x3d\xd3\xbd\xfd\x56\x26\x66\xc7" + + "\xe4\xdf\xcb\xfc\x1d\xb1\x27\x7d\x33\x80\x6a\xd8\xe3\x77\xd0\xef\xca\x38\x3a\xc3\x0b\x98\x8e\xc3\xa3\xfb\xce\xce" + + "\x26\x13\x47\x95\x22\x60\xc3\x51\x25\x4b\x76\x1e\x09\xcd\x20\x1a\x5f\xf3\x69\x74\xf1\xc9\x00\xf6\x7b\x01\xaa\x7e" + + "\xbb\xf5\xe7\x2d\x1f\xe3\xff\xa2\x91\x39\x91\x71\xcb\xc5\xeb\x09\xca\xbe\x7e\x79\x82\x89\xcc\xc8\x4b\x34\x11\xff" + + "\xf8\x94\xcc\x35\x4b\x0f\xbc\xd6\x5f\xd1\x28\xbd\x1b\x2e\x01\xaf\x75\x51\xa7\xc2\x95\x2b\xf0\x8f\xf9\x9f\xfd\x17" + + "\xb6\x51\x96\xfe\x90\x67\x75\x3c\x8a\xde\x06\xf5\xf5\x62\x33\x6c\x5c\xb7\x33\x16\x7a\xd3\xd5\x21\xfb\x1b\x00\x00" + + "\xff\xff\xa5\x20\x97\xf0\x24\x05\x00\x00") func bindataTemplatesRdstfMaintfBytes() ([]byte, error) { return bindataRead( @@ -151,10 +153,10 @@ func bindataTemplatesRdstfMaintf() (*asset, error) { info := bindataFileInfo{ name: "templates/rds-tf/main.tf", - size: 1056, + size: 1316, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1578995480, 0), + modTime: time.Unix(1582701559, 0), } a := &asset{bytes: bytes, info: info} diff --git a/resource.go b/resource.go index c67f345..9c51655 100644 --- a/resource.go +++ b/resource.go @@ -49,7 +49,7 @@ func templateResourceTf(templateName, resourceDir string, manifest *Manifest) er return err } - err = t.Execute(tfOut, manifest.ExtraResources) + err = t.Execute(tfOut, manifest) if err != nil { log.Fatalf("\nErr: %v", err) return err diff --git a/sample_infra_manifest.json b/sample_infra_manifest.json index 271bccd..a71be54 100644 --- a/sample_infra_manifest.json +++ b/sample_infra_manifest.json @@ -8,5 +8,8 @@ "sizeInGb": 7, "dbNames": ["auth_service"] } + }, + "team": { + "name": "LoanOrigination" } } diff --git a/templates/rds-tf/deploy.sh b/templates/rds-tf/deploy.sh index 8bfd697..ddfacc9 100644 --- a/templates/rds-tf/deploy.sh +++ b/templates/rds-tf/deploy.sh @@ -1,6 +1,6 @@ #!/bin/sh terraform init -terraform workspace select {{ .Workspace }} || terraform workspace new {{ .Workspace }} +terraform workspace select {{ .ExtraResources.Workspace }} || terraform workspace new {{ .ExtraResources.Workspace }} terraform apply -target=module.rds.data.aws_subnet_ids.command_private_subnets -auto-approve terraform apply -target=module.rds.module.rds_instance -auto-approve terraform apply -target=module.rds.module.postgres_db -auto-approve diff --git a/templates/rds-tf/main.tf b/templates/rds-tf/main.tf index e9c5ab3..c755ab0 100644 --- a/templates/rds-tf/main.tf +++ b/templates/rds-tf/main.tf @@ -3,7 +3,7 @@ terraform { bucket = "navi-bank-terraform-command-state" region = "ap-south-1" key = "rds" - workspace_key_prefix = "rds-states/{{ .Database.InstanceName }}" + workspace_key_prefix = "rds-states/{{ .ExtraResources.Database.InstanceName }}" profile = "cmd" acl = "bucket-owner-full-control" } @@ -11,23 +11,27 @@ terraform { module "rds" { source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/rds.git" - environment = {{ .Environment | quote }} - instance_name = {{ .Database.InstanceName | quote }} - password = {{ .Database.Password | quote }} - size = {{ .Database.SizeInGb }} - user = {{ .Database.User | quote }} + environment = {{ .ExtraResources.Environment | quote }} + instance_name = {{ .ExtraResources.Database.InstanceName | quote }} + password = {{ .ExtraResources.Database.Password | quote }} + size = {{ .ExtraResources.Database.SizeInGb }} + user = {{ .ExtraResources.Database.User | quote }} - databases = {{ .Database.DbNames | mustToJson }} - - {{- if .Database.AwsInstanceClass }} - aws_instance_class = {{ .Database.AwsInstanceClass | quote }} + databases = {{ .ExtraResources.Database.DbNames | mustToJson }} + database_tags = { + Team = {{ .Team.Name | quote }} + } + + {{- if .ExtraResources.Database.AwsInstanceClass }} + aws_instance_class = {{ .ExtraResources.Database.AwsInstanceClass | quote }} {{- end }} - {{- if .Database.PsqlFamily }} - psql_family = {{ .Database.PsqlFamily | quote }} + {{- if .ExtraResources.Database.PsqlFamily }} + psql_family = {{ .ExtraResources.Database.PsqlFamily | quote }} {{- end }} - {{- if .Database.PsqlEngineVersion }} - psql_engine_version = {{ .Database.PsqlEngineVersion | quote }} + {{- if .ExtraResources.Database.PsqlEngineVersion }} + psql_engine_version = {{ .ExtraResources.Database.PsqlEngineVersion | quote }} {{- end }} + } diff --git a/types.go b/types.go index 030a0b1..349833f 100644 --- a/types.go +++ b/types.go @@ -9,6 +9,7 @@ var workspaceMap = map[string]string { type Manifest struct { ExtraResources ExtraResources `json:"extraResources"` + Team Team `json:"team"` } type ExtraResources struct { @@ -28,3 +29,7 @@ type Database struct { DbNames []string `json:"dbNames"` InstanceName string `json:"instanceName"` } + +type Team struct { + Name string `json:"name"` +}