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

Add 'Context' as an optional parameter for EC2 'CreateFleet' #23304

Merged
merged 4 commits into from
Feb 22, 2022
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
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