diff --git a/bindata.go b/bindata.go index 54649c9..053353f 100644 --- a/bindata.go +++ b/bindata.go @@ -112,7 +112,7 @@ func bindataTemplatesAwsrolestfDeploysh() (*asset, error) { size: 340, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582728061, 0), + modTime: time.Unix(1582729878, 0), } a := &asset{bytes: bytes, info: info} @@ -121,19 +121,19 @@ func bindataTemplatesAwsrolestfDeploysh() (*asset, error) { } var _bindataTemplatesAwsrolestfMaintf = []byte( - "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x91\x3f\x8f\xe3\x20\x10\xc5\x7b\x7f\x0a\xe4\x1e\x5b\xa7\xeb\x22\x45" + - "\xba\xe2\xd2\x5c\x71\x45\x72\xbd\x85\xf1\xd8\x46\x06\xc6\x07\x43\xfe\x28\xe1\xbb\xaf\x80\x55\x94\x55\xb2\x5a\x69" + - "\xe9\x18\xfd\xde\x83\xf7\x86\xc0\x39\x31\xa2\x33\xec\x5a\x31\xd6\x0b\xb9\x80\x1d\x58\xed\x7f\xd6\x79\xc0\x58\x1f" + - "\xe4\x02\xc4\x3e\x9e\x2d\xab\xad\x38\x2a\xde\x0b\xbb\xf0\xbb\x05\x97\x68\x8c\xb0\x03\xf7\x24\x08\xea\x2c\x77\x30" + - "\x29\xb4\xcf\x72\xb1\x72\x8f\x81\x66\xfe\xa3\x70\x0b\x5c\xd8\xd3\xd9\xb2\xda\x83\x3b\x2a\x09\x5c\x09\xc3\x1d\x6a" + - "\xf0\x05\x3f\xa1\x5b\xfc\x2a\x24\x74\x0b\x5c\xba\xd5\xc1\xa8\xce\x09\x57\xc2\x64\xaa\xbd\x5e\x59\xb3\x3b\x93\x13" + - "\x7b\xf0\x18\x9c\x04\xdf\xec\xec\x51\x39\xb4\x06\x2c\xb1\x18\x33\xf1\x1b\x56\x8d\x97\x34\x69\xfe\x0a\x03\x2c\x46" + - "\xfe\x62\x7c\x08\x63\xb2\x8f\xb1\xbc\xbd\x3a\x1c\x95\x86\xa7\xaf\x4a\x33\x14\x40\x48\xfd\x32\x4b\xa9\x92\xe3\xc9" + - "\x82\xe3\x63\xd0\x9a\x4b\xb4\xe4\x50\x27\x59\xac\x62\x55\x19\x1c\x82\x86\x1c\x23\xa7\x2d\x4b\x28\x01\x1e\x8c\x26" + - "\x45\x9b\x8d\xf7\xf3\xa6\x6d\x27\x45\xbf\x26\x45\x73\xe8\x1b\x69\x86\x26\x6f\x85\x40\xce\x8d\xb2\x6d\xbe\x28\x3b" + - "\x3a\xd1\xde\xeb\x6b\x26\x45\xe9\x39\x78\x28\x23\x79\x7e\xd1\xd7\x8d\xfd\x0f\x48\xa9\xa0\xf4\x9f\xb2\x93\x2e\x19" + - "\x7e\xa2\x3d\x14\x64\x9f\x88\x1b\x33\xc1\xd3\x3f\xfc\xe3\xd1\x16\x83\x24\xec\x6c\x2a\xfc\x3d\xd0\xb7\x76\x11\xab" + - "\xb7\x00\x00\x00\xff\xff\x9e\x05\xfd\x70\xbd\x02\x00\x00") + "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x91\x41\x6b\xdc\x30\x10\x85\xef\xfe\x15\xc2\x77\xc9\x94\xde\x16\x02" + + "\x6d\x68\x2e\x3d\x94\x12\x17\x7a\x34\x5a\xed\xd8\x16\x96\x34\xee\x68\xb4\xc9\xb2\xf1\x7f\x2f\x92\x92\xb2\x65\xb7" + + "\xb4\xd5\xcd\xc3\x7b\x9f\xe7\xbd\x61\x20\xd2\x23\x92\x17\xe7\x46\x88\xbd\x36\x0b\x84\x83\x68\xe3\xfb\xb6\x0c\x84" + + "\xd8\x27\xb3\x00\x8b\xdf\xdf\x9d\x68\xcf\x67\xa1\x7a\xd6\x0c\x3d\x23\xc1\x7d\x35\xaa\xfb\xa2\xfe\xa2\x3d\x88\x6d" + + "\x6b\x0b\x80\x60\xb2\x18\xae\x01\x7a\x95\x11\x13\xcf\xf2\x5d\xd5\x2d\x70\x12\x57\xef\x4e\xb4\x11\xe8\x68\x0d\x48" + + "\xab\xbd\x24\x74\x10\xab\xfc\x09\x69\x89\xab\x36\x30\x2c\x70\x1a\x56\x82\xd1\x3e\x67\xb9\xd5\xbe\xa8\xba\xbc\xe0" + + "\xc3\x33\x93\x7e\x84\x88\x89\x0c\x44\xf5\x10\x8e\x96\x30\x78\x08\x2c\xb6\xad\x28\x3e\xc1\xea\xf0\x94\x27\xea\x75" + + "\x6b\x79\x63\xdc\xa7\x31\xe3\xdf\x22\xad\x84\xa3\x75\xf0\x8f\x9d\x7c\xfc\xde\x7f\x7d\x35\xbc\x01\xb4\x71\x37\xb3" + + "\xd6\xb2\x25\x3e\x05\x20\x39\x26\xe7\xa4\xc1\xc0\x84\x2e\xdb\xb6\x66\x6b\x1a\x8f\x87\xe4\xa0\xc4\x2c\x6d\xd4\x33" + + "\xd5\x80\x17\xa0\xc9\xf2\x6e\x17\xe3\xbc\xeb\xba\xc9\xf2\x87\xc9\xf2\x9c\xf6\xca\xf8\x83\x0a\xfa\x68\x25\x83\x99" + + "\x95\x0d\x5d\xf9\xb0\x61\x24\xdd\xfd\xaa\x57\x4d\x96\xf3\xef\xe0\xa2\xac\xcc\xfc\x4b\x9f\x2f\xe2\x47\x42\xce\x11" + + "\xf3\x3e\xf5\x66\x43\x06\xfe\xc1\xdb\x57\xc9\x63\x56\xbc\x08\x9f\x22\x7f\xc3\xcf\x11\x43\x05\x64\xe3\x10\xf2\x41" + + "\x2e\xaa\xfd\xef\x5b\x6d\xcd\xcf\x00\x00\x00\xff\xff\xd4\xd2\x05\x95\xdf\x02\x00\x00") func bindataTemplatesAwsrolestfMaintfBytes() ([]byte, error) { return bindataRead( @@ -152,10 +152,10 @@ func bindataTemplatesAwsrolestfMaintf() (*asset, error) { info := bindataFileInfo{ name: "templates/aws-roles-tf/main.tf", - size: 701, + size: 735, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582727097, 0), + modTime: time.Unix(1582736085, 0), } a := &asset{bytes: bytes, info: info} @@ -192,7 +192,7 @@ func bindataTemplatesRdstfDeploysh() (*asset, error) { size: 373, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582718244, 0), + modTime: time.Unix(1582729878, 0), } a := &asset{bytes: bytes, info: info} @@ -240,7 +240,7 @@ func bindataTemplatesRdstfMaintf() (*asset, error) { size: 1316, md5checksum: "", mode: os.FileMode(420), - modTime: time.Unix(1582718244, 0), + modTime: time.Unix(1582729878, 0), } a := &asset{bytes: bytes, info: info} diff --git a/environment_config.go b/environment_config.go new file mode 100644 index 0000000..06e37c5 --- /dev/null +++ b/environment_config.go @@ -0,0 +1,25 @@ +package main + +var workspaceMap = map[string]string{ + "prod": "aps1.prod.navi-tech.in", + "cmd": "prod.cmd.navi-tech.in", + "dev": "nonprod.np.navi-tech.in", + "qa": "nonprod.np.navi-tech.in", + "spike": "spike.np.navi-tech.in", +} + +var storageBackendBucketMap = map[string]string{ + "prod": "navi-bank-terraform-command-state", + "cmd": "navi-bank-terraform-command-state", + "dev": "navi-bank-terraform-nonprod-state", + "qa": "navi-bank-terraform-nonprod-state", + "spike": "navi-bank-terraform-nonprod-state", +} + +var awsProfileMap = map[string]string{ + "prod": "prod", + "cmd": "cmd", + "dev": "nonprod", + "qa": "nonprod", + "spike": "nonprod", +} \ No newline at end of file diff --git a/main.go b/main.go index 613a2d4..1259186 100644 --- a/main.go +++ b/main.go @@ -33,8 +33,13 @@ func parseManifest(manifestPath string) (*Manifest, error) { log.Fatalf("\nErr: %v", err) return nil, err } + manifest.ExtraResources.Workspace = workspaceMap[manifest.ExtraResources.Environment] manifest.Deployment.NameSuffix = DEPLOYMENT_NAME_SUFFIX + + //Fix: Required for templating storage backend + manifest.StateStoreBackend.BucketName = storageBackendBucketMap[manifest.ExtraResources.Environment] + manifest.StateStoreBackend.AWSProfile = awsProfileMap[manifest.ExtraResources.Environment] return &manifest, nil } diff --git a/templates/aws-roles-tf/main.tf b/templates/aws-roles-tf/main.tf index c08c62b..c3b7e0f 100644 --- a/templates/aws-roles-tf/main.tf +++ b/templates/aws-roles-tf/main.tf @@ -1,10 +1,10 @@ terraform { backend "s3" { - bucket = "navi-bank-terraform-command-state" + bucket = "{{ .StateStoreBackend.BucketName }}" region = "ap-south-1" key = "service-iam-roles" workspace_key_prefix = "iamroles/{{ .ExtraResources.Environment }}/{{ .Deployment.Name }}-{{ .Deployment.NameSuffix }}" - profile = "cmd" + profile = "{{ .StateStoreBackend.AWSProfile }}" acl = "bucket-owner-full-control" } } diff --git a/types.go b/types.go index e4a7b36..727ccce 100644 --- a/types.go +++ b/types.go @@ -1,13 +1,5 @@ package main -var workspaceMap = map[string]string{ - "prod": "aps1.prod.navi-tech.in", - "cmd": "prod.cmd.navi-tech.in", - "dev": "nonprod.np.navi-tech.in", - "qa": "nonprod.np.navi-tech.in", - "spike": "spike.np.navi-tech.in", -} - const DEPLOYMENT_NAME_SUFFIX = "navi-service" type Deployment struct { @@ -19,6 +11,7 @@ type Manifest struct { ExtraResources ExtraResources `json:"extraResources"` Team Team `json:"team"` Deployment Deployment `json:"deployment"` + StateStoreBackend StateStoreBackend } type ExtraResources struct { @@ -52,3 +45,8 @@ type Policies struct { type ServiceRole struct { Policies []Policies `json:"policies"` } + +type StateStoreBackend struct { + BucketName string + AWSProfile string +} \ No newline at end of file