@@ -89,14 +89,22 @@ import (
8989 "context"
9090 "fmt"
9191
92+ {{ if or .HasProject .HasTarget -}}
9293 "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
93- {{ if $requireAttr }}"github.com/hashicorp/terraform-plugin-framework/attr"{{ end }}
94+ {{ end -}}
95+ {{ if $requireAttr -}}
96+ "github.com/hashicorp/terraform-plugin-framework/attr"
97+ {{ end -}}
9498 "github.com/hashicorp/terraform-plugin-framework/datasource"
9599 "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
100+ {{ if or .HasProject .HasTarget -}}
96101 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
102+ {{ end -}}
97103 "github.com/hashicorp/terraform-plugin-framework/diag"
98104 "github.com/hashicorp/terraform-plugin-framework/types"
99- {{ if $requireBasetypes }}"github.com/hashicorp/terraform-plugin-framework/types/basetypes"{{ end }}
105+ {{ if $requireBasetypes -}}
106+ "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
107+ {{ end }}
100108
101109 "github.com/lxc/terraform-provider-incus/internal/common"
102110 "github.com/lxc/terraform-provider-incus/internal/errors"
@@ -114,7 +122,9 @@ type {{ .Name | pascalcase }}DataSourceModel struct {
114122 {{- if .HasProject }}
115123 Project types.String `tfsdk:"project"`
116124 {{- end }}
125+ {{- if .HasTarget }}
117126 Target types.String `tfsdk:"target"`
127+ {{- end }}
118128 Remote types.String `tfsdk:"remote"`
119129
120130 Description types.String `tfsdk:"description"`
@@ -182,13 +192,15 @@ func (d *{{ .Name | pascalcase }}DataSource) Schema(ctx context.Context, req dat
182192 "remote": schema.StringAttribute{
183193 Optional: true,
184194 },
195+ {{- if .HasTarget }}
185196
186197 "target": schema.StringAttribute{
187198 Optional: true,
188199 Validators: []validator.String{
189200 stringvalidator.LengthAtLeast(1),
190201 },
191202 },
203+ {{- end }}
192204
193205 "description": schema.StringAttribute{
194206 Optional: true,
@@ -304,7 +316,11 @@ func (d *{{ .Name | pascalcase }}DataSource) Read(ctx context.Context, req datas
304316 {{- else }}
305317 providerProjectName := ""
306318 {{- end }}
319+ {{- if .HasTarget }}
307320 providerTarget := state.Target.ValueString()
321+ {{- else }}
322+ providerTarget := ""
323+ {{- end }}
308324 server, err := d.provider.InstanceServer(providerRemote, providerProjectName, providerTarget)
309325 if err != nil {
310326 resp.Diagnostics.Append(errors.NewInstanceServerError(err))
0 commit comments