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 Fargate support to Batch compute environments #16819

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a49c404
Add FARGATE and FARGATE_SPOT types
gmazelier Dec 17, 2020
aa363ff
instance_type is now optional
gmazelier Dec 17, 2020
015d97e
instance_role is now optional
gmazelier Dec 17, 2020
17538b1
min_vcpus is now optional
gmazelier Dec 17, 2020
b8191ed
Ensure optional values are really undefined
gmazelier Dec 17, 2020
4890c7b
Create FARGATE environment test
gmazelier Dec 17, 2020
5a538fa
Create FARGATE_SPOT environment test
gmazelier Dec 17, 2020
e4bdcc0
Fix warnings
gmazelier Dec 17, 2020
ee6312c
Update documentation
gmazelier Dec 17, 2020
d079373
Set min_vcpus to 0 if not defined for EC2 or SPOT
gmazelier Dec 18, 2020
06a55d7
Add test case switch from EC2 to Fargate type
gmazelier Mar 12, 2021
ab04c52
Update min_vcpus only if the expected type matches
gmazelier Mar 12, 2021
02bb788
Add CHANGELOG entry.
ewbankkit Apr 20, 2021
c348531
r/aws_batch_compute_environment: Add and use internal waiter package.
ewbankkit Apr 20, 2021
0dfcdc9
r/aws_batch_compute_environment: Use internal finder package in resou…
ewbankkit Apr 20, 2021
643b920
r/aws_batch_compute_environment: Use internal naming package.
ewbankkit Apr 20, 2021
f4696b5
Fix terrafmt errors.
ewbankkit Apr 20, 2021
2b3a037
r/aws_batch_compute_environment: Add name generation tests.
ewbankkit Apr 21, 2021
d1e7bf7
r/aws_batch_compute_environment: Add 'TestAccAWSBatchComputeEnvironme…
ewbankkit Apr 21, 2021
a6fdab9
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
50086ba
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
6fee2eb
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
88967c1
r/aws_batch_compute_environment: Add 'TestAccAWSBatchComputeEnvironme…
ewbankkit Apr 21, 2021
fc394ac
r/aws_batch_compute_environment: Add 'TestAccAWSBatchComputeEnvironme…
ewbankkit Apr 21, 2021
4efb3b2
r/aws_batch_compute_environment: Rename 'TestAccAWSBatchComputeEnviro…
ewbankkit Apr 21, 2021
56a2351
Remove 'TestAccAWSBatchComputeEnvironment_ComputeResources_DesiredVcp…
ewbankkit Apr 21, 2021
102a1de
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
5725b2d
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
4e3ea24
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
a880e91
r/aws_batch_compute_environment: Check all attributes in 'TestAccAWSB…
ewbankkit Apr 21, 2021
200f312
Fix terrafmt errors.
ewbankkit Apr 21, 2021
e154ba1
Finder tweak.
ewbankkit Apr 22, 2021
0fa2c89
r/aws_batch_compute_environment: Mark 'compute_resources' as 'ForceNew'.
ewbankkit Apr 22, 2021
7a3b1a6
r/aws_batch_compute_environment: Simplify flatten and expand.
ewbankkit Apr 22, 2021
2e66c98
r/aws_batch_compute_environment: Security Group IDs and Subnets can b…
ewbankkit Apr 22, 2021
88bfc1a
Fix terrafmt errors.
ewbankkit Apr 22, 2021
f91de7c
CHANGELOG additions.
ewbankkit Apr 22, 2021
bd79808
r/aws_batch_compute_environment: Correctly handle disabling an INVALI…
ewbankkit Apr 22, 2021
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
11 changes: 11 additions & 0 deletions .changelog/16819.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_batch_compute_environment: Additional supported value `FARGATE` and `FARGATE_SPOT` for the `type` argument in the `compute_resources` configuration block
```

```release-note:enhancement
resource/aws_batch_compute_environment: The `instance_role`, `instance_type` and `min_vcpus` arguments in the `compute_resources` configuration block are now optional
```

```release-note:enhancement
resource/aws_batch_compute_environment: The `security_group_ids` and `subnets` arguments in the `compute_resources` configuration block can now be updated in-place for Fargate compute resources
```
62 changes: 54 additions & 8 deletions aws/internal/service/batch/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,56 @@ import (
tfbatch "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/batch"
)

func JobDefinitionByARN(conn *batch.Batch, arn string) (*batch.JobDefinition, error) {
input := &batch.DescribeJobDefinitionsInput{
JobDefinitions: aws.StringSlice([]string{arn}),
func ComputeEnvironmentDetailByName(conn *batch.Batch, name string) (*batch.ComputeEnvironmentDetail, error) {
input := &batch.DescribeComputeEnvironmentsInput{
ComputeEnvironments: aws.StringSlice([]string{name}),
}

computeEnvironmentDetail, err := ComputeEnvironmentDetail(conn, input)

if err != nil {
return nil, err
}

return JobDefinition(conn, input)
if status := aws.StringValue(computeEnvironmentDetail.Status); status == batch.CEStatusDeleted {
return nil, &resource.NotFoundError{
Message: status,
LastRequest: input,
}
}

return computeEnvironmentDetail, nil
}

func JobDefinition(conn *batch.Batch, input *batch.DescribeJobDefinitionsInput) (*batch.JobDefinition, error) {
output, err := conn.DescribeJobDefinitions(input)
func ComputeEnvironmentDetail(conn *batch.Batch, input *batch.DescribeComputeEnvironmentsInput) (*batch.ComputeEnvironmentDetail, error) {
output, err := conn.DescribeComputeEnvironments(input)

if err != nil {
return nil, err
}

if output == nil || len(output.JobDefinitions) == 0 || output.JobDefinitions[0] == nil {
if output == nil || len(output.ComputeEnvironments) == 0 || output.ComputeEnvironments[0] == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

jobDefinition := output.JobDefinitions[0]
// TODO if len(output.ComputeEnvironments) > 1

return output.ComputeEnvironments[0], nil
}

func JobDefinitionByARN(conn *batch.Batch, arn string) (*batch.JobDefinition, error) {
input := &batch.DescribeJobDefinitionsInput{
JobDefinitions: aws.StringSlice([]string{arn}),
}

jobDefinition, err := JobDefinition(conn, input)

if err != nil {
return nil, err
}

if status := aws.StringValue(jobDefinition.Status); status == tfbatch.JobDefinitionStatusInactive {
return nil, &resource.NotFoundError{
Expand All @@ -40,3 +67,22 @@ func JobDefinition(conn *batch.Batch, input *batch.DescribeJobDefinitionsInput)

return jobDefinition, nil
}

func JobDefinition(conn *batch.Batch, input *batch.DescribeJobDefinitionsInput) (*batch.JobDefinition, error) {
output, err := conn.DescribeJobDefinitions(input)

if err != nil {
return nil, err
}

if output == nil || len(output.JobDefinitions) == 0 || output.JobDefinitions[0] == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

// TODO if len(output.JobDefinitions) > 1

return output.JobDefinitions[0], nil
}
25 changes: 25 additions & 0 deletions aws/internal/service/batch/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/batch"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/batch/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func ComputeEnvironmentStatus(conn *batch.Batch, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
computeEnvironmentDetail, err := finder.ComputeEnvironmentDetailByName(conn, name)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return computeEnvironmentDetail, aws.StringValue(computeEnvironmentDetail.Status), nil
}
}
76 changes: 76 additions & 0 deletions aws/internal/service/batch/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/batch"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func ComputeEnvironmentCreated(conn *batch.Batch, name string, timeout time.Duration) (*batch.ComputeEnvironmentDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{batch.CEStatusCreating},
Target: []string{batch.CEStatusValid},
Refresh: ComputeEnvironmentStatus(conn, name),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
}

return nil, err
}

func ComputeEnvironmentDeleted(conn *batch.Batch, name string, timeout time.Duration) (*batch.ComputeEnvironmentDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{batch.CEStatusDeleting},
Target: []string{},
Refresh: ComputeEnvironmentStatus(conn, name),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
}

return nil, err
}

func ComputeEnvironmentDisabled(conn *batch.Batch, name string, timeout time.Duration) (*batch.ComputeEnvironmentDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{batch.CEStatusUpdating},
Target: []string{batch.CEStatusValid, batch.CEStatusInvalid},
Refresh: ComputeEnvironmentStatus(conn, name),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
}

return nil, err
}

func ComputeEnvironmentUpdated(conn *batch.Batch, name string, timeout time.Duration) (*batch.ComputeEnvironmentDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{batch.CEStatusUpdating},
Target: []string{batch.CEStatusValid},
Refresh: ComputeEnvironmentStatus(conn, name),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
}

return nil, err
}
Loading