Skip to content

Commit

Permalink
Batch datasource
Browse files Browse the repository at this point in the history
Co-authored-by: Drew Mullen <mullen.drew@gmail.com>
  • Loading branch information
danquack and drewmullen committed Dec 20, 2023
1 parent 0215a25 commit ad586a2
Show file tree
Hide file tree
Showing 11 changed files with 1,944 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/apprunner v1.25.5
github.com/aws/aws-sdk-go-v2/service/athena v1.37.3
github.com/aws/aws-sdk-go-v2/service/auditmanager v1.30.5
github.com/aws/aws-sdk-go-v2/service/batch v1.30.5
github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.5
github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines v1.13.5
github.com/aws/aws-sdk-go-v2/service/chimesdkvoice v1.12.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/aws/aws-sdk-go-v2/service/athena v1.37.3 h1:qNLkDi/rOaauOuh33a4MNZjyf
github.com/aws/aws-sdk-go-v2/service/athena v1.37.3/go.mod h1:MlpC6swcjh1Il80u6XoeY2BTHIZRZWvoXOfaq3rfh8I=
github.com/aws/aws-sdk-go-v2/service/auditmanager v1.30.5 h1:sV05+Tgq3hsUBe9iLeGyZy31EJ59X5twiz/Mrzcin/o=
github.com/aws/aws-sdk-go-v2/service/auditmanager v1.30.5/go.mod h1:5zHM7qND9NI5fVAHwcNwFeIG4E51Dq8tBPrtkBg9IFk=
github.com/aws/aws-sdk-go-v2/service/batch v1.30.5 h1:plf1gPkD4t7yFygClkfxYREpDnLu/tub6tJO6U31TKU=
github.com/aws/aws-sdk-go-v2/service/batch v1.30.5/go.mod h1:PueWUeJBztSAvgaTrbefYvj+kOhBbjE2nia473vk2L8=
github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.5 h1:dnIEmiCC9JWN6k7da5lLGQ7OKwfl/rJus4vFlR053UE=
github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.5/go.mod h1:BV0qlxGaHddZC0s61iQ91+bLER+H0fZBOHuD4oqB8/s=
github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines v1.13.5 h1:vKjaKyzWIr4JlAvSTgPRlX9/YyZRoquOdT7qW+LFM7g=
Expand Down
5 changes: 5 additions & 0 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions internal/service/batch/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package batch

const (
JobDefinitionStatusInactive string = "INACTIVE"
JobDefinitionStatusActive string = "ACTIVE"
)

func JobDefinitionStatus_Values() []string {
return []string{
JobDefinitionStatusInactive,
JobDefinitionStatusActive,
}
}
54 changes: 54 additions & 0 deletions internal/service/batch/findv2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package batch

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/batch"
"github.com/aws/aws-sdk-go-v2/service/batch/types"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func FindJobDefinitionV2ByARN(ctx context.Context, conn *batch.Client, arn string) (*types.JobDefinition, error) {
input := &batch.DescribeJobDefinitionsInput{
JobDefinitions: []string{arn},
}

out, err := conn.DescribeJobDefinitions(ctx, input)

if err != nil {
return nil, err
}

if out == nil || len(out.JobDefinitions) == 0 {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(out.JobDefinitions); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
}

return &out.JobDefinitions[0], nil
}

func ListJobDefinitionsV2ByNameWithStatus(ctx context.Context, conn *batch.Client, input *batch.DescribeJobDefinitionsInput) ([]types.JobDefinition, error) {
var out []types.JobDefinition

pages := batch.NewDescribeJobDefinitionsPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return nil, err
}
out = append(out, page.JobDefinitions...)
}

if out == nil || len(out) == 0 {

Check failure on line 49 in internal/service/batch/findv2.go

View workflow job for this annotation

GitHub Actions / 2 of 2

S1009: should omit nil check; len() for []github.com/aws/aws-sdk-go-v2/service/batch/types.JobDefinition is defined as zero (gosimple)
return nil, tfresource.NewEmptyResultError(input)
}

return out, nil
}
Loading

0 comments on commit ad586a2

Please sign in to comment.