@@ -20,8 +20,8 @@ import (
2020
2121// Config represents the structure of the YAML file
2222type Config struct {
23- Systems []System `yaml:"systems"`
24- Providers ResourceProvider `yaml:"resourceProvider"`
23+ Systems []System `yaml:"systems"`
24+ Providers ResourceProvider `yaml:"resourceProvider"`
2525}
2626
2727type System struct {
@@ -33,9 +33,9 @@ type System struct {
3333}
3434
3535type Environment struct {
36- Name string `yaml:"name"`
37- Description string `yaml:"description"`
38- ResourceSelector map [string ]any `yaml:"resourceSelector"`
36+ Name string `yaml:"name"`
37+ Description string `yaml:"description"`
38+ ResourceSelector * map [string ]any `yaml:"resourceSelector,omitempty "`
3939}
4040
4141type Deployment struct {
@@ -212,6 +212,7 @@ func processSystemDeployments(
212212 system System ,
213213) {
214214 var deploymentWg sync.WaitGroup
215+ var environmentWg sync.WaitGroup
215216 for _ , deployment := range system .Deployments {
216217 deploymentWg .Add (1 )
217218 log .Info ("Creating deployment" , "system" , system .Name , "name" , deployment .Name )
@@ -223,9 +224,41 @@ func processSystemDeployments(
223224 & deploymentWg ,
224225 )
225226 }
227+
228+ for _ , environment := range system .Environments {
229+ environmentWg .Add (1 )
230+ log .Info ("Creating environment" , "system" , system .Name , "name" , environment .Name )
231+ go processEnvironment (ctx , client , systemID , environment , & environmentWg )
232+ }
233+
234+ environmentWg .Wait ()
226235 deploymentWg .Wait ()
227236}
228237
238+ func processEnvironment (
239+ ctx context.Context ,
240+ client * api.ClientWithResponses ,
241+ systemID uuid.UUID ,
242+ environment Environment ,
243+ environmentWg * sync.WaitGroup ,
244+ ) {
245+ defer environmentWg .Done ()
246+
247+ body := api.CreateEnvironmentJSONRequestBody {
248+ SystemId : systemID .String (),
249+ Name : environment .Name ,
250+ Description : & environment .Description ,
251+ }
252+ if environment .ResourceSelector != nil {
253+ body .ResourceSelector = environment .ResourceSelector
254+ }
255+
256+ _ , err := client .CreateEnvironmentWithResponse (ctx , body )
257+ if err != nil {
258+ log .Error ("Failed to create environment" , "name" , environment .Name , "error" , err )
259+ }
260+ }
261+
229262func processDeployment (
230263 ctx context.Context ,
231264 client * api.ClientWithResponses ,
0 commit comments