@@ -16,6 +16,8 @@ import (
1616 "github.com/commitdev/commit0/internal/config"
1717 "github.com/commitdev/commit0/internal/templator"
1818 "github.com/commitdev/commit0/internal/util"
19+ "github.com/kyokomi/emoji"
20+ "github.com/logrusorgru/aurora"
1921 "github.com/manifoldco/promptui"
2022 "gopkg.in/yaml.v2"
2123)
@@ -29,9 +31,26 @@ type Secrets struct {
2931 }
3032}
3133
34+ // @TODO : These are specific to a k8s version. If we make the version a config option we will need to change this
35+ var amiLookup = map [string ]string {
36+ "us-east-1" : "ami-0392bafc801b7520f" ,
37+ "us-east-2" : "ami-082bb518441d3954c" ,
38+ "us-west-2" : "ami-05d586e6f773f6abf" ,
39+ "eu-west-1" : "ami-059c6874350e63ca9" ,
40+ "eu-central-1" : "ami-0e21bc066a9dbabfa" ,
41+ }
42+
3243// Generate templates
3344func Generate (t * templator.Templator , cfg * config.Commit0Config , wg * sync.WaitGroup , pathPrefix string ) {
34- data := templator.GenericTemplateData {* cfg }
45+ if cfg .Infrastructure .AWS .EKS .WorkerAMI == "" {
46+ ami , found := amiLookup [cfg .Infrastructure .AWS .Region ]
47+ if ! found {
48+ log .Fatalln (aurora .Red (emoji .Sprintf (":exclamation: Unable to look up an AMI for the chosen region" )))
49+ }
50+
51+ cfg .Infrastructure .AWS .EKS .WorkerAMI = ami
52+ }
53+ data := templator.GenericTemplateData {Config : * cfg }
3554 t .Kubernetes .TemplateFiles (data , false , wg , pathPrefix )
3655}
3756
@@ -50,17 +69,31 @@ func Execute(config *config.Commit0Config, pathPrefix string) {
5069 }
5170
5271 envars := getAwsEnvars (readSecrets ())
53- log .Println ("Planning infrastructure..." )
54- execute (exec .Command ("terraform" , "init" ), pathPrefix , envars )
55- execute (exec .Command ("terraform" , "plan" ), pathPrefix , envars )
72+
73+ pathPrefix = filepath .Join (pathPrefix , "kubernetes/terraform" )
74+
75+ // @TODO : A check here would be nice to see if this stuff exists first, mostly for testing
76+ log .Println (aurora .Cyan (emoji .Sprintf (":alarm_clock: Initializing remote backend..." )))
77+ execute (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "bootstrap/remote-state" ), envars )
78+ execute (exec .Command ("terraform" , "apply" , "-auto-approve" ), filepath .Join (pathPrefix , "bootstrap/remote-state" ), envars )
79+
80+ log .Println (aurora .Cyan (":alarm_clock: Planning infrastructure..." ))
81+ execute (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
82+ execute (exec .Command ("terraform" , "plan" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
83+
84+ log .Println (aurora .Cyan (":alarm_clock: Applying infrastructure configuration..." ))
85+ execute (exec .Command ("terraform" , "apply" ), filepath .Join (pathPrefix , "environments/staging" ), envars )
86+
87+ log .Println (aurora .Cyan (":alarm_clock: Applying kubernetes configuration..." ))
88+ execute (exec .Command ("terraform" , "init" ), filepath .Join (pathPrefix , "environments/staging/kubernetes" ), envars )
89+ execute (exec .Command ("terraform" , "plan" ), filepath .Join (pathPrefix , "environments/staging/kubernetes" ), envars )
5690 }
5791}
5892
5993func execute (cmd * exec.Cmd , pathPrefix string , envars []string ) {
6094 dir := util .GetCwd ()
6195
62- kubDir := path .Join (pathPrefix , "kubernetes/terraform/environments/staging" )
63- cmd .Dir = path .Join (dir , kubDir )
96+ cmd .Dir = path .Join (dir , pathPrefix )
6497
6598 stdoutPipe , _ := cmd .StdoutPipe ()
6699 stderrPipe , _ := cmd .StderrPipe ()
0 commit comments