Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f-aws_ecs_service: support for EBS #37019

Merged
merged 23 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4635f46
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 20, 2024
425b589
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
cb26c76
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
86ea283
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
2ae17da
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
51ea746
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
634edd0
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
b6c5fc1
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
8634e43
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
524c628
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
f6f0660
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
42e36fc
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
b202520
f-support for network_card_index
nikhil-goenka Apr 21, 2024
d749795
update test to refer to partition
nikhil-goenka Apr 21, 2024
072c837
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
d4002f1
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
f314063
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
e4ff2af
f-aws_ecs_service: support for EBS
nikhil-goenka Apr 21, 2024
f48e6e4
make: Respect PKG in semgrep-constants
YakDriver May 23, 2024
5177e75
ecs/service: Use consts
YakDriver May 23, 2024
806add0
ecs/task_def: Use consts
YakDriver May 23, 2024
307a991
docs/ecs/service: Clean up
YakDriver May 23, 2024
d29615b
ecs/service: Fix permissions for volume configuration
YakDriver May 23, 2024
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
7 changes: 7 additions & 0 deletions .changelog/37019.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_ecs_service: Add `volume_configuration` argument
```

```release-note:enhancement
resource/aws_ecs_task_definition: Add `configure_at_launch` parameter in `volume` argument
```
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ semgrep-code-quality: semgrep-validate ## [CI] Semgrep Checks / Code Quality Sca
semgrep-constants: semgrep-validate ## Fix constants with Semgrep --autofix
@echo "make: Fix constants with Semgrep --autofix"
@semgrep $(SEMGREP_ARGS) --autofix \
$(if $(filter-out $(origin PKG), undefined),--include $(PKG_NAME),) \
--config .ci/.semgrep-constants.yml \
--config .ci/.semgrep-test-constants.yml

Expand Down
132 changes: 132 additions & 0 deletions internal/service/ecs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,69 @@ func ResourceService() *schema.Resource {
Optional: true,
Default: false,
},
"volume_configuration": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrName: {
Type: schema.TypeString,
Required: true,
},
"managed_ebs_volume": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrRoleARN: {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.ValidARN,
},
names.AttrEncrypted: {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"file_system_type": {
Type: schema.TypeString,
Optional: true,
Default: ecs.TaskFilesystemTypeXfs,
ValidateFunc: validation.StringInSlice(ecs.TaskFilesystemType_Values(), false),
},
names.AttrIOPS: {
Type: schema.TypeInt,
Optional: true,
},
names.AttrKMSKeyID: {
Type: schema.TypeString,
Optional: true,
},
"size_in_gb": {
Type: schema.TypeInt,
Optional: true,
},
names.AttrSnapshotID: {
Type: schema.TypeString,
Optional: true,
},
"throughput": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.IntBetween(0, 1000),
},
names.AttrVolumeType: {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
},
},

CustomizeDiff: customdiff.Sequence(
Expand Down Expand Up @@ -625,6 +688,10 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int
input.ServiceConnectConfiguration = expandServiceConnectConfiguration(v.([]interface{}))
}

if v, ok := d.GetOk("volume_configuration"); ok && len(v.([]interface{})) > 0 {
input.VolumeConfigurations = expandVolumeConfigurations(v.([]interface{}))
}

serviceRegistries := d.Get("service_registries").([]interface{})
if len(serviceRegistries) > 0 {
srs := make([]*ecs.ServiceRegistry, 0, len(serviceRegistries))
Expand Down Expand Up @@ -956,6 +1023,10 @@ func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta int
input.ServiceConnectConfiguration = expandServiceConnectConfiguration(d.Get("service_connect_configuration").([]interface{}))
}

if d.HasChange("volume_configuration") {
input.VolumeConfigurations = expandVolumeConfigurations(d.Get("volume_configuration").([]interface{}))
}

if d.HasChange("service_registries") {
input.ServiceRegistries = expandServiceRegistries(d.Get("service_registries").([]interface{}))
}
Expand Down Expand Up @@ -1466,6 +1537,67 @@ func expandSecretOptions(sop []interface{}) []*ecs.Secret {
return out
}

func expandVolumeConfigurations(vc []interface{}) []*ecs.ServiceVolumeConfiguration {
if len(vc) == 0 {
return nil
}

vcs := make([]*ecs.ServiceVolumeConfiguration, 0)

for _, raw := range vc {
p := raw.(map[string]interface{})

config := &ecs.ServiceVolumeConfiguration{
Name: aws.String(p[names.AttrName].(string)),
}

if v, ok := p["managed_ebs_volume"].([]interface{}); ok && len(v) > 0 {
config.ManagedEBSVolume = expandManagedEBSVolume(v)
}
vcs = append(vcs, config)
}

return vcs
}

func expandManagedEBSVolume(ebs []interface{}) *ecs.ServiceManagedEBSVolumeConfiguration {
if len(ebs) == 0 {
return &ecs.ServiceManagedEBSVolumeConfiguration{}
}
raw := ebs[0].(map[string]interface{})

config := &ecs.ServiceManagedEBSVolumeConfiguration{}
if v, ok := raw[names.AttrRoleARN].(string); ok && v != "" {
config.RoleArn = aws.String(v)
}
if v, ok := raw[names.AttrEncrypted].(bool); ok {
config.Encrypted = aws.Bool(v)
}
if v, ok := raw["file_system_type"].(string); ok && v != "" {
config.FilesystemType = aws.String(v)
}
if v, ok := raw[names.AttrIOPS].(int); ok && v != 0 {
config.Iops = aws.Int64(int64(v))
}
if v, ok := raw[names.AttrKMSKeyID].(string); ok && v != "" {
config.KmsKeyId = aws.String(v)
}
if v, ok := raw["size_in_gb"].(int); ok && v != 0 {
config.SizeInGiB = aws.Int64(int64(v))
}
if v, ok := raw[names.AttrSnapshotID].(string); ok && v != "" {
config.SnapshotId = aws.String(v)
}
if v, ok := raw["throughput"].(int); ok && v != 0 {
config.Throughput = aws.Int64(int64(v))
}
if v, ok := raw[names.AttrVolumeType].(string); ok && v != "" {
config.VolumeType = aws.String(v)
}

return config
}

func expandServices(srv []interface{}) []*ecs.ServiceConnectService {
if len(srv) == 0 {
return nil
Expand Down
Loading
Loading