Skip to content

Commit a6d96a2

Browse files
committed
Add ssh access back again
1 parent 2f4b039 commit a6d96a2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

templates/aws-stack.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Metadata:
4242
- ImageIdParameter
4343
- InstanceType
4444
- AgentsPerInstance
45+
- KeyName
4546
- SpotPrice
4647
- SecretsBucket
4748
- ArtifactsBucket
@@ -91,6 +92,11 @@ Metadata:
9192
- EnableDockerLoginPlugin
9293

9394
Parameters:
95+
KeyName:
96+
Description: Optional - SSH keypair used to access the buildkite instances via ec2_user, setting this will enable SSH ingress
97+
Type: String
98+
Default: ""
99+
94100
BuildkiteAgentRelease:
95101
Type: String
96102
AllowedValues:
@@ -519,6 +525,17 @@ Conditions:
519525
UseCostAllocationTags:
520526
!Equals [ !Ref EnableCostAllocationTags, "true" ]
521527

528+
HasKeyName:
529+
!Not [ !Equals [ !Ref KeyName, "" ] ]
530+
531+
EnableSshIngress:
532+
!And
533+
- { Condition : CreateSecurityGroup }
534+
# Enable ingress if a key can be specified another way
535+
- !Or
536+
- { Condition: HasKeyName }
537+
- !Not [ !Equals [ !Ref AuthorizedUsersUrl, "" ] ]
538+
522539
# Whether or not there's any managed polices to attach
523540
HasManagedPolicies:
524541
!Or [ { Condition: UseManagedPolicyARN }, { Condition: UseECR } ]
@@ -841,6 +858,7 @@ Resources:
841858
- DeviceIndex: 0
842859
AssociatePublicIpAddress: { Ref: AssociatePublicIpAddress }
843860
Groups: !Split [ ",", !If [ "CreateSecurityGroup", !Ref SecurityGroup, !Ref SecurityGroupId ] ]
861+
KeyName: !If [ "HasKeyName", !Ref KeyName, !Ref 'AWS::NoValue' ]
844862
IamInstanceProfile:
845863
Arn: !GetAtt "IAMInstanceProfile.Arn"
846864
InstanceType: !Select [ "0", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
@@ -1084,6 +1102,16 @@ Resources:
10841102
- Key: Name
10851103
Value: !Ref 'AWS::StackName'
10861104

1105+
SecurityGroupSshIngress:
1106+
Condition: EnableSshIngress
1107+
Type: AWS::EC2::SecurityGroupIngress
1108+
Properties:
1109+
GroupId: !GetAtt SecurityGroup.GroupId
1110+
IpProtocol: tcp
1111+
FromPort: 22
1112+
ToPort: 22
1113+
CidrIp: 0.0.0.0/0
1114+
10871115
Autoscaling:
10881116
Type: AWS::Serverless::Application
10891117
Condition: HasVariableSize

0 commit comments

Comments
 (0)