From 2ceb4f74aeec4317e7cf2275d1292331778544c9 Mon Sep 17 00:00:00 2001 From: Gustavo Veloso Date: Mon, 21 Feb 2022 18:28:07 -0300 Subject: [PATCH 1/4] Add 'Context' as an optional parameter for EC2 'CreateFleet' --- internal/service/ec2/fleet.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/service/ec2/fleet.go b/internal/service/ec2/fleet.go index a06f172b289..b6d7552940a 100644 --- a/internal/service/ec2/fleet.go +++ b/internal/service/ec2/fleet.go @@ -35,6 +35,10 @@ func ResourceFleet() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "context": { + Type: schema.TypeString, + Optional: true, + }, "excess_capacity_termination_policy": { Type: schema.TypeString, Optional: true, @@ -335,6 +339,7 @@ func resourceFleetCreate(d *schema.ResourceData, meta interface{}) error { tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) input := &ec2.CreateFleetInput{ + Context: aws.String(d.Get("context").(string)), ExcessCapacityTerminationPolicy: aws.String(d.Get("excess_capacity_termination_policy").(string)), LaunchTemplateConfigs: expandEc2FleetLaunchTemplateConfigRequests(d.Get("launch_template_config").([]interface{})), OnDemandOptions: expandEc2OnDemandOptionsRequest(d.Get("on_demand_options").([]interface{})), From 17a6973c9640df607bf130e25f3a19ce0384a746 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 22 Feb 2022 08:11:12 -0500 Subject: [PATCH 2/4] Add CHANGELOG entry. --- .changelog/23304.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/23304.txt diff --git a/.changelog/23304.txt b/.changelog/23304.txt new file mode 100644 index 00000000000..ec263a910cf --- /dev/null +++ b/.changelog/23304.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_ec2_fleet: Add `context` argument +``` \ No newline at end of file From b872bf1673382db4213fc719586a1783d505ed02 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 22 Feb 2022 08:32:21 -0500 Subject: [PATCH 3/4] r/aws_ec2_fleet: Set 'context' on resource Read. --- internal/service/ec2/fleet.go | 6 +++++- internal/service/ec2/fleet_test.go | 1 + website/docs/r/ec2_fleet.html.markdown | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/service/ec2/fleet.go b/internal/service/ec2/fleet.go index b6d7552940a..edf8d8eda62 100644 --- a/internal/service/ec2/fleet.go +++ b/internal/service/ec2/fleet.go @@ -339,7 +339,6 @@ func resourceFleetCreate(d *schema.ResourceData, meta interface{}) error { tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) input := &ec2.CreateFleetInput{ - Context: aws.String(d.Get("context").(string)), ExcessCapacityTerminationPolicy: aws.String(d.Get("excess_capacity_termination_policy").(string)), LaunchTemplateConfigs: expandEc2FleetLaunchTemplateConfigRequests(d.Get("launch_template_config").([]interface{})), OnDemandOptions: expandEc2OnDemandOptionsRequest(d.Get("on_demand_options").([]interface{})), @@ -358,6 +357,10 @@ func resourceFleetCreate(d *schema.ResourceData, meta interface{}) error { } } + if v, ok := d.GetOk("context"); ok { + input.Context = aws.String(v.(string)) + } + log.Printf("[DEBUG] Creating EC2 Fleet: %s", input) output, err := conn.CreateFleet(input) @@ -457,6 +460,7 @@ func resourceFleetRead(d *schema.ResourceData, meta interface{}) error { } } + d.Set("context", fleet.Context) d.Set("excess_capacity_termination_policy", fleet.ExcessCapacityTerminationPolicy) if err := d.Set("launch_template_config", flattenEc2FleetLaunchTemplateConfigs(fleet.LaunchTemplateConfigs)); err != nil { diff --git a/internal/service/ec2/fleet_test.go b/internal/service/ec2/fleet_test.go index e0d5e29936c..5437243d1b2 100644 --- a/internal/service/ec2/fleet_test.go +++ b/internal/service/ec2/fleet_test.go @@ -33,6 +33,7 @@ func TestAccEC2Fleet_basic(t *testing.T) { Config: testAccFleetConfig_TargetCapacitySpecification_DefaultTargetCapacityType(rName, "spot"), Check: resource.ComposeTestCheckFunc( testAccCheckFleetExists(resourceName, &fleet1), + resource.TestCheckResourceAttr(resourceName, "context", ""), resource.TestCheckResourceAttr(resourceName, "excess_capacity_termination_policy", "termination"), resource.TestCheckResourceAttr(resourceName, "launch_template_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "launch_template_config.0.launch_template_specification.#", "1"), diff --git a/website/docs/r/ec2_fleet.html.markdown b/website/docs/r/ec2_fleet.html.markdown index 57bb27920b1..c60bdebef67 100644 --- a/website/docs/r/ec2_fleet.html.markdown +++ b/website/docs/r/ec2_fleet.html.markdown @@ -34,6 +34,7 @@ The following arguments are supported: * `launch_template_config` - (Required) Nested argument containing EC2 Launch Template configurations. Defined below. * `target_capacity_specification` - (Required) Nested argument containing target capacity configurations. Defined below. +* `context` - (Optional) Reserved. * `excess_capacity_termination_policy` - (Optional) Whether running instances should be terminated if the total target capacity of the EC2 Fleet is decreased below the current size of the EC2. Valid values: `no-termination`, `termination`. Defaults to `termination`. * `on_demand_options` - (Optional) Nested argument containing On-Demand configurations. Defined below. * `replace_unhealthy_instances` - (Optional) Whether EC2 Fleet should replace unhealthy instances. Defaults to `false`. From c0b9afe72a57fca98c3ba1781b330ba2a422a888 Mon Sep 17 00:00:00 2001 From: Gustavo Veloso Date: Tue, 22 Feb 2022 15:31:27 -0300 Subject: [PATCH 4/4] Add context to ModifyFleet --- internal/service/ec2/fleet.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/ec2/fleet.go b/internal/service/ec2/fleet.go index edf8d8eda62..0ed9a084bcb 100644 --- a/internal/service/ec2/fleet.go +++ b/internal/service/ec2/fleet.go @@ -502,6 +502,7 @@ func resourceFleetUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*conns.AWSClient).EC2Conn input := &ec2.ModifyFleetInput{ + Context: aws.String(d.Get("context").(string)), ExcessCapacityTerminationPolicy: aws.String(d.Get("excess_capacity_termination_policy").(string)), LaunchTemplateConfigs: expandEc2FleetLaunchTemplateConfigRequests(d.Get("launch_template_config").([]interface{})), FleetId: aws.String(d.Id()),