@@ -31,8 +31,12 @@ import (
31
31
ecsclient "github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/ecs"
32
32
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/commands/flags"
33
33
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/config"
34
+ "github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils"
34
35
"github.com/aws/aws-sdk-go/aws"
36
+ sdkCFN "github.com/aws/aws-sdk-go/service/cloudformation"
37
+ "github.com/aws/aws-sdk-go/service/ecs"
35
38
"github.com/docker/libcompose/project"
39
+ "github.com/pkg/errors"
36
40
"github.com/sirupsen/logrus"
37
41
"github.com/urfave/cli"
38
42
)
@@ -238,6 +242,7 @@ func createCluster(context *cli.Context, awsClients *AWSClients, commandConfig *
238
242
if err != nil {
239
243
return err
240
244
}
245
+
241
246
cfnParams .Add (ParameterKeyCluster , commandConfig .Cluster )
242
247
if context .Bool (flags .NoAutoAssignPublicIPAddressFlag ) {
243
248
cfnParams .Add (ParameterKeyAssociatePublicIPAddress , "false" )
@@ -282,6 +287,14 @@ func createCluster(context *cli.Context, awsClients *AWSClients, commandConfig *
282
287
return fmt .Errorf ("You have selected subnets. Please specify a VPC with the '--%s' flag" , flags .VpcIdFlag )
283
288
}
284
289
290
+ tags := make ([]* ecs.Tag , 0 )
291
+ if tagVal := context .String (flags .ResourceTagsFlag ); tagVal != "" {
292
+ tags , err = utils .GetTags (tagVal , tags )
293
+ if err != nil {
294
+ return err
295
+ }
296
+ }
297
+
285
298
if launchType == config .LaunchTypeEC2 {
286
299
architecture , err := determineArchitecture (cfnParams )
287
300
if err != nil {
@@ -306,7 +319,7 @@ func createCluster(context *cli.Context, awsClients *AWSClients, commandConfig *
306
319
}
307
320
308
321
// Create ECS cluster
309
- if _ , err := ecsClient .CreateCluster (commandConfig .Cluster ); err != nil {
322
+ if _ , err := ecsClient .CreateCluster (commandConfig .Cluster , tags ); err != nil {
310
323
return err
311
324
}
312
325
@@ -321,9 +334,12 @@ func createCluster(context *cli.Context, awsClients *AWSClients, commandConfig *
321
334
}
322
335
}
323
336
// Create cfn stack
324
- template := cloudformation .GetClusterTemplate ()
337
+ template , err := cloudformation .GetClusterTemplate (tags , stackName )
338
+ if err != nil {
339
+ return errors .Wrapf (err , "Error building cloudformation template" )
340
+ }
325
341
326
- if _ , err := cfnClient .CreateStack (template , stackName , true , cfnParams ); err != nil {
342
+ if _ , err := cfnClient .CreateStack (template , stackName , true , cfnParams , convertToCFNTags ( tags ) ); err != nil {
327
343
return err
328
344
}
329
345
@@ -354,6 +370,18 @@ func determineArchitecture(cfnParams *cloudformation.CfnStackParams) (string, er
354
370
return architecture , nil
355
371
}
356
372
373
+ // unfortunately go SDK lacks a unified Tag type
374
+ func convertToCFNTags (tags []* ecs.Tag ) []* sdkCFN.Tag {
375
+ var cfnTags []* sdkCFN.Tag
376
+ for _ , tag := range tags {
377
+ cfnTags = append (cfnTags , & sdkCFN.Tag {
378
+ Key : tag .Key ,
379
+ Value : tag .Value ,
380
+ })
381
+ }
382
+ return cfnTags
383
+ }
384
+
357
385
var newCommandConfig = func (context * cli.Context , rdwr config.ReadWriter ) (* config.CommandConfig , error ) {
358
386
return config .NewCommandConfig (context , rdwr )
359
387
}
@@ -378,7 +406,16 @@ func createEmptyCluster(context *cli.Context, ecsClient ecsclient.ECSClient, cfn
378
406
return fmt .Errorf ("A CloudFormation stack already exists for the cluster '%s'." , commandConfig .Cluster )
379
407
}
380
408
381
- if _ , err := ecsClient .CreateCluster (commandConfig .Cluster ); err != nil {
409
+ tags := make ([]* ecs.Tag , 0 )
410
+ var err error
411
+ if tagVal := context .String (flags .ResourceTagsFlag ); tagVal != "" {
412
+ tags , err = utils .GetTags (tagVal , tags )
413
+ if err != nil {
414
+ return err
415
+ }
416
+ }
417
+
418
+ if _ , err := ecsClient .CreateCluster (commandConfig .Cluster , tags ); err != nil {
382
419
return err
383
420
}
384
421
0 commit comments