diff --git a/docs/resources/tests.md b/docs/resources/tests.md index cf30bdd..722ee44 100644 --- a/docs/resources/tests.md +++ b/docs/resources/tests.md @@ -25,6 +25,7 @@ description: |- - `drivers` (Attributes) The resource specific driver configuration. This is merged with the provider scoped drivers configuration. (see [below for nested schema](#nestedatt--drivers)) - `labels` (Map of String) Metadata to attach to the tests resource. Used for filtering and grouping. - `name` (String) The name of the test. If one is not provided, a random name will be generated. +- `repo` (String) The target repository the provider will use for pushing/pulling dynamically built images, overriding provider config. - `skipped` (Boolean) Whether or not the tests were skipped. This is set to true if the tests were skipped, and false otherwise. - `tests` (Attributes List) An ordered list of test suites to run (see [below for nested schema](#nestedatt--tests)) - `timeout` (String) The maximum amount of time to wait for all tests to complete. This includes the time it takes to start and destroy the driver. diff --git a/internal/provider/tests_resource.go b/internal/provider/tests_resource.go index 6f042b2..7036069 100644 --- a/internal/provider/tests_resource.go +++ b/internal/provider/tests_resource.go @@ -51,15 +51,16 @@ type TestsResource struct { } type TestsResourceModel struct { - Id types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Driver DriverResourceModel `tfsdk:"driver"` - Drivers *TestsDriversResourceModel `tfsdk:"drivers"` - Images TestsImageResource `tfsdk:"images"` - Tests []TestResourceModel `tfsdk:"tests"` - Timeout types.String `tfsdk:"timeout"` - Labels map[string]string `tfsdk:"labels"` - Skipped types.Bool `tfsdk:"skipped"` + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Driver DriverResourceModel `tfsdk:"driver"` + Drivers *TestsDriversResourceModel `tfsdk:"drivers"` + Images TestsImageResource `tfsdk:"images"` + Tests []TestResourceModel `tfsdk:"tests"` + Timeout types.String `tfsdk:"timeout"` + Labels map[string]string `tfsdk:"labels"` + Skipped types.Bool `tfsdk:"skipped"` + RepoOverride types.String `tfsdk:"repo"` } type TestsImageResource map[string]string @@ -120,6 +121,10 @@ func (t *TestsResource) Schema(ctx context.Context, req resource.SchemaRequest, Description: "The driver to use for the test suite. Only one driver can be used at a time.", Required: true, }, + "repo": schema.StringAttribute{ + Optional: true, + Description: "The target repository the provider will use for pushing/pulling dynamically built images, overriding provider config.", + }, "drivers": DriverResourceSchema(ctx), "images": schema.MapAttribute{ ElementType: types.StringType, @@ -284,7 +289,17 @@ func (t *TestsResource) do(ctx context.Context, data *TestsResourceModel) (ds di return []diag.Diagnostic{diag.NewErrorDiagnostic("invalid entrypoint image provided", "")} } - trepo, err := name.NewRepository(fmt.Sprintf("%s/%s", t.repo.String(), "imagetest")) + repo := t.repo + if data.RepoOverride.ValueString() != "" { + l.InfoContextf(ctx, "using repository override %q", data.RepoOverride.String()) + var err error + repo, err = name.NewRepository(data.RepoOverride.ValueString()) + if err != nil { + return []diag.Diagnostic{diag.NewErrorDiagnostic("failed to parse repo override", err.Error())} + } + } + + trepo, err := name.NewRepository(fmt.Sprintf("%s/%s", repo.String(), "imagetest")) if err != nil { return []diag.Diagnostic{diag.NewErrorDiagnostic("failed to create target repository", err.Error())} } @@ -369,8 +384,8 @@ func (t *TestsResource) do(ctx context.Context, data *TestsResourceModel) (ds di } envs["IMAGES"] = string(imgsResolvedData) envs["IMAGETEST_DRIVER"] = string(data.Driver) - envs["IMAGETEST_REGISTRY"] = t.repo.RegistryStr() - envs["IMAGETEST_REPO"] = t.repo.String() + envs["IMAGETEST_REGISTRY"] = trepo.RegistryStr() + envs["IMAGETEST_REPO"] = trepo.String() if os.Getenv("IMAGETEST_SKIP_TEARDOWN_ON_FAILURE") != "" || os.Getenv("IMAGETEST_SKIP_TEARDOWN") != "" { envs["IMAGETEST_PAUSE_ON_ERROR"] = "true"