diff --git a/internal/provider/structure_test_data_source.go b/internal/provider/structure_test_data_source.go index 8f47db5..6f7f3be 100644 --- a/internal/provider/structure_test_data_source.go +++ b/internal/provider/structure_test_data_source.go @@ -150,17 +150,38 @@ func (d *StructureTestDataSource) Read(ctx context.Context, req datasource.ReadR } } - img, err := desc.Image() - if err != nil { - resp.Diagnostics.AddError("Unable to load image", fmt.Sprintf("Unable to load image for ref %s, got error: %s", data.Digest.ValueString(), err)) - return - } + if desc.MediaType.IsIndex() { + index, err := desc.ImageIndex() + if err != nil { + resp.Diagnostics.AddError("Unable to read image index", fmt.Sprintf("Unable to read image index for ref %s, got error: %s", data.Digest.ValueString(), err)) + return + } - if err := conds.Check(img); err != nil { - data.TestedRef = basetypes.NewStringValue("") - data.Id = basetypes.NewStringValue("") - resp.Diagnostics.AddError("Image does not match rules", fmt.Sprintf("Image does not match rules:\n%s", err)) - return + indexManifest, err := index.IndexManifest() + if err != nil { + resp.Diagnostics.AddError("Unable to read image index manifest", fmt.Sprintf("Unable to read image index manifest for ref %s, got error: %s", data.Digest.ValueString(), err)) + return + } + + for _, mDesc := range indexManifest.Manifests { + if !mDesc.MediaType.IsImage() { + // ignore if not image + continue + } + + img, err := index.Image(mDesc.Digest) + if err != nil { + resp.Diagnostics.AddError("Unable to load image", fmt.Sprintf("Unable to load image for ref %s, got error: %s", data.Digest.ValueString(), err)) + return + } + + if err := conds.Check(img); err != nil { + data.TestedRef = basetypes.NewStringValue("") + data.Id = basetypes.NewStringValue("") + resp.Diagnostics.AddError("Image does not match rules", fmt.Sprintf("Image does not match rules:\n%s", err)) + return + } + } } data.TestedRef = data.Digest