Skip to content

Commit

Permalink
Merge pull request #23304 from gjmveloso/ec2/fleet_context
Browse files Browse the repository at this point in the history
Add 'Context' as an optional parameter for EC2 'CreateFleet'
  • Loading branch information
ewbankkit authored Feb 22, 2022
2 parents 60d9135 + c0b9afe commit d4e7d61
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/23304.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ec2_fleet: Add `context` argument
```
10 changes: 10 additions & 0 deletions internal/service/ec2/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -353,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)

Expand Down Expand Up @@ -452,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 {
Expand Down Expand Up @@ -493,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()),
Expand Down
1 change: 1 addition & 0 deletions internal/service/ec2/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ec2_fleet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit d4e7d61

Please sign in to comment.