Skip to content
Merged
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
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s *BackendService) Template() (string, error) {
LogConfig: convertLogging(s.manifest.Logging),
DesiredCountLambda: desiredCountLambda.String(),
Storage: storage,
Network: convertNetworkConfig(s.manifest.Network),
})
if err != nil {
return "", fmt.Errorf("parse backend service template: %w", err)
Expand Down
9 changes: 9 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/backend_svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ Outputs:
StackName: addon.StackName,
VariableOutputs: []string{"MyTable"},
},
Network: &template.NetworkOpts{
AssignPublicIP: template.DisablePublicIP,
SubnetsType: template.PrivateSubnetsPlacement,
SecurityGroups: []string{"sg-1234"},
},
}).Return(&template.Content{Buffer: bytes.NewBufferString("template")}, nil)
svc.parser = m
svc.addons = mockTemplater{
Expand Down Expand Up @@ -196,6 +201,10 @@ Outputs:
},
manifest: tc.manifest,
}
if tc.manifest != nil {
conf.manifest.Network.VPC.Placement = aws.String(manifest.PrivateSubnetPlacement)
conf.manifest.Network.VPC.SecurityGroups = []string{"sg-1234"}
}
tc.mockDependencies(t, ctrl, conf)

// WHEN
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (s *LoadBalancedWebService) Template() (string, error) {
DesiredCountLambda: desiredCountLambda.String(),
EnvControllerLambda: envControllerLambda.String(),
Storage: storage,
Network: convertNetworkConfig(s.manifest.Network),
})
if err != nil {
return "", err
Expand Down
8 changes: 8 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ Outputs:
RulePriorityLambda: "lambda",
DesiredCountLambda: "something",
EnvControllerLambda: "something",
Network: &template.NetworkOpts{
AssignPublicIP: template.EnablePublicIP,
SubnetsType: template.PublicSubnetsPlacement,
},
}).Return(&template.Content{Buffer: bytes.NewBufferString("template")}, nil)

addons := mockTemplater{err: &addon.ErrAddonsDirNotExist{}}
Expand Down Expand Up @@ -205,6 +209,10 @@ Outputs:
RulePriorityLambda: "lambda",
DesiredCountLambda: "something",
EnvControllerLambda: "something",
Network: &template.NetworkOpts{
AssignPublicIP: template.EnablePublicIP,
SubnetsType: template.PublicSubnetsPlacement,
},
}).Return(&template.Content{Buffer: bytes.NewBufferString("template")}, nil)
addons := mockTemplater{
tpl: `Resources:
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/scheduled_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (j *ScheduledJob) Template() (string, error) {
StateMachine: stateMachine,
LogConfig: convertLogging(j.manifest.Logging),
Storage: storage,
Network: convertNetworkConfig(j.manifest.Network),
})
if err != nil {
return "", fmt.Errorf("parse scheduled job template: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func TestScheduledJob_Template(t *testing.T) {
Timeout: aws.Int(5400),
Retries: aws.Int(3),
},
Network: &template.NetworkOpts{
AssignPublicIP: template.EnablePublicIP,
SubnetsType: template.PublicSubnetsPlacement,
},
})).Return(&template.Content{Buffer: bytes.NewBufferString("template")}, nil)
addons := mockTemplater{err: &addon.ErrAddonsDirNotExist{}}
j.parser = m
Expand All @@ -75,6 +79,10 @@ func TestScheduledJob_Template(t *testing.T) {
Timeout: aws.Int(5400),
Retries: aws.Int(3),
},
Network: &template.NetworkOpts{
AssignPublicIP: template.EnablePublicIP,
SubnetsType: template.PublicSubnetsPlacement,
},
})).Return(&template.Content{Buffer: bytes.NewBufferString("template")}, nil)
addons := mockTemplater{
tpl: `Resources:
Expand Down
37 changes: 25 additions & 12 deletions internal/pkg/deploy/cloudformation/stack/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func convertSidecar(s map[string]*manifest.SidecarConfig) ([]*template.SidecarOp
if err != nil {
return nil, err
}
mp, err := renderSidecarMountPoints(config.MountPoints)
mp, err := convertSidecarMountPoints(config.MountPoints)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -161,15 +161,15 @@ func convertStorageOpts(in *manifest.Storage) (*template.StorageOpts, error) {
if in == nil {
return nil, nil
}
v, err := renderVolumes(in.Volumes)
v, err := convertVolumes(in.Volumes)
if err != nil {
return nil, err
}
mp, err := renderMountPoints(in.Volumes)
mp, err := convertMountPoints(in.Volumes)
if err != nil {
return nil, err
}
perms, err := renderStoragePermissions(in.Volumes)
perms, err := convertEFSPermissions(in.Volumes)
if err != nil {
return nil, err
}
Expand All @@ -180,14 +180,14 @@ func convertStorageOpts(in *manifest.Storage) (*template.StorageOpts, error) {
}, nil
}

// renderSidecarMountPoints is used to convert from manifest to template objects.
func renderSidecarMountPoints(in []manifest.SidecarMountPoint) ([]*template.MountPoint, error) {
// convertSidecarMountPoints is used to convert from manifest to template objects.
func convertSidecarMountPoints(in []manifest.SidecarMountPoint) ([]*template.MountPoint, error) {
if len(in) == 0 {
return nil, nil
}
var output []*template.MountPoint
for _, smp := range in {
mp, err := renderMountPoint(smp.SourceVolume, smp.ContainerPath, smp.ReadOnly)
mp, err := convertMountPoint(smp.SourceVolume, smp.ContainerPath, smp.ReadOnly)
if err != nil {
return nil, err
}
Expand All @@ -196,7 +196,7 @@ func renderSidecarMountPoints(in []manifest.SidecarMountPoint) ([]*template.Moun
return output, nil
}

func renderMountPoint(sourceVolume, containerPath *string, readOnly *bool) (*template.MountPoint, error) {
func convertMountPoint(sourceVolume, containerPath *string, readOnly *bool) (*template.MountPoint, error) {
// containerPath must be specified.
if aws.StringValue(containerPath) == "" {
return nil, errNoContainerPath
Expand All @@ -221,13 +221,13 @@ func renderMountPoint(sourceVolume, containerPath *string, readOnly *bool) (*tem
}, nil
}

func renderMountPoints(input map[string]manifest.Volume) ([]*template.MountPoint, error) {
func convertMountPoints(input map[string]manifest.Volume) ([]*template.MountPoint, error) {
if len(input) == 0 {
return nil, nil
}
var output []*template.MountPoint
for name, volume := range input {
mp, err := renderMountPoint(aws.String(name), volume.ContainerPath, volume.ReadOnly)
mp, err := convertMountPoint(aws.String(name), volume.ContainerPath, volume.ReadOnly)
if err != nil {
return nil, err
}
Expand All @@ -236,7 +236,7 @@ func renderMountPoints(input map[string]manifest.Volume) ([]*template.MountPoint
return output, nil
}

func renderStoragePermissions(input map[string]manifest.Volume) ([]*template.EFSPermission, error) {
func convertEFSPermissions(input map[string]manifest.Volume) ([]*template.EFSPermission, error) {
if len(input) == 0 {
return nil, nil
}
Expand All @@ -260,7 +260,7 @@ func renderStoragePermissions(input map[string]manifest.Volume) ([]*template.EFS
return output, nil
}

func renderVolumes(input map[string]manifest.Volume) ([]*template.Volume, error) {
func convertVolumes(input map[string]manifest.Volume) ([]*template.Volume, error) {
if len(input) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -317,3 +317,16 @@ func renderVolumes(input map[string]manifest.Volume) ([]*template.Volume, error)
}
return output, nil
}

func convertNetworkConfig(network manifest.NetworkConfig) *template.NetworkOpts {
opts := &template.NetworkOpts{
AssignPublicIP: template.EnablePublicIP,
SubnetsType: template.PublicSubnetsPlacement,
SecurityGroups: network.VPC.SecurityGroups,
}
if aws.StringValue(network.VPC.Placement) != manifest.PublicSubnetPlacement {
opts.AssignPublicIP = template.DisablePublicIP
opts.SubnetsType = template.PrivateSubnetsPlacement
}
return opts
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func Test_convertSidecarMountPoints(t *testing.T) {
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
got, err := renderSidecarMountPoints(tc.inMountPoints)
got, err := convertSidecarMountPoints(tc.inMountPoints)
if tc.wantErr != "" {
require.EqualError(t, err, tc.wantErr)
} else {
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/manifest/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type BackendServiceConfig struct {
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
Sidecars map[string]*SidecarConfig `yaml:"sidecars"`
Network NetworkConfig `yaml:"network"`
}

type imageWithPortAndHealthcheck struct {
Expand Down Expand Up @@ -133,6 +134,11 @@ func newDefaultBackendService() *BackendService {
Value: aws.Int(1),
},
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
},
},
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/manifest/backend_svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func TestNewBackendSvc(t *testing.T) {
Value: aws.Int(1),
},
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP("public"),
},
},
},
},
},
Expand Down Expand Up @@ -93,6 +98,11 @@ func TestNewBackendSvc(t *testing.T) {
Value: aws.Int(1),
},
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP("public"),
},
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/manifest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ScheduledJobConfig struct {
Sidecars map[string]*SidecarConfig `yaml:"sidecars"`
On JobTriggerConfig `yaml:"on,flow"`
JobFailureHandlerConfig `yaml:",inline"`
Network NetworkConfig `yaml:"network"`
}

// JobTriggerConfig represents the configuration for the event that triggers the job.
Expand Down Expand Up @@ -78,6 +79,11 @@ func newDefaultScheduledJob() *ScheduledJob {
Value: aws.Int(1),
},
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
},
},
},
}
}
Expand Down
8 changes: 6 additions & 2 deletions internal/pkg/manifest/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const (

// Default values for HTTPHealthCheck for a load balanced web service.
const (
// LogRetentionInDays is the default log retention time in days.
LogRetentionInDays = 30
DefaultHealthCheckPath = "/"
)

Expand Down Expand Up @@ -53,6 +51,7 @@ type LoadBalancedWebServiceConfig struct {
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
Sidecars map[string]*SidecarConfig `yaml:"sidecars"`
Network NetworkConfig `yaml:"network"`
}

// HTTPHealthCheckArgs holds the configuration to determine if the load balanced web service is healthy.
Expand Down Expand Up @@ -150,6 +149,11 @@ func newDefaultLoadBalancedWebService() *LoadBalancedWebService {
Value: aws.Int(1),
},
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
},
},
},
}
}
Expand Down
Loading