Skip to content

Commit 726a3af

Browse files
committed
Merge branch 'merge' into issue-273
2 parents a8b88f3 + c4d570e commit 726a3af

File tree

14 files changed

+276
-19
lines changed

14 files changed

+276
-19
lines changed

common/types.go

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,50 @@ type Service struct {
147147

148148
// Database definition
149149
type Database struct {
150-
Name string `yaml:"name,omitempty" validate:"validateLeadingAlphaNumericDash"`
151-
InstanceClass string `yaml:"instanceClass,omitempty" validate:"validateInstanceType"`
152-
Engine string `yaml:"engine,omitempty" validate:"validateAlphaNumericDash"`
153-
IamAuthentication bool `yaml:"iamAuthentication,omitempty"`
154-
MasterUsername string `yaml:"masterUsername,omitempty"`
155-
AllocatedStorage string `yaml:"allocatedStorage,omitempty"`
156-
KmsKey map[string]string `yaml:"kmsKey,omitempty"`
150+
DatabaseConfig `yaml:",inline"`
151+
EnvironmentConfig map[string]DatabaseConfig `yaml:"environmentConfig"`
152+
}
153+
154+
// DatabaseConfig definition
155+
type DatabaseConfig struct {
156+
Name string `yaml:"name,omitempty" validate:"validateLeadingAlphaNumericDash"`
157+
InstanceClass string `yaml:"instanceClass,omitempty" validate:"validateInstanceType"`
158+
Engine string `yaml:"engine,omitempty" validate:"validateAlphaNumericDash"`
159+
EngineMode string `yaml:"engineMode,omitempty" validate:"validateAlphaNumericDash"`
160+
IamAuthentication string `yaml:"iamAuthentication,omitempty"`
161+
MasterUsername string `yaml:"masterUsername,omitempty"`
162+
AllocatedStorage string `yaml:"allocatedStorage,omitempty"`
163+
KmsKey string `yaml:"kmsKey,omitempty"`
164+
MinSize string `yaml:"minSize,omitempty"`
165+
MaxSize string `yaml:"maxSize,omitempty"`
166+
SecondsUntilAutoPause string `yaml:"secondsUntilAutoPause,omitempty"`
167+
}
168+
169+
// GetDatabaseConfig definition
170+
func (database *Database) GetDatabaseConfig(environmentName string) *DatabaseConfig {
171+
first := func(options ...string) string {
172+
for _, s := range options {
173+
if s != "" {
174+
return s
175+
}
176+
}
177+
return ""
178+
}
179+
envConfig := database.EnvironmentConfig[environmentName]
180+
dbConfig := &DatabaseConfig{
181+
Name: first(envConfig.Name, database.Name),
182+
InstanceClass: first(envConfig.InstanceClass, database.InstanceClass),
183+
Engine: first(envConfig.Engine, database.Engine),
184+
EngineMode: first(envConfig.EngineMode, database.EngineMode),
185+
IamAuthentication: first(envConfig.IamAuthentication, database.IamAuthentication),
186+
MasterUsername: first(envConfig.MasterUsername, database.MasterUsername),
187+
AllocatedStorage: first(envConfig.AllocatedStorage, database.AllocatedStorage),
188+
KmsKey: first(envConfig.KmsKey, database.KmsKey),
189+
MinSize: first(envConfig.MinSize, database.MinSize),
190+
MaxSize: first(envConfig.MaxSize, database.MaxSize),
191+
SecondsUntilAutoPause: first(envConfig.SecondsUntilAutoPause, database.SecondsUntilAutoPause),
192+
}
193+
return dbConfig
157194
}
158195

159196
// Schedule definition

common/types_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package common
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestDatabase_GetDatabaseConfig(t *testing.T) {
10+
assert := assert.New(t)
11+
12+
db := &Database{
13+
DatabaseConfig: DatabaseConfig{
14+
Name: "name-foo",
15+
Engine: "postgres-foo",
16+
},
17+
EnvironmentConfig: map[string]DatabaseConfig{
18+
"acceptance": DatabaseConfig{
19+
Engine: "mysql-bar",
20+
EngineMode: "serverless",
21+
},
22+
},
23+
}
24+
25+
acptConfig := db.GetDatabaseConfig("acceptance")
26+
prodConfig := db.GetDatabaseConfig("production")
27+
28+
assert.Equal("name-foo", acptConfig.Name)
29+
assert.Equal("name-foo", prodConfig.Name)
30+
31+
assert.Equal("mysql-bar", acptConfig.Engine)
32+
assert.Equal("postgres-foo", prodConfig.Engine)
33+
34+
assert.Equal("serverless", acptConfig.EngineMode)
35+
assert.Equal("", prodConfig.EngineMode)
36+
}

e2e/e2e-fargate/mu.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ service:
1111
- /*
1212
database:
1313
name: e2efgate
14-
engine: mysql
14+
engine: aurora
15+
engineMode: serverless
1516
environment:
1617
DB_HOST: ${DatabaseEndpointAddress}
1718
DB_PORT: ${DatabaseEndpointPort}

examples/database-serveless/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Examples
2+
These examples are not intended to be run directly. Rather, they serve as a reference that can be consulted when creating your own `mu.yml` files.
3+
4+
For detailed steps to create your own project, check out the [quickstart](https://github.com/stelligent/mu/wiki/Quickstart#steps).
5+

examples/database-serveless/mu.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
3+
service:
4+
name: sample-service
5+
database:
6+
name: sample
7+
engine: aurora
8+
environmentConfig:
9+
acceptance:
10+
engineMode: serverless
11+
secondsUntilAutoPause: 300

provider/aws/cloudformation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (cfnMgr *cloudformationStackManager) cleanStackIfInRollback(stack *common.S
267267
if err != nil {
268268
return nil, err
269269
}
270-
*stack = *cfnMgr.AwaitFinalStatus(stackName)
270+
stack = cfnMgr.AwaitFinalStatus(stackName)
271271
}
272272
return stack, nil
273273
}

provider/aws/roleset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (rolesetMgr *iamRolesetManager) GetEnvironmentRoleset(environmentName strin
6060
func (rolesetMgr *iamRolesetManager) GetServiceRoleset(environmentName string, serviceName string) (common.Roleset, error) {
6161
roleset := rolesetMgr.getRolesetFromStack("service", serviceName, environmentName)
6262

63-
overrideRole(roleset, "DatabaseKeyArn", rolesetMgr.context.Config.Service.Database.KmsKey[environmentName])
63+
overrideRole(roleset, "DatabaseKeyArn", rolesetMgr.context.Config.Service.Database.GetDatabaseConfig(environmentName).KmsKey)
6464
overrideRole(roleset, "EC2InstanceProfileArn", rolesetMgr.context.Config.Service.Roles.Ec2Instance)
6565
overrideRole(roleset, "CodeDeployRoleArn", rolesetMgr.context.Config.Service.Roles.CodeDeploy)
6666
overrideRole(roleset, "EcsEventsRoleArn", rolesetMgr.context.Config.Service.Roles.EcsEvents)

templates/assets/common-iam.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ Resources:
188188
- autoscaling:DescribeTags
189189
- autoscaling:DeleteTags
190190
- autoscaling:TerminateInstanceInAutoScalingGroup
191+
- ssm:CreateAssociation
192+
- ssm:DescribeAssociation
193+
- ssm:DeleteAssociation
194+
- ssm:ListAssociations
195+
- ssm:UpdateAssociationStatus
191196
#
192197
# the cloudwatch:PutRule & cloudwatch:PutTargets
193198
# are documented under http://docs.aws.amazon.com/AmazonCloudWatchEvents/latest/APIReference/API_PutRule.html

templates/assets/database.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ Parameters:
66
Type: String
77
Description: Engine for database
88
Default: aurora
9+
DatabaseEngineMode:
10+
Type: String
11+
Description: Engine mode for database
12+
Default: provisioned
13+
SecondsUntilAutoPause:
14+
Type: Number
15+
Description: Seconds before auto pause
16+
Default: 300
17+
ScalingMaxCapacity:
18+
Type: Number
19+
Description: Max number of database units
20+
Default: 256
21+
ScalingMinCapacity:
22+
Type: Number
23+
Description: Min number of database units
24+
Default: 2
925
DatabaseInstanceClass:
1026
Type: String
1127
Description: Instance class for database
@@ -38,6 +54,10 @@ Parameters:
3854
Type: String
3955
Description: KMS key for Database
4056
Conditions:
57+
IsServerless:
58+
"Fn::Equals":
59+
- !Ref DatabaseEngineMode
60+
- 'serverless'
4161
IsClustered:
4262
"Fn::Or":
4363
- "Fn::Equals":
@@ -46,9 +66,23 @@ Conditions:
4666
- "Fn::Equals":
4767
- !Ref DatabaseEngine
4868
- 'aurora'
69+
- "Fn::Equals":
70+
- !Ref DatabaseEngine
71+
- 'aurora-mysql'
4972
IsStandalone:
5073
"Fn::Not":
5174
- !Condition IsClustered
75+
IsClusterProvisioned:
76+
"Fn::And":
77+
- !Condition IsClustered
78+
- "Fn::Equals":
79+
- !Ref DatabaseEngineMode
80+
- 'provisioned'
81+
IsServerlessAutoPause:
82+
"Fn::Not":
83+
- "Fn::Equals":
84+
- !Ref SecondsUntilAutoPause
85+
- '0'
5286
Resources:
5387
DBSubnetsGroup:
5488
Type: "AWS::RDS::DBSubnetGroup"
@@ -95,8 +129,21 @@ Resources:
95129
DatabaseName: !Ref DatabaseName
96130
DBSubnetGroupName: !Ref DBSubnetsGroup
97131
Engine: !Ref DatabaseEngine
132+
EngineMode: !Ref DatabaseEngineMode
98133
KmsKeyId: !Ref DatabaseKeyArn
99134
StorageEncrypted: true
135+
ScalingConfiguration:
136+
Fn::If:
137+
- IsServerless
138+
- MaxCapacity: !Ref ScalingMaxCapacity
139+
MinCapacity: !Ref ScalingMinCapacity
140+
SecondsUntilAutoPause: !Ref SecondsUntilAutoPause
141+
AutoPause:
142+
Fn::If:
143+
- IsServerlessAutoPause
144+
- 'true'
145+
- 'false'
146+
- AWS::NoValue
100147
MasterUsername: !Ref DatabaseMasterUsername
101148
MasterUserPassword: !Ref DatabaseMasterPassword
102149
Tags:
@@ -107,7 +154,7 @@ Resources:
107154
DeletionPolicy: Snapshot
108155
DBInstanceClustered:
109156
Type: AWS::RDS::DBInstance
110-
Condition: IsClustered
157+
Condition: IsClusterProvisioned
111158
Properties:
112159
PubliclyAccessible: false
113160
DBClusterIdentifier: !Ref DBCluster

templates/assets/env-ecs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,33 @@ Resources:
214214
Namespace: AWS/ECS
215215
Statistic: Average
216216
TargetValue: !Ref TargetMemoryReservation
217+
InventoryAssociation:
218+
Condition: HasLaunchTypeEC2
219+
Type: AWS::SSM::Association
220+
Properties:
221+
AssociationName: 'Inventory-Association'
222+
Name: 'AWS-GatherSoftwareInventory'
223+
ScheduleExpression: 'rate(1 day)'
224+
Parameters:
225+
applications:
226+
- Enabled
227+
awsComponents:
228+
- Enabled
229+
customInventory:
230+
- Enabled
231+
instanceDetailedInformation:
232+
- Enabled
233+
networkConfig:
234+
- Enabled
235+
services:
236+
- Enabled
237+
windowsRoles:
238+
- Enabled
239+
windowsUpdates:
240+
- Enabled
241+
Targets:
242+
- Key: tag:aws:autoscaling:groupName
243+
Values: [!Ref EcsAutoScalingGroup]
217244
ContainerInstances:
218245
Condition: HasLaunchTypeEC2
219246
Type: AWS::AutoScaling::LaunchConfiguration
@@ -238,6 +265,11 @@ Resources:
238265
cwlogs = cwlogs
239266
[default]
240267
region = ${AWS::Region}
268+
commands:
269+
01_configure_ssm_agent:
270+
command: !Sub |
271+
#!/bin/bash
272+
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
241273
services:
242274
sysvinit:
243275
awslogs:
@@ -318,6 +350,13 @@ Resources:
318350
log_group_name = ${AWS::StackName}
319351
log_stream_name = instance/cfn-init/{instance_id}
320352
datetime_format = %Y-%m-%d %H:%M:%S
353+
354+
[ssm]
355+
file = /var/log/amazon/ssm/*
356+
log_group_name = ${AWS::StackName}
357+
log_stream_name = instance/ssm/{instance_id}
358+
datetime_format = %Y-%m-%d %H:%M:%S
359+
321360
commands:
322361
01_add_instance_to_cluster:
323362
command: !Sub |

0 commit comments

Comments
 (0)