Skip to content

Commit

Permalink
fix: Convert SingleNestedBlocks to ListNestedBlocks for aws_rekogniti…
Browse files Browse the repository at this point in the history
…on_stream_processor
  • Loading branch information
acwwat committed Feb 13, 2025
1 parent d355e38 commit ed553bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .changelog/41380.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_rekognition_stream_processor: Fix `regions_of_interest.*.bounding_box` and `regions_of_interest.*.polygon` argument validation
```
78 changes: 35 additions & 43 deletions internal/service/rekognition/stream_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,45 +215,42 @@ func (r *resourceStreamProcessor) Schema(ctx context.Context, req resource.Schem
objectvalidator.AtLeastOneOf(path.MatchRelative().AtName("bounding_box"), path.MatchRelative().AtName("polygon")),
},
Blocks: map[string]schema.Block{
"bounding_box": schema.SingleNestedBlock{
CustomType: fwtypes.NewObjectTypeOf[boundingBoxModel](ctx),
"bounding_box": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[boundingBoxModel](ctx),
Description: "The box representing a region of interest on screen.",
Validators: []validator.Object{
objectvalidator.AlsoRequires(
path.MatchRelative().AtName("height"),
path.MatchRelative().AtName("left"),
path.MatchRelative().AtName("top"),
path.MatchRelative().AtName("width"),
),
objectvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("polygon")),
Validators: []validator.List{
listvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("polygon")),
listvalidator.SizeBetween(1, 1),
},
Attributes: map[string]schema.Attribute{
"height": schema.Float64Attribute{
Optional: true,
Description: "Height of the bounding box as a ratio of the overall image height.",
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"height": schema.Float64Attribute{
Description: "Height of the bounding box as a ratio of the overall image height.",
Required: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
},
},
},
"left": schema.Float64Attribute{
Description: "Left coordinate of the bounding box as a ratio of overall image width.",
Optional: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
"left": schema.Float64Attribute{
Description: "Left coordinate of the bounding box as a ratio of overall image width.",
Required: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
},
},
},
"top": schema.Float64Attribute{
Description: "Top coordinate of the bounding box as a ratio of overall image height.",
Optional: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
"top": schema.Float64Attribute{
Description: "Top coordinate of the bounding box as a ratio of overall image height.",
Required: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
},
},
},
"width": schema.Float64Attribute{
Description: "Width of the bounding box as a ratio of the overall image width.",
Optional: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
"width": schema.Float64Attribute{
Description: "Width of the bounding box as a ratio of the overall image width.",
Required: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
},
},
},
},
Expand All @@ -267,22 +264,17 @@ func (r *resourceStreamProcessor) Schema(ctx context.Context, req resource.Schem
},
NestedObject: schema.NestedBlockObject{
CustomType: fwtypes.NewObjectTypeOf[polygonModel](ctx),
Validators: []validator.Object{
objectvalidator.AlsoRequires(
path.MatchRelative().AtName("x"),
path.MatchRelative().AtName("y"),
)},
Attributes: map[string]schema.Attribute{
"x": schema.Float64Attribute{
Description: "The value of the X coordinate for a point on a Polygon.",
Optional: true,
Required: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
},
},
"y": schema.Float64Attribute{
Description: "The value of the Y coordinate for a point on a Polygon.",
Optional: true,
Required: true,
Validators: []validator.Float64{
float64validator.Between(0.0, 1.0),
},
Expand Down Expand Up @@ -875,8 +867,8 @@ type s3DestinationModel struct {
}

type regionOfInterestModel struct {
BoundingBox fwtypes.ObjectValueOf[boundingBoxModel] `tfsdk:"bounding_box"`
Polygon fwtypes.ListNestedObjectValueOf[polygonModel] `tfsdk:"polygon"`
BoundingBox fwtypes.ListNestedObjectValueOf[boundingBoxModel] `tfsdk:"bounding_box"`
Polygon fwtypes.ListNestedObjectValueOf[polygonModel] `tfsdk:"polygon"`
}

type boundingBoxModel struct {
Expand Down
20 changes: 12 additions & 8 deletions internal/service/rekognition/stream_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ func TestAccRekognitionStreamProcessor_connectedHome(t *testing.T) {
testAccCheckStreamProcessorExists(ctx, resourceName, &streamprocessor),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.#", "1"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.#", "0"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.left", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.top", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.height", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.width", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.#", "1"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.left", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.top", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.height", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.width", "0.5"),
),
},
{
Expand All @@ -132,6 +133,7 @@ func TestAccRekognitionStreamProcessor_connectedHome(t *testing.T) {
testAccCheckStreamProcessorExists(ctx, resourceName, &streamprocessor2),
testAccCheckStreamProcessorNotRecreated(&streamprocessor, &streamprocessor2),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.#", "1"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.#", "0"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.#", "3"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.0.x", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.0.y", "0.5"),
Expand Down Expand Up @@ -204,10 +206,11 @@ func TestAccRekognitionStreamProcessor_faceRecognition_boundingBox(t *testing.T)
testAccCheckStreamProcessorExists(ctx, resourceName, &streamprocessor),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.#", "1"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.#", "0"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.left", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.top", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.height", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.width", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.#", "1"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.left", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.top", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.height", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.0.width", "0.5"),
),
},
},
Expand Down Expand Up @@ -236,6 +239,7 @@ func TestAccRekognitionStreamProcessor_faceRecognition_polygon(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckStreamProcessorExists(ctx, resourceName, &streamprocessor),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.#", "1"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.bounding_box.#", "0"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.#", "3"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.0.x", "0.5"),
resource.TestCheckResourceAttr(resourceName, "regions_of_interest.0.polygon.0.y", "0.5"),
Expand Down

0 comments on commit ed553bb

Please sign in to comment.