Skip to content

Commit

Permalink
arn_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
danquack committed Feb 15, 2024
1 parent 0d685d9 commit 4d38da8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/service/batch/job_definition_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package batch
import (
"context"
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/service/batch"
batchtypes "github.com/aws/aws-sdk-go-v2/service/batch/types"
Expand Down Expand Up @@ -62,6 +63,10 @@ func (d *dataSourceJobDefinition) Schema(ctx context.Context, req datasource.Sch
Optional: true,
CustomType: fwtypes.ARNType,
},
"arn_prefix": schema.StringAttribute{
Optional: true,
CustomType: fwtypes.ARNType,
},
"container_orchestration_type": schema.StringAttribute{
Computed: true,
},
Expand Down Expand Up @@ -624,8 +629,11 @@ func (d *dataSourceJobDefinition) Read(ctx context.Context, req datasource.ReadR

// These fields don't have the same name as their api
data.ARN = flex.StringToFrameworkARN(ctx, jd.JobDefinitionArn)
arnPrefix := strings.TrimSuffix(aws.StringValue(jd.JobDefinitionArn), fmt.Sprintf(":%d", aws.Int32Value(jd.Revision)))
data.ARNPrefix = flex.StringToFrameworkARN(ctx, aws.String(arnPrefix))
data.ID = flex.StringToFramework(ctx, jd.JobDefinitionArn)
data.Name = flex.StringToFramework(ctx, jd.JobDefinitionName)

data.Revision = flex.Int32ToFramework(ctx, jd.Revision)
data.Status = flex.StringToFramework(ctx, jd.Status)
data.Type = flex.StringToFramework(ctx, jd.Type)
Expand Down Expand Up @@ -1109,6 +1117,7 @@ func frameworkFlattenRetryStrategy(ctx context.Context, jd *batchtypes.RetryStra

type dataSourceJobDefinitionData struct {
ARN fwtypes.ARN `tfsdk:"arn"`
ARNPrefix fwtypes.ARN `tfsdk:"arn_prefix"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Revision types.Int64 `tfsdk:"revision"`
Expand Down
1 change: 1 addition & 0 deletions internal/service/batch/job_definition_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestAccBatchJobDefinitionDataSource_basicARN(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "revision", "1"),
resource.TestCheckResourceAttr(dataSourceName, "retry_strategy.attempts", "10"),
acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "batch", regexache.MustCompile(fmt.Sprintf(`job-definition/%s:\d+`, rName))),
acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn_prefix", "batch", regexache.MustCompile(fmt.Sprintf(`job-definition/%s`, rName))),
),
},
{
Expand Down

0 comments on commit 4d38da8

Please sign in to comment.