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

Commit 6be1902

Browse files
committed
ECS: supporting x-aws-assign_public_ip
Allowing users to choose whether their instances should get a public IP address or not. Defaulting to "no".
1 parent 79770d5 commit 6be1902

6 files changed

+346
-2
lines changed

ecs/cloudformation.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ func (b *ecsAPIService) createService(project *types.Project, service types.Serv
235235
return err
236236
}
237237

238-
assignPublicIP := ecsapi.AssignPublicIpEnabled
238+
assignPublicIP := "DISABLED"
239+
if assignPublicIPSetting, ok := service.Extensions[extensionAssignPublicIp]; ok && assignPublicIPSetting.(bool){
240+
assignPublicIP = ecsapi.AssignPublicIpEnabled
241+
}
239242
launchType := ecsapi.LaunchTypeFargate
240243
platformVersion := "1.4.0" // LATEST which is set to 1.3.0 (?) which doesn’t allow efs volumes.
241244
if requireEC2(service) {

ecs/cloudformation_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ func TestSimpleConvert(t *testing.T) {
5151
golden.Assert(t, result, expected)
5252
}
5353

54+
func TestSlightlyComplexConvert(t *testing.T) {
55+
bytes, err := ioutil.ReadFile("testdata/input/slightly-complex-service.yaml")
56+
assert.NilError(t, err)
57+
template := convertYaml(t, string(bytes), nil, useDefaultVPC)
58+
resultAsJSON, err := marshall(template, "yaml")
59+
assert.NilError(t, err)
60+
result := fmt.Sprintf("%s\n", string(resultAsJSON))
61+
expected := "slightly-complex-cloudformation-conversion.golden"
62+
golden.Assert(t, result, expected)
63+
}
64+
5465
func TestLogging(t *testing.T) {
5566
template := convertYaml(t, `
5667
services:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
entrance:
3+
image: nginx
4+
ports:
5+
- "80:80"
6+
x-aws-assign_public_ip: true
7+
8+
sensitive:
9+
image: python

ecs/testdata/simple-cloudformation-conversion.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Resources:
8181
Ref: SimpleTCP80TargetGroup
8282
NetworkConfiguration:
8383
AwsvpcConfiguration:
84-
AssignPublicIp: ENABLED
84+
AssignPublicIp: DISABLED
8585
SecurityGroups:
8686
- Ref: DefaultNetwork
8787
Subnets:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Resources:
3+
CloudMap:
4+
Properties:
5+
Description: Service Map for Docker Compose project TestSlightlyComplexConvert
6+
Name: TestSlightlyComplexConvert.local
7+
Vpc: vpc-123
8+
Type: AWS::ServiceDiscovery::PrivateDnsNamespace
9+
Cluster:
10+
Properties:
11+
ClusterName: TestSlightlyComplexConvert
12+
Tags:
13+
- Key: com.docker.compose.project
14+
Value: TestSlightlyComplexConvert
15+
Type: AWS::ECS::Cluster
16+
Default80Ingress:
17+
Properties:
18+
CidrIp: 0.0.0.0/0
19+
Description: entrance:80/tcp on default network
20+
FromPort: 80
21+
GroupId:
22+
Ref: DefaultNetwork
23+
IpProtocol: TCP
24+
ToPort: 80
25+
Type: AWS::EC2::SecurityGroupIngress
26+
DefaultNetwork:
27+
Properties:
28+
GroupDescription: TestSlightlyComplexConvert Security Group for default network
29+
Tags:
30+
- Key: com.docker.compose.project
31+
Value: TestSlightlyComplexConvert
32+
- Key: com.docker.compose.network
33+
Value: TestSlightlyComplexConvert_default
34+
VpcId: vpc-123
35+
Type: AWS::EC2::SecurityGroup
36+
DefaultNetworkIngress:
37+
Properties:
38+
Description: Allow communication within network default
39+
GroupId:
40+
Ref: DefaultNetwork
41+
IpProtocol: "-1"
42+
SourceSecurityGroupId:
43+
Ref: DefaultNetwork
44+
Type: AWS::EC2::SecurityGroupIngress
45+
EntranceService:
46+
DependsOn:
47+
- EntranceTCP80Listener
48+
Properties:
49+
Cluster:
50+
Fn::GetAtt:
51+
- Cluster
52+
- Arn
53+
DeploymentConfiguration:
54+
MaximumPercent: 200
55+
MinimumHealthyPercent: 100
56+
DeploymentController:
57+
Type: ECS
58+
DesiredCount: 1
59+
LaunchType: FARGATE
60+
LoadBalancers:
61+
- ContainerName: entrance
62+
ContainerPort: 80
63+
TargetGroupArn:
64+
Ref: EntranceTCP80TargetGroup
65+
NetworkConfiguration:
66+
AwsvpcConfiguration:
67+
AssignPublicIp: ENABLED
68+
SecurityGroups:
69+
- Ref: DefaultNetwork
70+
Subnets:
71+
- subnet1
72+
- subnet2
73+
PlatformVersion: 1.4.0
74+
PropagateTags: SERVICE
75+
SchedulingStrategy: REPLICA
76+
ServiceRegistries:
77+
- RegistryArn:
78+
Fn::GetAtt:
79+
- EntranceServiceDiscoveryEntry
80+
- Arn
81+
Tags:
82+
- Key: com.docker.compose.project
83+
Value: TestSlightlyComplexConvert
84+
- Key: com.docker.compose.service
85+
Value: entrance
86+
TaskDefinition:
87+
Ref: EntranceTaskDefinition
88+
Type: AWS::ECS::Service
89+
EntranceServiceDiscoveryEntry:
90+
Properties:
91+
Description: '"entrance" service discovery entry in Cloud Map'
92+
DnsConfig:
93+
DnsRecords:
94+
- TTL: 60
95+
Type: A
96+
RoutingPolicy: MULTIVALUE
97+
HealthCheckCustomConfig:
98+
FailureThreshold: 1
99+
Name: entrance
100+
NamespaceId:
101+
Ref: CloudMap
102+
Type: AWS::ServiceDiscovery::Service
103+
EntranceTCP80Listener:
104+
Properties:
105+
DefaultActions:
106+
- ForwardConfig:
107+
TargetGroups:
108+
- TargetGroupArn:
109+
Ref: EntranceTCP80TargetGroup
110+
Type: forward
111+
LoadBalancerArn:
112+
Ref: LoadBalancer
113+
Port: 80
114+
Protocol: HTTP
115+
Type: AWS::ElasticLoadBalancingV2::Listener
116+
EntranceTCP80TargetGroup:
117+
Properties:
118+
Port: 80
119+
Protocol: HTTP
120+
Tags:
121+
- Key: com.docker.compose.project
122+
Value: TestSlightlyComplexConvert
123+
TargetType: ip
124+
VpcId: vpc-123
125+
Type: AWS::ElasticLoadBalancingV2::TargetGroup
126+
EntranceTaskDefinition:
127+
Properties:
128+
ContainerDefinitions:
129+
- Command:
130+
- .compute.internal
131+
- TestSlightlyComplexConvert.local
132+
Essential: false
133+
Image: docker/ecs-searchdomain-sidecar:1.0
134+
LogConfiguration:
135+
LogDriver: awslogs
136+
Options:
137+
awslogs-group:
138+
Ref: LogGroup
139+
awslogs-region:
140+
Ref: AWS::Region
141+
awslogs-stream-prefix: TestSlightlyComplexConvert
142+
Name: Entrance_ResolvConf_InitContainer
143+
- DependsOn:
144+
- Condition: SUCCESS
145+
ContainerName: Entrance_ResolvConf_InitContainer
146+
Essential: true
147+
Image: nginx
148+
LinuxParameters: {}
149+
LogConfiguration:
150+
LogDriver: awslogs
151+
Options:
152+
awslogs-group:
153+
Ref: LogGroup
154+
awslogs-region:
155+
Ref: AWS::Region
156+
awslogs-stream-prefix: TestSlightlyComplexConvert
157+
Name: entrance
158+
PortMappings:
159+
- ContainerPort: 80
160+
HostPort: 80
161+
Protocol: tcp
162+
Cpu: "256"
163+
ExecutionRoleArn:
164+
Ref: EntranceTaskExecutionRole
165+
Family: TestSlightlyComplexConvert-entrance
166+
Memory: "512"
167+
NetworkMode: awsvpc
168+
RequiresCompatibilities:
169+
- FARGATE
170+
Type: AWS::ECS::TaskDefinition
171+
EntranceTaskExecutionRole:
172+
Properties:
173+
AssumeRolePolicyDocument:
174+
Statement:
175+
- Action:
176+
- sts:AssumeRole
177+
Condition: {}
178+
Effect: Allow
179+
Principal:
180+
Service: ecs-tasks.amazonaws.com
181+
Version: 2012-10-17
182+
ManagedPolicyArns:
183+
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
184+
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
185+
Tags:
186+
- Key: com.docker.compose.project
187+
Value: TestSlightlyComplexConvert
188+
- Key: com.docker.compose.service
189+
Value: entrance
190+
Type: AWS::IAM::Role
191+
LoadBalancer:
192+
Properties:
193+
Scheme: internet-facing
194+
SecurityGroups:
195+
- Ref: DefaultNetwork
196+
Subnets:
197+
- subnet1
198+
- subnet2
199+
Tags:
200+
- Key: com.docker.compose.project
201+
Value: TestSlightlyComplexConvert
202+
Type: application
203+
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
204+
LogGroup:
205+
Properties:
206+
LogGroupName: /docker-compose/TestSlightlyComplexConvert
207+
Type: AWS::Logs::LogGroup
208+
SensitiveService:
209+
Properties:
210+
Cluster:
211+
Fn::GetAtt:
212+
- Cluster
213+
- Arn
214+
DeploymentConfiguration:
215+
MaximumPercent: 200
216+
MinimumHealthyPercent: 100
217+
DeploymentController:
218+
Type: ECS
219+
DesiredCount: 1
220+
LaunchType: FARGATE
221+
NetworkConfiguration:
222+
AwsvpcConfiguration:
223+
AssignPublicIp: DISABLED
224+
SecurityGroups:
225+
- Ref: DefaultNetwork
226+
Subnets:
227+
- subnet1
228+
- subnet2
229+
PlatformVersion: 1.4.0
230+
PropagateTags: SERVICE
231+
SchedulingStrategy: REPLICA
232+
ServiceRegistries:
233+
- RegistryArn:
234+
Fn::GetAtt:
235+
- SensitiveServiceDiscoveryEntry
236+
- Arn
237+
Tags:
238+
- Key: com.docker.compose.project
239+
Value: TestSlightlyComplexConvert
240+
- Key: com.docker.compose.service
241+
Value: sensitive
242+
TaskDefinition:
243+
Ref: SensitiveTaskDefinition
244+
Type: AWS::ECS::Service
245+
SensitiveServiceDiscoveryEntry:
246+
Properties:
247+
Description: '"sensitive" service discovery entry in Cloud Map'
248+
DnsConfig:
249+
DnsRecords:
250+
- TTL: 60
251+
Type: A
252+
RoutingPolicy: MULTIVALUE
253+
HealthCheckCustomConfig:
254+
FailureThreshold: 1
255+
Name: sensitive
256+
NamespaceId:
257+
Ref: CloudMap
258+
Type: AWS::ServiceDiscovery::Service
259+
SensitiveTaskDefinition:
260+
Properties:
261+
ContainerDefinitions:
262+
- Command:
263+
- .compute.internal
264+
- TestSlightlyComplexConvert.local
265+
Essential: false
266+
Image: docker/ecs-searchdomain-sidecar:1.0
267+
LogConfiguration:
268+
LogDriver: awslogs
269+
Options:
270+
awslogs-group:
271+
Ref: LogGroup
272+
awslogs-region:
273+
Ref: AWS::Region
274+
awslogs-stream-prefix: TestSlightlyComplexConvert
275+
Name: Sensitive_ResolvConf_InitContainer
276+
- DependsOn:
277+
- Condition: SUCCESS
278+
ContainerName: Sensitive_ResolvConf_InitContainer
279+
Essential: true
280+
Image: python
281+
LinuxParameters: {}
282+
LogConfiguration:
283+
LogDriver: awslogs
284+
Options:
285+
awslogs-group:
286+
Ref: LogGroup
287+
awslogs-region:
288+
Ref: AWS::Region
289+
awslogs-stream-prefix: TestSlightlyComplexConvert
290+
Name: sensitive
291+
Cpu: "256"
292+
ExecutionRoleArn:
293+
Ref: SensitiveTaskExecutionRole
294+
Family: TestSlightlyComplexConvert-sensitive
295+
Memory: "512"
296+
NetworkMode: awsvpc
297+
RequiresCompatibilities:
298+
- FARGATE
299+
Type: AWS::ECS::TaskDefinition
300+
SensitiveTaskExecutionRole:
301+
Properties:
302+
AssumeRolePolicyDocument:
303+
Statement:
304+
- Action:
305+
- sts:AssumeRole
306+
Condition: {}
307+
Effect: Allow
308+
Principal:
309+
Service: ecs-tasks.amazonaws.com
310+
Version: 2012-10-17
311+
ManagedPolicyArns:
312+
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
313+
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
314+
Tags:
315+
- Key: com.docker.compose.project
316+
Value: TestSlightlyComplexConvert
317+
- Key: com.docker.compose.service
318+
Value: sensitive
319+
Type: AWS::IAM::Role
320+

ecs/x.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ const (
3131
extensionManagedPolicies = "x-aws-policies"
3232
extensionAutoScaling = "x-aws-autoscaling"
3333
extensionCloudFormation = "x-aws-cloudformation"
34+
extensionAssignPublicIp = "x-aws-assign_public_ip"
3435
)

0 commit comments

Comments
 (0)