From e00dd68489695dd1609d993e547f4652b209c06a Mon Sep 17 00:00:00 2001 From: piyush-sinha Date: Wed, 26 Feb 2020 17:33:50 +0530 Subject: [PATCH] [ch3990] | Piyush & Abhishek | Incorporate new changes from provisioner --- bindata.go | 56 +++++++++++++++----------------- templates/aws-roles-tf/deploy.sh | 12 +++---- templates/aws-roles-tf/main.tf | 6 ++-- types.go | 49 ++++++++++------------------ 4 files changed, 52 insertions(+), 71 deletions(-) diff --git a/bindata.go b/bindata.go index 7b14e3f..51597ee 100644 --- a/bindata.go +++ b/bindata.go @@ -82,18 +82,14 @@ func (fi bindataFileInfo) Sys() interface{} { } var _bindataTemplatesAwsrolestfDeploysh = []byte( - "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x8f\xd1\xee\xd2\x30\x14\xc6\xef\xfb\x14\x9f\xdb\x12\xae\xb6\xff\x03" + - "\x18\x62\x06\x2c\x6a\x22\x68\x18\x44\x2f\x48\x48\xe9\xce\x58\xb3\xae\x5d\xda\x8e\x41\xc6\xde\xdd\x80\x88\x44\xbd" + - "\xec\xd7\xdf\x39\xbf\xf3\x85\xef\xde\x0e\x52\xbf\xb9\x8a\xb1\x10\x74\x96\x1e\x7d\x45\x1a\x5c\x5f\x20\x4c\xd3\x70" + - "\x5d\xa0\xe4\x52\x39\xe6\xc8\x23\x26\x16\xa2\x26\x6a\xe1\x2d\x17\x35\x4c\x09\x5f\x11\x14\x77\x1e\x74\x26\xd1\x79" + - "\x2a\x7e\x8f\x31\x6f\x79\x8b\xc9\xed\x6f\xff\x88\xa6\x91\xe8\xac\x25\xfd\x0c\xde\xe3\xaf\x60\x1a\xcd\xd2\xfc\xd3" + - "\x7e\xfe\x75\xb9\x4c\x57\x8b\x09\x16\xd9\x6c\xfb\xf1\x76\x98\xa8\x0c\xb8\x06\x59\x6b\x2c\x1a\x72\x8e\x1f\x09\x07" + - "\x2a\x8d\xa5\xfb\xd5\x52\x1f\x1f\xc2\x3b\x1a\xec\x82\x68\x78\x55\x8f\xbb\xe0\x4f\x1f\xa9\xa8\x40\x2f\x7d\xf5\xab" + - "\xb0\x30\x05\x21\xfa\x90\x04\x13\x64\x3f\x3e\x6f\x98\x27\x6b\x79\x69\x6c\x03\xa9\xa5\x7f\x79\xf6\xc6\xd6\xae\xe5" + - "\x82\xe0\x48\x91\xf0\x18\x06\x24\xdf\x9f\xe1\x38\xe2\x7a\xc5\xff\x70\x4d\xfd\x3f\xec\xcb\x5e\xde\xb6\xea\x82\x98" + - "\x77\xde\xc4\xbc\x6d\xad\x39\x11\xab\xbb\x03\x09\xaf\x20\x8c\x2e\xe5\x11\x9d\xa3\x58\x18\xed\xe9\xec\x11\x0e\xf3" + - "\x2f\xdb\x7c\x93\xad\xc7\x27\xf5\xd8\x50\xde\x2d\x39\xd9\x93\x14\xb4\x36\x8a\x92\x15\x6f\x6e\xb2\xe4\xc2\x1b\x85" + - "\x58\x23\x1c\x56\xe9\x32\xcb\xbf\xa5\xf3\x6c\x64\x3f\x03\x00\x00\xff\xff\xa2\x4c\xce\x13\xfc\x01\x00\x00") + "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x8d\xcd\x6a\xc2\x40\x14\x85\xf7\xf3\x14\xb7\xe8\x76\xe2\x33\x88\x64" + + "\xd7\x4a\x49\x5a\xba\xbe\x4e\x4f\xea\xe0\xfc\x31\x73\x63\x12\x62\xde\xbd\x14\x8a\xb8\x08\xb8\x3c\xf0\x7d\xe7\xdb" + + "\xbc\xec\x4e\x36\xec\xca\x59\xa9\x0d\x61\xb4\x42\xc3\x19\x81\x38\x4c\x64\xa2\xf7\x1c\xbe\xa9\x63\xeb\x8a\x2a\x10" + + "\xd2\x50\x4a\x90\x33\x77\x31\x7b\xb2\xc1\xca\xc3\x1c\x62\xbe\x94\xc4\x06\x54\xe0\x60\x84\xe6\x99\xaa\x7a\x94\xcc" + + "\x0d\x4a\xec\xb3\x41\xa9\xbe\xee\xcc\xb2\xd0\xed\x46\x6b\x76\xc0\xf0\x4c\x7d\xa8\x72\x4a\x6e\x22\xcd\xbd\x44\xcd" + + "\x29\xe5\x78\x85\x52\x97\xfe\x04\x23\x8e\x4c\x0c\x9d\xfd\xa1\xbe\x40\x9b\x18\x04\xa3\xd0\x76\x3e\xbc\x7e\xb6\x1f" + + "\x75\xb3\xdc\xa9\xff\x8b\x6e\xad\xda\x22\x5f\xad\x41\x13\x1d\xaa\x23\xfb\xbf\x78\x35\xb1\x77\xa4\x03\x6d\xe7\xe3" + + "\xfe\xad\x6e\xdf\xf7\x87\x7a\x51\xbf\x01\x00\x00\xff\xff\xbe\xdc\x5b\x53\x48\x01\x00\x00") func bindataTemplatesAwsrolestfDeployshBytes() ([]byte, error) { return bindataRead( @@ -112,10 +108,10 @@ func bindataTemplatesAwsrolestfDeploysh() (*asset, error) { info := bindataFileInfo{ name: "templates/aws-roles-tf/deploy.sh", - size: 508, + size: 328, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582717639, 0), + modTime: time.Unix(1582718514, 0), } a := &asset{bytes: bytes, info: info} @@ -124,18 +120,18 @@ func bindataTemplatesAwsrolestfDeploysh() (*asset, error) { } var _bindataTemplatesAwsrolestfMaintf = []byte( - "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x90\x31\x8f\xe3\x20\x10\x85\x7b\xff\x8a\x91\x7b\x6c\x9d\xae\x8b\x14" + - "\xe9\x9a\x6b\xae\xb8\x62\x77\xfb\x08\xe3\xb1\x8d\x0c\x8c\x17\x86\x64\xa3\x84\xff\xbe\x02\xb4\x51\x36\x59\x3a\x46" + - "\xef\xbd\x79\xf3\x31\x7a\x2f\x27\xf2\x16\x2e\x0d\xc0\x20\xd5\x8a\x6e\x84\x36\xfc\x6e\xcb\x00\x60\x88\x6a\x45\x86" + - "\xef\x6f\x0f\xad\x93\x47\x2d\x06\xe9\x56\x71\x8b\x10\x8a\xac\x95\x6e\x14\x81\x25\x63\x5b\xec\x1e\x67\x4d\xee\xd9" + - "\x2e\x37\x11\x28\xf2\x22\x7e\x55\xdd\x8a\x67\x78\x7a\x7b\x68\x03\xfa\xa3\x56\x28\xb4\xb4\xc2\x93\xc1\x50\xe5\x27" + - "\xf2\x6b\xd8\xa4\xc2\xc3\x8a\xe7\xc3\xe6\x71\xd2\x1f\x59\xae\xa5\x2d\xaa\xfe\x72\x81\xee\xaf\x3b\x6a\x4f\xce\xa2" + - "\x63\x48\xa9\x8c\x5e\x6b\xdc\x0b\x19\xec\xfe\x4b\x8b\x90\x52\x0d\xdc\x3c\x4d\xda\xe0\xd3\x7e\x65\xc7\x2a\x90\xca" + - "\xfc\x58\xb0\xf2\x11\x74\x72\xe8\xc5\x14\x8d\x11\x8a\x1c\x7b\x32\xd9\x96\x9a\xd4\x34\x96\xc6\x68\xb0\x74\x2b\x27" + - "\x54\xb2\x81\xa2\x57\x78\x17\x34\x6b\xde\xed\x42\x58\x76\x7d\x3f\x6b\xfe\x33\x6b\x5e\xe2\xd0\x29\x3b\x76\x05\x35" + - "\xa3\x5a\x3a\xed\xfa\xf2\xd1\x6e\xf2\xb2\xbf\x31\xe9\x66\xcd\x79\x1d\xde\x1d\x9c\x33\x1f\x21\x5c\xe1\x3d\x12\xe7" + - "\xa3\x73\x81\x8a\xe2\x90\x13\xbe\x4a\x3c\x20\x82\x2b\xd8\x18\xf8\x8d\xfe\x05\x72\xd9\x95\x9a\xcf\x00\x00\x00\xff" + - "\xff\x48\x68\xe4\x76\x30\x02\x00\x00") + "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x91\xbf\xce\xdb\x30\x0c\xc4\x77\x3f\x05\xe1\x5d\x36\x8a\x6e\x01\x3e" + + "\xa0\x4b\x96\x0e\x1d\xd2\xee\x81\x2c\xd3\xb6\x60\x49\x74\x29\x2a\x7f\x90\xf8\xdd\x0b\x59\x68\x90\x22\x41\x3f\x6e" + + "\x36\x8e\x77\xc7\x9f\x04\x99\xf5\x40\xec\xe1\x56\x01\x74\xda\xcc\x18\x7a\xa8\xe3\xd7\x7a\xfb\x01\xd0\x25\x33\xa3" + + "\xc0\xbf\xf3\x01\x75\xd0\x27\xab\x3a\x1d\x66\xf5\xb0\x50\x86\xbc\xd7\xa1\x57\x51\xb4\x60\xbd\xad\x33\x8e\x96\xc2" + + "\xeb\xba\x5e\x54\xa4\x24\x93\xfa\x52\x74\x33\x5e\xe1\x65\x3e\xa0\x8e\xc8\x27\x6b\x50\x59\xed\x15\x93\xc3\x58\xe4" + + "\x67\xe2\x39\x2e\xda\xe0\x71\xc6\xeb\x71\x61\x1c\xec\x25\xcb\xad\xf6\x9b\xaa\xbd\xdd\xa0\xd9\x5f\x84\xf5\x01\x23" + + "\x25\x36\x18\x9b\x7d\x38\x59\xa6\xe0\x31\x08\xac\xeb\x3b\xc5\xcf\x12\x76\x20\x87\xcd\x0f\xed\x11\xd6\xb5\xc4\x2d" + + "\x4c\x83\x75\xf8\xd2\xce\xf8\xbe\x08\xb4\x71\x6f\xeb\x17\x7a\x8a\xce\x01\x59\x0d\xc9\x39\x65\x28\x08\x93\xcb\x6b" + + "\x6b\xb5\x56\x95\xa7\x3e\x39\xdc\x9a\x6f\x07\x16\xee\xa5\xd1\x93\xd1\x68\x65\xb7\x8b\x71\xda\xb5\xed\x68\xe5\xdb" + + "\x68\x65\x4a\x5d\x63\x7c\xdf\x6c\x0f\x21\x68\xa6\xc6\x86\x76\xfb\xb0\x61\x60\xdd\x3e\x88\x35\xa3\x95\x1c\x87\x4f" + + "\xf7\x67\xcf\x4f\x10\xdd\xe1\x77\x22\xc9\x0c\x72\x9f\x42\xe6\x98\x0d\xff\x76\xfa\x3f\x40\xb8\x83\x4f\x51\x7e\xd1" + + "\xf7\x48\x21\x9b\xac\xd5\x9f\x00\x00\x00\xff\xff\x7a\x00\x8b\x07\x6c\x02\x00\x00") func bindataTemplatesAwsrolestfMaintfBytes() ([]byte, error) { return bindataRead( @@ -154,10 +150,10 @@ func bindataTemplatesAwsrolestfMaintf() (*asset, error) { info := bindataFileInfo{ name: "templates/aws-roles-tf/main.tf", - size: 560, + size: 620, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582717639, 0), + modTime: time.Unix(1582718551, 0), } a := &asset{bytes: bytes, info: info} @@ -194,7 +190,7 @@ func bindataTemplatesRdstfDeploysh() (*asset, error) { size: 373, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582717464, 0), + modTime: time.Unix(1582718244, 0), } a := &asset{bytes: bytes, info: info} @@ -242,7 +238,7 @@ func bindataTemplatesRdstfMaintf() (*asset, error) { size: 1316, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582717464, 0), + modTime: time.Unix(1582718244, 0), } a := &asset{bytes: bytes, info: info} diff --git a/templates/aws-roles-tf/deploy.sh b/templates/aws-roles-tf/deploy.sh index 695e5ad..2dfe164 100644 --- a/templates/aws-roles-tf/deploy.sh +++ b/templates/aws-roles-tf/deploy.sh @@ -2,12 +2,10 @@ # exit when any command fails set -e -# keep track of the last executed command -trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG -# echo an error message before exiting -trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT + terraform init -terraform workspace select {{ .Workspace }} || terraform workspace new {{ .Workspace }} +terraform workspace select {{ .ExtraResources.Workspace }} || terraform workspace new {{ .ExtraResources.Workspace }} terraform apply -auto-approve -kubectl config use-context #{CLUSTER} -kubectl apply -f {{ .ServiceRole.Name }}.yaml -n #{NAMESPACE} + +kubectl config use-context ${CLUSTER} +kubectl apply -f {{ .ExtraResources.ServiceRole.Name }}.yaml -n ${NAMESPACE} diff --git a/templates/aws-roles-tf/main.tf b/templates/aws-roles-tf/main.tf index 3effaf9..55f43a9 100644 --- a/templates/aws-roles-tf/main.tf +++ b/templates/aws-roles-tf/main.tf @@ -3,7 +3,7 @@ terraform { bucket = "navi-bank-terraform-command-state" region = "ap-south-1" key = "service-iam-roles" - workspace_key_prefix = "iamroles/{{ .Environment }}/{{ .ServiceRole.Name }}" + workspace_key_prefix = "iamroles/{{ .ExtraResources.Environment }}/{{ .ExtraResources.ServiceRole.Name }}" profile = "cmd" acl = "bucket-owner-full-control" } @@ -11,6 +11,6 @@ terraform { module "iam-role" { source = "git::ssh://git@github.cmd.navi-tech.in/navi-infra/iam-roles.git" - environment = {{ .Environment | quote }} - service_role = {{ .ServiceRole | mustToJson }} + environment = {{ .ExtraResources.Environment | quote }} + service_role = {{ .ExtraResources.ServiceRole | mustToJson }} } diff --git a/types.go b/types.go index c6d4217..dd21e21 100644 --- a/types.go +++ b/types.go @@ -1,59 +1,46 @@ package main -var workspaceMap = map[string]string { - "prod": "aps1.prod.navi-tech.in", - "cmd": "prod.cmd.navi-tech.in", +var workspaceMap = map[string]string{ + "prod": "aps1.prod.navi-tech.in", + "cmd": "prod.cmd.navi-tech.in", "nonprod": "nonprod.np.navi-tech.in", - "spike": "spike.np.navi-tech.in", + "spike": "spike.np.navi-tech.in", } type Manifest struct { ExtraResources ExtraResources `json:"extraResources"` - Team Team `json:"team"` + Team Team `json:"team"` } type ExtraResources struct { Environment string `json:"environment"` - Workspace string - Database Database `json:"database"` + Workspace string + Database Database `json:"database"` ServiceRole ServiceRole `json:"service_role"` } //We provide defaults in respective terraforms instead of here to keep all values at one place type Database struct { - AwsInstanceClass string `json:"awsInstanceClass"` - PsqlFamily string `json:"psqlFamily"` - PsqlEngineVersion string `json:"psqlEngineVersion"` - User string `json:"user"` - Password string `json:"password"` - SizeInGb int `json:"sizeInGb"` - DbNames []string `json:"dbNames"` - InstanceName string `json:"instanceName"` + AwsInstanceClass string `json:"awsInstanceClass"` + PsqlFamily string `json:"psqlFamily"` + PsqlEngineVersion string `json:"psqlEngineVersion"` + User string `json:"user"` + Password string `json:"password"` + SizeInGb int `json:"sizeInGb"` + DbNames []string `json:"dbNames"` + InstanceName string `json:"instanceName"` } type Team struct { Name string `json:"name"` } -type ServiceRole struct { - Name string `json:"name"` - Policies []Policies `json:"policies"` -} - type Policies struct { - Actions []string `json:"actions"` - Resource string `json:"resource"` -} -type Team struct { - Name string `json:"name"` + Actions []string `json:"actions"` + Resource string `json:"resource"` } type ServiceRole struct { - Name string `json:"name"` + Name string `json:"name"` Policies []Policies `json:"policies"` } - -type Policies struct { - Actions []string `json:"actions"` - Resource string `json:"resource"` -} \ No newline at end of file