@@ -10,6 +10,7 @@ import (
1010const (
1111 environmentTemplate = `######################################
1212## DO NOT EDIT THIS FILE ##
13+ ## Environment version: 1 ##
1314## Generated by tfconfig ##
1415## tfconfig {{.TfconfigVersion}} ##
1516######################################
@@ -57,6 +58,62 @@ provider "aws" {
5758`
5859)
5960
61+ const (
62+ environmentTemplateV2 = `######################################
63+ ## DO NOT EDIT THIS FILE ##
64+ ## Environment version: 2 ##
65+ ## Generated by tfconfig ##
66+ ## tfconfig {{.TfconfigVersion}} ##
67+ ######################################
68+
69+ module "config" {
70+ source = "{{.ConfigModulePath}}"
71+ }
72+
73+ locals {
74+ name = "{{.ProjectName}}"
75+ domain = "{{.ProjectDomain}}"
76+ git_repo = "{{.GitRepo}}"
77+ aws_profile = "{{ if .Local }}{{.AwsProfile}}{{ else }}default{{ end }}"
78+ }
79+
80+ terraform {
81+ backend "s3" {
82+ encrypt = true{{ if .Local }}
83+ profile = "{{.AwsProfile}}"{{ end }}
84+ }
85+ required_providers {
86+ aws = {
87+ source = "hashicorp/aws"
88+ version = "{{.AwsProviderVersion}}"
89+ }
90+ null = {
91+ source = "hashicorp/null"
92+ version = "{{.NullProviderVersion}}"
93+ }
94+ random = {
95+ source = "hashicorp/random"
96+ version = "{{.RandomProviderVersion}}"
97+ }
98+ cloudinit = {
99+ source = "hashicorp/cloudinit"
100+ version = "{{.TemplateProviderVersion}}"
101+ }
102+ dns = {
103+ source = "hashicorp/dns"
104+ version = "{{.DnsProviderVersion}}"
105+ }
106+ }
107+ }
108+
109+ provider "aws" {
110+ region = module.config.region{{ if .Local }}
111+ profile = local.aws_profile{{ end }}
112+ }
113+
114+ `
115+ )
116+
60117type ProjectConfig struct {
61118 ConfigModulePath string
62119 TfconfigVersion string
@@ -82,6 +139,7 @@ type EnvCommand struct {
82139 app * App
83140 log * Log
84141 environment string
142+ modulesDir string
85143 modulesPath string
86144 modulesSource string
87145 modulesPathAbs string
@@ -139,7 +197,14 @@ func (c *EnvCommand) run(context *kingpin.ParseContext) error {
139197}
140198
141199func (c * EnvCommand ) validate (context * kingpin.ParseContext ) error {
142- c .template = c .app .ParseTemplate (environmentTemplate )
200+ //c.template = c.app.ParseTemplate(environmentTemplate)
201+ if c .app .isNewEnvVersion () {
202+ c .template = c .app .ParseTemplate (environmentTemplateV2 )
203+ c .modulesDir = ModulesDirV2
204+ } else {
205+ c .template = c .app .ParseTemplate (environmentTemplate )
206+ c .modulesDir = ModulesDir
207+ }
143208
144209 c .app .ValidatePath ()
145210
@@ -159,9 +224,9 @@ func (c *EnvCommand) validate(context *kingpin.ParseContext) error {
159224
160225 // TODO move under normalized path resolving
161226 // TODO refactor modules shouldnt looking twice
162- modulesAbsPath , isFoundModules := c .app .findModules (c .app .projectPath )
227+ modulesAbsPath , isFoundModules := c .app .findModules (c .app .projectPath , c . modulesDir )
163228 if ! isFoundModules {
164- c .log .ErrorF ("Cant find '%s' dir" , ModulesDir )
229+ c .log .ErrorF ("Cant find '%s' dir" , c . modulesDir )
165230 }
166231 c .modulesPathAbs = modulesAbsPath
167232
@@ -189,7 +254,7 @@ func (c *EnvCommand) validate(context *kingpin.ParseContext) error {
189254 // TODO modules shouldnt searching twice, see todo above
190255 modulesPath , isFoundModules := c .findModules (c .app .projectPath )
191256 if ! isFoundModules {
192- c .log .ErrorF ("Cant find '%s' dir" , ModulesDir )
257+ c .log .ErrorF ("Cant find '%s' dir" , c . modulesDir )
193258 }
194259
195260 c .modulesPath = modulesPath
@@ -199,8 +264,8 @@ func (c *EnvCommand) validate(context *kingpin.ParseContext) error {
199264// TODO use app.FindModules
200265func (c * EnvCommand ) findModules (path string ) (modulesPath string , isFound bool ) {
201266 for _ , v := range listSearchPaths () {
202- if c .app .FindFolder (GetFullPath (path , v ), ModulesDir ) {
203- return v + ModulesDir , true
267+ if c .app .FindFolder (GetFullPath (path , v ), c . modulesDir ) {
268+ return v + c . modulesDir , true
204269 }
205270 }
206271 return "" , false
0 commit comments