From b6d502674c1171019440ec83a86bb4b17de7d646 Mon Sep 17 00:00:00 2001 From: E Camden Fisher Date: Thu, 16 Dec 2021 15:28:23 -0500 Subject: [PATCH] only set tag specification if tags are passed --- api/orchestration_sgs.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/api/orchestration_sgs.go b/api/orchestration_sgs.go index 04eb33a..70a0be9 100644 --- a/api/orchestration_sgs.go +++ b/api/orchestration_sgs.go @@ -26,27 +26,32 @@ func (o *ec2Orchestrator) createSecurityGroup(ctx context.Context, req *Ec2Secur } }() - tags := []*ec2.Tag{} - for _, tag := range req.Tags { - for k, v := range tag { - tags = append(tags, &ec2.Tag{ - Key: aws.String(k), - Value: aws.String(v), - }) - } - } - - out, err := o.client.CreateSecurityGroup(ctx, &ec2.CreateSecurityGroupInput{ + input := &ec2.CreateSecurityGroupInput{ Description: aws.String(req.Description), GroupName: aws.String(req.GroupName), VpcId: aws.String(req.VpcId), - TagSpecifications: []*ec2.TagSpecification{ + } + + if len(req.Tags) > 0 { + tags := []*ec2.Tag{} + for _, tag := range req.Tags { + for k, v := range tag { + tags = append(tags, &ec2.Tag{ + Key: aws.String(k), + Value: aws.String(v), + }) + } + } + + input.SetTagSpecifications([]*ec2.TagSpecification{ { ResourceType: aws.String("security-group"), Tags: tags, }, - }, - }) + }) + } + + out, err := o.client.CreateSecurityGroup(ctx, input) if err != nil { return "", err }