Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

ECS: replace github.com/sanathkr/go-yaml with gopkg.in/yaml.v3 #2228

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ecs/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"fmt"

applicationautoscaling2 "github.com/aws/aws-sdk-go/service/applicationautoscaling"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/applicationautoscaling"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/applicationautoscaling"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/compose-spec/compose-go/types"
)

Expand Down Expand Up @@ -63,7 +63,7 @@ func (b *ecsAPIService) createAutoscalingPolicy(project *types.Project, resource
role := fmt.Sprintf("%sAutoScalingRole", normalizeResourceName(service.Name))
template.Resources[role] = &iam.Role{
AssumeRolePolicyDocument: ausocalingAssumeRolePolicyDocument,
Path: "/",
Path: cloudformation.String("/"),
Policies: []iam.Role_Policy{
{
PolicyDocument: &PolicyDocument{
Expand Down Expand Up @@ -113,14 +113,14 @@ func (b *ecsAPIService) createAutoscalingPolicy(project *types.Project, resource
template.Resources[policy] = &applicationautoscaling.ScalingPolicy{
PolicyType: "TargetTrackingScaling",
PolicyName: policy,
ScalingTargetId: cloudformation.Ref(target),
ScalingTargetId: cloudformation.RefPtr(target),
StepScalingPolicyConfiguration: nil,
TargetTrackingScalingPolicyConfiguration: &applicationautoscaling.ScalingPolicy_TargetTrackingScalingPolicyConfiguration{
PredefinedMetricSpecification: &applicationautoscaling.ScalingPolicy_PredefinedMetricSpecification{
PredefinedMetricType: metric,
},
ScaleOutCooldown: 60,
ScaleInCooldown: 60,
ScaleOutCooldown: cloudformation.Int(60),
ScaleInCooldown: cloudformation.Int(60),
TargetValue: float64(targetPercent),
},
}
Expand Down
2 changes: 1 addition & 1 deletion ecs/autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package ecs
import (
"testing"

autoscaling "github.com/awslabs/goformation/v4/cloudformation/applicationautoscaling"
autoscaling "github.com/awslabs/goformation/v7/cloudformation/applicationautoscaling"
"gotest.tools/v3/assert"
)

Expand Down
40 changes: 20 additions & 20 deletions ecs/awsResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (

"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/ec2"
"github.com/awslabs/goformation/v4/cloudformation/ecs"
"github.com/awslabs/goformation/v4/cloudformation/efs"
"github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/ec2"
"github.com/awslabs/goformation/v7/cloudformation/ecs"
"github.com/awslabs/goformation/v7/cloudformation/efs"
"github.com/awslabs/goformation/v7/cloudformation/elasticloadbalancingv2"
"github.com/compose-spec/compose-go/types"
"github.com/docker/compose/v2/pkg/api"
"github.com/pkg/errors"
Expand Down Expand Up @@ -322,7 +322,7 @@ func (b *ecsAPIService) ensureCluster(r *awsResources, project *types.Project, t
return
}
template.Resources["Cluster"] = &ecs.Cluster{
ClusterName: project.Name,
ClusterName: cloudformation.String(project.Name),
Tags: projectTags(project),
}
r.cluster = cloudformationResource{logicalName: "Cluster"}
Expand All @@ -339,16 +339,16 @@ func (b *ecsAPIService) ensureNetworks(r *awsResources, project *types.Project,
securityGroup := networkResourceName(name)
template.Resources[securityGroup] = &ec2.SecurityGroup{
GroupDescription: fmt.Sprintf("%s Security Group for %s network", project.Name, name),
VpcId: r.vpc,
VpcId: cloudformation.String(r.vpc),
Tags: networkTags(project, net),
}

ingress := securityGroup + "Ingress"
template.Resources[ingress] = &ec2.SecurityGroupIngress{
Description: fmt.Sprintf("Allow communication within network %s", name),
Description: cloudformation.String(fmt.Sprintf("Allow communication within network %s", name)),
IpProtocol: allProtocols,
GroupId: cloudformation.Ref(securityGroup),
SourceSecurityGroupId: cloudformation.Ref(securityGroup),
GroupId: cloudformation.RefPtr(securityGroup),
SourceSecurityGroupId: cloudformation.RefPtr(securityGroup),
}

r.securityGroups[name] = cloudformation.Ref(securityGroup)
Expand All @@ -371,7 +371,7 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t
var lifecyclePolicies []efs.FileSystem_LifecyclePolicy
if policy, ok := volume.DriverOpts["lifecycle_policy"]; ok {
lifecyclePolicies = append(lifecyclePolicies, efs.FileSystem_LifecyclePolicy{
TransitionToIA: strings.TrimSpace(policy),
TransitionToIA: cloudformation.String(strings.TrimSpace(policy)),
})
}

Expand All @@ -391,7 +391,7 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t
n := volumeResourceName(name)
template.Resources[n] = &efs.FileSystem{
BackupPolicy: backupPolicy,
Encrypted: true,
Encrypted: cloudformation.Bool(true),
FileSystemPolicy: nil,
FileSystemTags: []efs.FileSystem_ElasticFileSystemTag{
{
Expand All @@ -407,11 +407,11 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t
Value: volume.Name,
},
},
KmsKeyId: kmsKeyID,
KmsKeyId: cloudformation.String(kmsKeyID),
LifecyclePolicies: lifecyclePolicies,
PerformanceMode: performanceMode,
ProvisionedThroughputInMibps: provisionedThroughputInMibps,
ThroughputMode: throughputMode,
PerformanceMode: cloudformation.String(performanceMode),
ProvisionedThroughputInMibps: cloudformation.Float64(provisionedThroughputInMibps),
ThroughputMode: cloudformation.String(throughputMode),
AWSCloudFormationDeletionPolicy: "Retain",
}
r.filesystems[name] = cloudformationResource{logicalName: n}
Expand Down Expand Up @@ -443,17 +443,17 @@ func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Proje
loadBalancerAttributes = append(
loadBalancerAttributes,
elasticloadbalancingv2.LoadBalancer_LoadBalancerAttribute{
Key: "load_balancing.cross_zone.enabled",
Value: "true",
Key: cloudformation.String("load_balancing.cross_zone.enabled"),
Value: cloudformation.String("true"),
})
}

template.Resources["LoadBalancer"] = &elasticloadbalancingv2.LoadBalancer{
Scheme: elbv2.LoadBalancerSchemeEnumInternetFacing,
Scheme: cloudformation.String(elbv2.LoadBalancerSchemeEnumInternetFacing),
SecurityGroups: securityGroups,
Subnets: r.subnetsIDs(),
Tags: projectTags(project),
Type: balancerType,
Type: cloudformation.String(balancerType),
LoadBalancerAttributes: loadBalancerAttributes,
}
r.loadBalancer = cloudformationARNResource{
Expand Down
94 changes: 47 additions & 47 deletions ecs/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
ecsapi "github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/elbv2"
cloudmapapi "github.com/aws/aws-sdk-go/service/servicediscovery"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/ec2"
"github.com/awslabs/goformation/v4/cloudformation/ecs"
"github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v4/cloudformation/logs"
"github.com/awslabs/goformation/v4/cloudformation/secretsmanager"
cloudmap "github.com/awslabs/goformation/v4/cloudformation/servicediscovery"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/ec2"
"github.com/awslabs/goformation/v7/cloudformation/ecs"
"github.com/awslabs/goformation/v7/cloudformation/elasticloadbalancingv2"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation/logs"
"github.com/awslabs/goformation/v7/cloudformation/secretsmanager"
cloudmap "github.com/awslabs/goformation/v7/cloudformation/servicediscovery"
"github.com/cnabio/cnab-to-oci/remotes"
"github.com/compose-spec/compose-go/types"
"github.com/distribution/distribution/v3/reference"
Expand Down Expand Up @@ -183,9 +183,9 @@ func (b *ecsAPIService) createService(project *types.Project, service types.Serv
if err != nil {
return err
}
definition.ExecutionRoleArn = cloudformation.Ref(taskExecutionRole)
definition.ExecutionRoleArn = cloudformation.RefPtr(taskExecutionRole)
if taskRole != "" {
definition.TaskRoleArn = cloudformation.Ref(taskRole)
definition.TaskRoleArn = cloudformation.RefPtr(taskRole)
}

taskDefinition := fmt.Sprintf("%sTaskDefinition", normalizeResourceName(service.Name))
Expand All @@ -212,9 +212,9 @@ func (b *ecsAPIService) createService(project *types.Project, service types.Serv
listenerName := b.createListener(service, port, template, targetGroupName, resources.loadBalancer, protocol)
dependsOn = append(dependsOn, listenerName)
serviceLB = append(serviceLB, ecs.Service_LoadBalancer{
ContainerName: service.Name,
ContainerPort: int(port.Target),
TargetGroupArn: cloudformation.Ref(targetGroupName),
ContainerName: cloudformation.String(service.Name),
ContainerPort: cloudformation.Int(int(port.Target)),
TargetGroupArn: cloudformation.RefPtr(targetGroupName),
})
}

Expand Down Expand Up @@ -247,31 +247,31 @@ func (b *ecsAPIService) createService(project *types.Project, service types.Serv

template.Resources[serviceResourceName(service.Name)] = &ecs.Service{
AWSCloudFormationDependsOn: dependsOn,
Cluster: resources.cluster.ARN(),
DesiredCount: desiredCount,
Cluster: cloudformation.String(resources.cluster.ARN()),
DesiredCount: cloudformation.Int(desiredCount),
DeploymentController: &ecs.Service_DeploymentController{
Type: ecsapi.DeploymentControllerTypeEcs,
Type: cloudformation.String(ecsapi.DeploymentControllerTypeEcs),
},
DeploymentConfiguration: &ecs.Service_DeploymentConfiguration{
MaximumPercent: maxPercent,
MinimumHealthyPercent: minPercent,
MaximumPercent: cloudformation.Int(maxPercent),
MinimumHealthyPercent: cloudformation.Int(minPercent),
},
LaunchType: launchType,
LaunchType: cloudformation.String(launchType),
// TODO we miss support for https://github.com/aws/containers-roadmap/issues/631 to select a capacity provider
LoadBalancers: serviceLB,
NetworkConfiguration: &ecs.Service_NetworkConfiguration{
AwsvpcConfiguration: &ecs.Service_AwsVpcConfiguration{
AssignPublicIp: assignPublicIP,
AssignPublicIp: cloudformation.String(assignPublicIP),
SecurityGroups: resources.serviceSecurityGroups(service),
Subnets: resources.subnetsIDs(),
},
},
PlatformVersion: platformVersion,
PropagateTags: ecsapi.PropagateTagsService,
SchedulingStrategy: ecsapi.SchedulingStrategyReplica,
PlatformVersion: cloudformation.String(platformVersion),
PropagateTags: cloudformation.String(ecsapi.PropagateTagsService),
SchedulingStrategy: cloudformation.String(ecsapi.SchedulingStrategyReplica),
ServiceRegistries: []ecs.Service_ServiceRegistry{serviceRegistry},
Tags: serviceTags(project, service),
TaskDefinition: cloudformation.Ref(normalizeResourceName(taskDefinition)),
TaskDefinition: cloudformation.RefPtr(normalizeResourceName(taskDefinition)),
}
return nil
}
Expand All @@ -285,12 +285,12 @@ func (b *ecsAPIService) createIngress(service types.ServiceConfig, net string, p
}
ingress := fmt.Sprintf("%s%dIngress", normalizeResourceName(net), port.Target)
template.Resources[ingress] = &ec2.SecurityGroupIngress{
CidrIp: "0.0.0.0/0",
Description: fmt.Sprintf("%s:%d/%s on %s network", service.Name, port.Target, port.Protocol, net),
GroupId: resources.securityGroups[net],
FromPort: int(port.Target),
CidrIp: cloudformation.String("0.0.0.0/0"),
Description: cloudformation.String(fmt.Sprintf("%s:%d/%s on %s network", service.Name, port.Target, port.Protocol, net)),
GroupId: cloudformation.String(resources.securityGroups[net]),
FromPort: cloudformation.Int(int(port.Target)),
IpProtocol: protocol,
ToPort: int(port.Target),
ToPort: cloudformation.Int(int(port.Target)),
}
}

Expand All @@ -305,8 +305,8 @@ func (b *ecsAPIService) createSecret(project *types.Project, name string, s type

resource := fmt.Sprintf("%sSecret", normalizeResourceName(s.Name))
template.Resources[resource] = &secretsmanager.Secret{
Description: fmt.Sprintf("Secret %s", s.Name),
SecretString: string(sensitiveData),
Description: cloudformation.String(fmt.Sprintf("Secret %s", s.Name)),
SecretString: cloudformation.String(string(sensitiveData)),
Tags: projectTags(project),
}
s.Name = cloudformation.Ref(resource)
Expand All @@ -321,8 +321,8 @@ func (b *ecsAPIService) createLogGroup(project *types.Project, template *cloudfo
}
logGroup := fmt.Sprintf("/docker-compose/%s", project.Name)
template.Resources["LogGroup"] = &logs.LogGroup{
LogGroupName: logGroup,
RetentionInDays: retention,
LogGroupName: cloudformation.String(logGroup),
RetentionInDays: cloudformation.Int(retention),
}
}

Expand Down Expand Up @@ -383,16 +383,16 @@ func (b *ecsAPIService) createListener(service types.ServiceConfig, port types.S
ForwardConfig: &elasticloadbalancingv2.Listener_ForwardConfig{
TargetGroups: []elasticloadbalancingv2.Listener_TargetGroupTuple{
{
TargetGroupArn: cloudformation.Ref(targetGroupName),
TargetGroupArn: cloudformation.RefPtr(targetGroupName),
},
},
},
Type: elbv2.ActionTypeEnumForward,
},
},
LoadBalancerArn: loadBalancer.ARN(),
Protocol: protocol,
Port: int(port.Target),
Protocol: cloudformation.String(protocol),
Port: cloudformation.Int(int(port.Target)),
}
return listenerName
}
Expand All @@ -405,37 +405,37 @@ func (b *ecsAPIService) createTargetGroup(project *types.Project, service types.
port.Published,
)
template.Resources[targetGroupName] = &elasticloadbalancingv2.TargetGroup{
Port: int(port.Target),
Protocol: protocol,
Port: cloudformation.Int(int(port.Target)),
Protocol: cloudformation.String(protocol),
Tags: projectTags(project),
TargetType: elbv2.TargetTypeEnumIp,
VpcId: vpc,
TargetType: cloudformation.String(elbv2.TargetTypeEnumIp),
VpcId: cloudformation.String(vpc),
}
return targetGroupName
}

func (b *ecsAPIService) createServiceRegistry(service types.ServiceConfig, template *cloudformation.Template, healthCheck *cloudmap.Service_HealthCheckConfig) ecs.Service_ServiceRegistry {
serviceRegistration := fmt.Sprintf("%sServiceDiscoveryEntry", normalizeResourceName(service.Name))
serviceRegistry := ecs.Service_ServiceRegistry{
RegistryArn: cloudformation.GetAtt(serviceRegistration, "Arn"),
RegistryArn: cloudformation.GetAttPtr(serviceRegistration, "Arn"),
}

template.Resources[serviceRegistration] = &cloudmap.Service{
Description: fmt.Sprintf("%q service discovery entry in Cloud Map", service.Name),
Description: cloudformation.String(fmt.Sprintf("%q service discovery entry in Cloud Map", service.Name)),
HealthCheckConfig: healthCheck,
HealthCheckCustomConfig: &cloudmap.Service_HealthCheckCustomConfig{
FailureThreshold: 1,
FailureThreshold: cloudformation.Float64(1),
},
Name: service.Name,
NamespaceId: cloudformation.Ref("CloudMap"),
Name: cloudformation.String(service.Name),
NamespaceId: cloudformation.RefPtr("CloudMap"),
DnsConfig: &cloudmap.Service_DnsConfig{
DnsRecords: []cloudmap.Service_DnsRecord{
{
TTL: 60,
Type: cloudmapapi.RecordTypeA,
},
},
RoutingPolicy: cloudmapapi.RoutingPolicyMultivalue,
RoutingPolicy: cloudformation.String(cloudmapapi.RoutingPolicyMultivalue),
},
}
return serviceRegistry
Expand Down Expand Up @@ -498,7 +498,7 @@ func (b *ecsAPIService) createTaskRole(project *types.Project, service types.Ser

func (b *ecsAPIService) createCloudMap(project *types.Project, template *cloudformation.Template, vpc string) {
template.Resources["CloudMap"] = &cloudmap.PrivateDnsNamespace{
Description: fmt.Sprintf("Service Map for Docker Compose project %s", project.Name),
Description: cloudformation.String(fmt.Sprintf("Service Map for Docker Compose project %s", project.Name)),
Name: fmt.Sprintf("%s.local", project.Name),
Vpc: vpc,
}
Expand Down
Loading