2
2
AWSTemplateFormatVersion : " 2010-09-09"
3
3
Description : " Buildkite stack %v"
4
4
5
+ Transform : AWS::Serverless-2016-10-31
6
+
5
7
Metadata :
6
8
AWS::CloudFormation::Interface :
7
9
ParameterGroups :
8
10
- Label :
9
11
default : Buildkite Configuration
10
12
Parameters :
11
- - BuildkiteAgentToken
12
13
- BuildkiteAgentTokenParameterStorePath
13
14
- BuildkiteAgentTokenParameterStoreKMSKey
15
+ - BuildkiteAgentToken
14
16
- BuildkiteQueue
15
17
16
18
- Label :
@@ -104,7 +106,7 @@ Parameters:
104
106
Default : " stable"
105
107
106
108
BuildkiteAgentToken :
107
- Description : Buildkite agent registration token
109
+ Description : Buildkite agent registration token. Deprecated, use BuildkiteAgentTokenParameterStorePath instead.
108
110
Type : String
109
111
NoEcho : true
110
112
Default : " "
@@ -507,11 +509,12 @@ Conditions:
507
509
UseECR :
508
510
!Not [ !Equals [ !Ref ECRAccessPolicy, "none" ] ]
509
511
510
- UseSSMAgentToken :
512
+ UseCustomerManagedParameterPath :
511
513
!Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStorePath, "" ] ]
512
-
513
514
UseCustomerManagedKeyForParameterStore :
514
515
!Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStoreKMSKey, "" ] ]
516
+ CreateAgentTokenParameter :
517
+ !Equals [ !Ref BuildkiteAgentTokenParameterStorePath, "" ]
515
518
516
519
HasVariableSize :
517
520
!Not [ !Equals [ !Ref MaxSize, !Ref MinSize ] ]
@@ -559,28 +562,6 @@ Mappings:
559
562
poweruser : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser' }
560
563
full : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess' }
561
564
562
- LambdaBucket :
563
- us-east-1 : { Bucket: "buildkite-lambdas" }
564
- us-east-2 : { Bucket: "buildkite-lambdas-us-east-2" }
565
- us-west-1 : { Bucket: "buildkite-lambdas-us-west-1" }
566
- us-west-2 : { Bucket: "buildkite-lambdas-us-west-2" }
567
- af-south-1 : { Bucket: "buildkite-lambdas-af-south-1" }
568
- ap-east-1 : { Bucket: "buildkite-lambdas-ap-east-1" }
569
- ap-south-1 : { Bucket: "buildkite-lambdas-ap-south-1" }
570
- ap-northeast-2 : { Bucket: "buildkite-lambdas-ap-northeast-2" }
571
- ap-northeast-1 : { Bucket: "buildkite-lambdas-ap-northeast-1" }
572
- ap-southeast-2 : { Bucket: "buildkite-lambdas-ap-southeast-2" }
573
- ap-southeast-1 : { Bucket: "buildkite-lambdas-ap-southeast-1" }
574
- ca-central-1 : { Bucket: "buildkite-lambdas-ca-central-1" }
575
- eu-central-1 : { Bucket: "buildkite-lambdas-eu-central-1" }
576
- eu-west-1 : { Bucket: "buildkite-lambdas-eu-west-1" }
577
- eu-west-2 : { Bucket: "buildkite-lambdas-eu-west-2" }
578
- eu-south-1 : { Bucket: "buildkite-lambdas-eu-south-1" }
579
- eu-west-3 : { Bucket: "buildkite-lambdas-eu-west-3" }
580
- eu-north-1 : { Bucket: "buildkite-lambdas-eu-north-1" }
581
- me-south-1 : { Bucket: "buildkite-lambdas-me-south-1" }
582
- sa-east-1 : { Bucket: "buildkite-lambdas-sa-east-1" }
583
-
584
565
# Generated from Makefile via build/mappings.yml
585
566
AWSRegion2AMI : { linuxamd64: !Ref ImageId, linuxarm64: !Ref ImageId, windows: !Ref ImageId }
586
567
@@ -672,6 +653,14 @@ Resources:
672
653
SubnetId : !Ref Subnet1
673
654
RouteTableId : !Ref Routes
674
655
656
+ BuildkiteAgentTokenParameter :
657
+ Type : AWS::SSM::Parameter
658
+ Condition : CreateAgentTokenParameter
659
+ Properties :
660
+ Name : !Sub "/${AWS::StackName}/buildkite/agent-token"
661
+ Type : String
662
+ Value : !Ref BuildkiteAgentToken
663
+
675
664
# Allow ec2 instances to assume a role and be granted the IAMPolicies
676
665
IAMInstanceProfile :
677
666
Type : AWS::IAM::InstanceProfile
@@ -714,17 +703,16 @@ Resources:
714
703
- kms:Decrypt
715
704
Resource : !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${BuildkiteAgentTokenParameterStoreKMSKey}
716
705
- !Ref ' AWS::NoValue'
717
- - !If
718
- - UseSSMAgentToken
719
- - PolicyName : ReadAgentToken
720
- PolicyDocument :
721
- Version : ' 2012-10-17'
722
- Statement :
723
- - Effect : Allow
724
- Action :
725
- - ssm:GetParameter
726
- Resource : !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${BuildkiteAgentTokenParameterStorePath}
727
- - !Ref ' AWS::NoValue'
706
+ - PolicyName : ReadAgentToken
707
+ PolicyDocument :
708
+ Version : ' 2012-10-17'
709
+ Statement :
710
+ - Effect : Allow
711
+ Action : ssm:GetParameter
712
+ Resource :
713
+ !Sub
714
+ - arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${ParameterPath}
715
+ - ParameterPath : !If [ UseCustomerManagedParameterPath, !Ref BuildkiteAgentTokenParameterStorePath, !Ref BuildkiteAgentTokenParameter ]
728
716
AssumeRolePolicyDocument :
729
717
Statement :
730
718
- Effect : Allow
@@ -923,8 +911,7 @@ Resources:
923
911
$Env:BUILDKITE_STACK_VERSION="%v"
924
912
$Env:BUILDKITE_SCALE_IN_IDLE_PERIOD="${ScaleInIdlePeriod}"
925
913
$Env:BUILDKITE_SECRETS_BUCKET="${LocalSecretsBucket}"
926
- $Env:BUILDKITE_AGENT_TOKEN="${BuildkiteAgentToken}"
927
- $Env:BUILDKITE_AGENT_TOKEN_PATH="${BuildkiteAgentTokenParameterStorePath}"
914
+ $Env:BUILDKITE_AGENT_TOKEN_PATH="${AgentTokenPath}"
928
915
$Env:BUILDKITE_AGENTS_PER_INSTANCE="${AgentsPerInstance}"
929
916
$Env:BUILDKITE_AGENT_TAGS="${BuildkiteAgentTags}"
930
917
$Env:BUILDKITE_AGENT_TIMESTAMP_LINES="${BuildkiteAgentTimestampLines}"
@@ -947,6 +934,7 @@ Resources:
947
934
</powershell>
948
935
- {
949
936
LocalSecretsBucket : !If [ CreateSecretsBucket, !Ref ManagedSecretsBucket, !Ref SecretsBucket ],
937
+ AgentTokenPath : !If [ UseCustomerManagedParameterPath, !Ref BuildkiteAgentTokenParameterStorePath, !Ref BuildkiteAgentTokenParameter ],
950
938
}
951
939
- !Sub
952
940
- |
@@ -964,8 +952,7 @@ Resources:
964
952
BUILDKITE_STACK_VERSION=%v \
965
953
BUILDKITE_SCALE_IN_IDLE_PERIOD=${ScaleInIdlePeriod} \
966
954
BUILDKITE_SECRETS_BUCKET="${LocalSecretsBucket}" \
967
- BUILDKITE_AGENT_TOKEN="${BuildkiteAgentToken}" \
968
- BUILDKITE_AGENT_TOKEN_PATH="${BuildkiteAgentTokenParameterStorePath}" \
955
+ BUILDKITE_AGENT_TOKEN_PATH="${AgentTokenPath}" \
969
956
BUILDKITE_AGENTS_PER_INSTANCE="${AgentsPerInstance}" \
970
957
BUILDKITE_AGENT_TAGS="${BuildkiteAgentTags}" \
971
958
BUILDKITE_AGENT_TIMESTAMP_LINES="${BuildkiteAgentTimestampLines}" \
@@ -987,6 +974,7 @@ Resources:
987
974
--==BOUNDARY==--
988
975
- {
989
976
LocalSecretsBucket : !If [ CreateSecretsBucket, !Ref ManagedSecretsBucket, !Ref SecretsBucket ],
977
+ AgentTokenPath : !If [ UseCustomerManagedParameterPath, !Ref BuildkiteAgentTokenParameterStorePath, !Ref BuildkiteAgentTokenParameter ],
990
978
}
991
979
992
980
AgentAutoScaleGroup :
@@ -1114,117 +1102,19 @@ Resources:
1114
1102
ToPort : 22
1115
1103
CidrIp : 0.0.0.0/0
1116
1104
1117
- AutoscalingLambdaExecutionRole :
1118
- Type : AWS::IAM::Role
1119
- Condition : HasVariableSize
1120
- Properties :
1121
- PermissionsBoundary : !If [ SetInstanceRolePermissionsBoundaryARN, !Ref InstanceRolePermissionsBoundaryARN, !Ref "AWS::NoValue" ]
1122
- Path : " /"
1123
- AssumeRolePolicyDocument :
1124
- Version : ' 2012-10-17'
1125
- Statement :
1126
- - Effect : Allow
1127
- Principal :
1128
- Service :
1129
- - lambda.amazonaws.com
1130
- Action :
1131
- - sts:AssumeRole
1132
- ManagedPolicyArns :
1133
- - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
1134
- Policies :
1135
- - PolicyName : AutoScalingGroups
1136
- PolicyDocument :
1137
- Version : ' 2012-10-17'
1138
- Statement :
1139
- - Effect : Allow
1140
- Action :
1141
- - autoscaling:DescribeAutoScalingGroups
1142
- - autoscaling:SetDesiredCapacity
1143
- Resource : ' *'
1144
- - PolicyName : WriteCloudwatchMetrics
1145
- PolicyDocument :
1146
- Version : ' 2012-10-17'
1147
- Statement :
1148
- - Effect : Allow
1149
- Action :
1150
- - cloudwatch:PutMetricData
1151
- Resource : ' *'
1152
- - !If
1153
- - UseCustomerManagedKeyForParameterStore
1154
- - PolicyName : DecryptAgentToken
1155
- PolicyDocument :
1156
- Version : ' 2012-10-17'
1157
- Statement :
1158
- - Effect : Allow
1159
- Action :
1160
- - kms:Decrypt
1161
- Resource : !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${BuildkiteAgentTokenParameterStoreKMSKey}
1162
- - !Ref ' AWS::NoValue'
1163
- - !If
1164
- - UseSSMAgentToken
1165
- - PolicyName : ReadAgentToken
1166
- PolicyDocument :
1167
- Version : ' 2012-10-17'
1168
- Statement :
1169
- - Effect : Allow
1170
- Action :
1171
- - ssm:GetParameter
1172
- Resource : !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${BuildkiteAgentTokenParameterStorePath}
1173
- - !Ref ' AWS::NoValue'
1174
-
1175
- # This mirrors the group that would be created by the lambda, but enforces
1176
- # a retention period and also ensures it's removed when the stack is removed
1177
- AutoscalingLogGroup :
1178
- Type : " AWS::Logs::LogGroup"
1179
- Condition : HasVariableSize
1180
- Properties :
1181
- LogGroupName : !Join ["/", ["/aws/lambda", !Ref AutoscalingFunction]]
1182
- RetentionInDays : 1
1183
-
1184
- AutoscalingFunction :
1185
- Type : AWS::Lambda::Function
1105
+ Autoscaling :
1106
+ Type : AWS::Serverless::Application
1186
1107
Condition : HasVariableSize
1187
1108
Properties :
1188
- Code :
1189
- S3Bucket : { 'Fn::FindInMap': [LambdaBucket, !Ref 'AWS::Region', 'Bucket'] }
1190
- S3Key : " buildkite-agent-scaler/v1.1.1/handler.zip"
1191
- Role : !GetAtt AutoscalingLambdaExecutionRole.Arn
1192
- Timeout : 120
1193
- Handler : handler
1194
- Runtime : go1.x
1195
- MemorySize : 128
1196
- Environment :
1197
- Variables :
1198
- BUILDKITE_AGENT_TOKEN : !If [ UseSSMAgentToken, !Ref 'AWS::NoValue', !Ref BuildkiteAgentToken ]
1199
- BUILDKITE_AGENT_TOKEN_SSM_KEY : !Ref BuildkiteAgentTokenParameterStorePath
1200
- BUILDKITE_QUEUE : !Ref BuildkiteQueue
1201
- AGENTS_PER_INSTANCE : !Ref AgentsPerInstance
1202
- CLOUDWATCH_METRICS : " 1"
1203
- DISABLE_SCALE_IN : " 1"
1204
- ASG_NAME : !Ref AgentAutoScaleGroup
1205
- MIN_SIZE : !Ref MinSize
1206
- MAX_SIZE : !Ref MaxSize
1207
- SCALE_OUT_FACTOR : !Ref ScaleOutFactor
1208
- INCLUDE_WAITING : !Ref ScaleOutForWaitingJobs
1209
- LAMBDA_TIMEOUT : " 50s"
1210
- LAMBDA_INTERVAL : " 10s"
1211
-
1212
- AutoscalingLambdaScheduledRule :
1213
- Type : " AWS::Events::Rule"
1214
- Condition : HasVariableSize
1215
- Properties :
1216
- Description : " ScheduledRule"
1217
- ScheduleExpression : " rate(1 minute)"
1218
- State : ENABLED
1219
- Targets :
1220
- - Arn : !GetAtt AutoscalingFunction.Arn
1221
- Id : " AutoscalingFunction"
1222
-
1223
- PermissionForEventsToInvokeAutoscalingLambda :
1224
- Type : " AWS::Lambda::Permission"
1225
- Condition : HasVariableSize
1226
- Properties :
1227
- FunctionName : !Ref AutoscalingFunction
1228
- Action : " lambda:InvokeFunction"
1229
- Principal : " events.amazonaws.com"
1230
- SourceArn : !GetAtt AutoscalingLambdaScheduledRule.Arn
1109
+ Location :
1110
+ ApplicationId : arn:aws:serverlessrepo:us-east-1:172840064832:applications/buildkite-agent-scaler
1111
+ SemanticVersion : ' 1.1.1'
1112
+ Parameters :
1113
+ BuildkiteAgentTokenParameter : !If [ UseCustomerManagedParameterPath, !Ref BuildkiteAgentTokenParameterStorePath, !Ref BuildkiteAgentTokenParameter ]
1114
+ BuildkiteQueue : !Ref BuildkiteQueue
1115
+ AgentsPerInstance : !Ref AgentsPerInstance
1116
+ MinSize : !Ref MinSize
1117
+ MaxSize : !Ref MaxSize
1118
+ AgentAutoScaleGroup : !Ref AgentAutoScaleGroup
1119
+ ScaleOutFactor : !Ref ScaleOutFactor
1120
+ ScaleOutForWaitingJobs : !Ref ScaleOutForWaitingJobs
0 commit comments