@@ -15,6 +15,9 @@ import (
1515 "github.com/aws/aws-sdk-go-v2/service/batch"
1616 awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types"
1717 "github.com/hashicorp/go-cty/cty"
18+ "github.com/hashicorp/terraform-plugin-framework/list"
19+ listschema "github.com/hashicorp/terraform-plugin-framework/list/schema"
20+ "github.com/hashicorp/terraform-plugin-log/tflog"
1821 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1922 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2023 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -23,12 +26,16 @@ import (
2326 "github.com/hashicorp/terraform-provider-aws/internal/conns"
2427 "github.com/hashicorp/terraform-provider-aws/internal/enum"
2528 "github.com/hashicorp/terraform-provider-aws/internal/errs"
29+ "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
2630 "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
2731 "github.com/hashicorp/terraform-provider-aws/internal/flex"
32+ "github.com/hashicorp/terraform-provider-aws/internal/framework"
33+ "github.com/hashicorp/terraform-provider-aws/internal/logging"
2834 "github.com/hashicorp/terraform-provider-aws/internal/provider/sdkv2/importer"
2935 "github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
3036 tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3137 "github.com/hashicorp/terraform-provider-aws/internal/tfresource"
38+ inttypes "github.com/hashicorp/terraform-provider-aws/internal/types"
3239 "github.com/hashicorp/terraform-provider-aws/names"
3340)
3441
@@ -1759,3 +1766,92 @@ func flattenEKSVolumes(apiObjects []awstypes.EksVolume) []any {
17591766
17601767 return tfList
17611768}
1769+
1770+ // @SDKListResource("aws_batch_job_definition")
1771+ func jobDefinitionResourceAsListResource () inttypes.ListResourceForSDK {
1772+ l := jobDefinitionListResource {}
1773+ l .SetResourceSchema (resourceJobDefinition ())
1774+ return & l
1775+ }
1776+
1777+ type jobDefinitionListResource struct {
1778+ framework.ResourceWithConfigure
1779+ framework.ListResourceWithSDKv2Resource
1780+ framework.ListResourceWithSDKv2Tags
1781+ }
1782+
1783+ type jobDefinitionListResourceModel struct {
1784+ framework.WithRegionModel
1785+ }
1786+
1787+ func (l * jobDefinitionListResource ) ListResourceConfigSchema (ctx context.Context , request list.ListResourceSchemaRequest , response * list.ListResourceSchemaResponse ) {
1788+ response .Schema = listschema.Schema {
1789+ Attributes : map [string ]listschema.Attribute {},
1790+ Blocks : map [string ]listschema.Block {},
1791+ }
1792+ }
1793+
1794+ func (l * jobDefinitionListResource ) List (ctx context.Context , request list.ListRequest , stream * list.ListResultsStream ) {
1795+ awsClient := l .Meta ()
1796+ conn := awsClient .BatchClient (ctx )
1797+
1798+ var query jobDefinitionListResourceModel
1799+ if request .Config .Raw .IsKnown () && ! request .Config .Raw .IsNull () {
1800+ if diags := request .Config .Get (ctx , & query ); diags .HasError () {
1801+ stream .Results = list .ListResultsStreamDiagnostics (diags )
1802+ return
1803+ }
1804+ }
1805+
1806+ var input batch.DescribeJobDefinitionsInput
1807+
1808+ tflog .Info (ctx , "Listing Batch job definitions" )
1809+
1810+ stream .Results = func (yield func (list.ListResult ) bool ) {
1811+ pages := batch .NewDescribeJobDefinitionsPaginator (conn , & input )
1812+ for pages .HasMorePages () {
1813+ page , err := pages .NextPage (ctx )
1814+ if err != nil {
1815+ result := fwdiag .NewListResultErrorDiagnostic (err )
1816+ yield (result )
1817+ return
1818+ }
1819+
1820+ for _ , jobDef := range page .JobDefinitions {
1821+ arn := aws .ToString (jobDef .JobDefinitionArn )
1822+ ctx := tflog .SetField (ctx , logging .ResourceAttributeKey (names .AttrID ), arn )
1823+
1824+ result := request .NewListResult (ctx )
1825+ rd := l .ResourceData ()
1826+ rd .SetId (arn )
1827+
1828+ tflog .Info (ctx , "Reading Batch job definition" )
1829+ diags := resourceJobDefinitionRead (ctx , rd , awsClient )
1830+ if diags .HasError () {
1831+ result = fwdiag .NewListResultErrorDiagnostic (fmt .Errorf ("reading Batch job definition %s" , arn ))
1832+ yield (result )
1833+ return
1834+ }
1835+
1836+ err = l .SetTags (ctx , awsClient , rd )
1837+ if err != nil {
1838+ result = fwdiag .NewListResultErrorDiagnostic (err )
1839+ yield (result )
1840+ return
1841+ }
1842+
1843+ result .DisplayName = aws .ToString (jobDef .JobDefinitionName )
1844+
1845+ l .SetResult (ctx , awsClient , request .IncludeResource , & result , rd )
1846+ if result .Diagnostics .HasError () {
1847+ yield (result )
1848+ return
1849+ }
1850+
1851+ if ! yield (result ) {
1852+ return
1853+ }
1854+ }
1855+ }
1856+ }
1857+ }
0 commit comments