@@ -37,25 +37,26 @@ func Generate(t *templator.Templator, cfg *config.Commit0Config, wg *sync.WaitGr
3737 t .Terraform .TemplateFiles (data , false , wg , pathPrefix )
3838}
3939
40+ // GetOutputs captures the terraform output for the specific variables
4041func GetOutputs (config * config.Commit0Config , pathPrefix string , outputs []string ) map [string ]string {
4142 outputsMap := make (map [string ]string )
4243
4344 log .Println ("Preparing aws environment..." )
4445
4546 envars := util .MakeAwsEnvars (util .GetSecrets ())
4647
47- path : = filepath .Join (pathPrefix , "terraform " )
48+ pathPrefix = filepath .Join (pathPrefix , "environments/staging " )
4849
4950 for _ , output := range outputs {
50- outputValue := util .ExecuteCommandOutput (exec .Command ("terraform" , "output" , output ), path , envars )
51+ outputValue := util .ExecuteCommandOutput (exec .Command ("terraform" , "output" , output ), pathPrefix , envars )
5152 outputsMap [output ] = outputValue
5253 }
5354
5455 return outputsMap
5556}
5657
57- // Execute terrafrom init & plan
58- func Execute (config * config.Commit0Config , pathPrefix string ) {
58+ // Init sets up anything required by Execute
59+ func Init (config * config.Commit0Config , pathPrefix string ) {
5960 // @TODO : Change this check. Most likely we should discover the accountid
6061 if config .Infrastructure .AWS .AccountId != "" {
6162 log .Println ("Preparing aws environment..." )
@@ -68,16 +69,31 @@ func Execute(config *config.Commit0Config, pathPrefix string) {
6869 log .Println (aurora .Cyan (emoji .Sprintf (":alarm_clock: Initializing remote backend..." )))
6970 util .ExecuteCommand (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "bootstrap/remote-state" ), envars )
7071 util .ExecuteCommand (exec .Command ("terraform" , "apply" , "-auto-approve" ), filepath .Join (pathPrefix , "bootstrap/remote-state" ), envars )
72+ }
73+ }
7174
72- log .Println (aurora .Cyan (":alarm_clock: Planning infrastructure..." ))
73- util .ExecuteCommand (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
74- util .ExecuteCommand (exec .Command ("terraform" , "plan" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
75+ // Execute terrafrom init & plan. May modify the config passed in
76+ func Execute (cfg * config.Commit0Config , pathPrefix string ) {
77+ // @TODO : Change this check. Most likely we should discover the accountid
78+ if cfg .Infrastructure .AWS .AccountId != "" {
79+ log .Println ("Preparing aws environment..." )
7580
76- log .Println (aurora .Cyan (":alarm_clock: Applying infrastructure configuration..." ))
77- util .ExecuteCommand (exec .Command ("terraform" , "apply" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
81+ envars := util .MakeAwsEnvars (util .GetSecrets ())
82+
83+ pathPrefix = filepath .Join (pathPrefix , "terraform" )
7884
79- log .Println (aurora .Cyan (":alarm_clock: Applying kubernetes configuration..." ))
80- util .ExecuteCommand (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "environments/staging/kubernetes" ), envars )
81- util .ExecuteCommand (exec .Command ("terraform" , "plan" ), filepath .Join (pathPrefix , "environments/staging/kubernetes" ), envars )
85+ log .Println (aurora .Cyan (emoji .Sprintf (":alarm_clock: Applying infrastructure configuration..." )))
86+ util .ExecuteCommand (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
87+ util .ExecuteCommand (exec .Command ("terraform" , "apply" , "-auto-approve" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
88+
89+ if cfg .Infrastructure .AWS .Cognito .Enabled {
90+ outputs := []string {
91+ "cognito_pool_id" ,
92+ "cognito_client_id" ,
93+ }
94+ outputValues := GetOutputs (cfg , pathPrefix , outputs )
95+ cfg .Frontend .Env .CognitoPoolID = outputValues ["cognito_pool_id" ]
96+ cfg .Frontend .Env .CognitoClientID = outputValues ["cognito_client_id" ]
97+ }
8298 }
8399}
0 commit comments