Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit042e4f1

Browse files
committed
all of it
1 parent3890c2d commit042e4f1

18 files changed

+382
-145
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package codersdkvalidator
2+
3+
import (
4+
"context"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
8+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
9+
)
10+
11+
typedisplayNameValidatorstruct {
12+
errerror
13+
}
14+
15+
funcDisplayName() validator.String {
16+
returndisplayNameValidator{}
17+
}
18+
19+
var_ validator.String=displayNameValidator{}
20+
21+
func (vdisplayNameValidator)ValidateString(ctx context.Context,req validator.StringRequest,resp*validator.StringResponse) {
22+
ifreq.ConfigValue.IsNull()||req.ConfigValue.IsUnknown() {
23+
return
24+
}
25+
26+
name:=req.ConfigValue.ValueString()
27+
ifv.err=codersdk.DisplayNameValid(name);v.err!=nil {
28+
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
29+
req.Path,
30+
v.Description(ctx),
31+
name,
32+
))
33+
}
34+
}
35+
36+
var_ validator.Describer=displayNameValidator{}
37+
38+
func (vdisplayNameValidator)Description(_ context.Context)string {
39+
ifv.err!=nil {
40+
returnv.err.Error()
41+
}
42+
return"value must be a valid display name"
43+
}
44+
45+
func (vdisplayNameValidator)MarkdownDescription(ctx context.Context)string {
46+
returnv.Description(ctx)
47+
}

‎internal/codersdkvalidator/name.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package codersdkvalidator
2+
3+
import (
4+
"context"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
8+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
9+
)
10+
11+
typenameValidatorstruct {
12+
errerror
13+
}
14+
15+
funcName() validator.String {
16+
returnnameValidator{}
17+
}
18+
19+
var_ validator.String=nameValidator{}
20+
21+
func (vnameValidator)ValidateString(ctx context.Context,req validator.StringRequest,resp*validator.StringResponse) {
22+
ifreq.ConfigValue.IsNull()||req.ConfigValue.IsUnknown() {
23+
return
24+
}
25+
26+
name:=req.ConfigValue.ValueString()
27+
ifv.err=codersdk.NameValid(name);v.err!=nil {
28+
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
29+
req.Path,
30+
v.Description(ctx),
31+
name,
32+
))
33+
}
34+
}
35+
36+
var_ validator.Describer=nameValidator{}
37+
38+
func (vnameValidator)Description(_ context.Context)string {
39+
ifv.err!=nil {
40+
returnv.err.Error()
41+
}
42+
return"value must be a valid name"
43+
}
44+
45+
func (vnameValidator)MarkdownDescription(ctx context.Context)string {
46+
returnv.Description(ctx)
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package codersdkvalidator
2+
3+
import (
4+
"context"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
8+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
9+
)
10+
11+
typetemplateVersionNameValidatorstruct {
12+
errerror
13+
}
14+
15+
funcTemplateVersionName() validator.String {
16+
returntemplateVersionNameValidator{}
17+
}
18+
19+
var_ validator.String=templateVersionNameValidator{}
20+
21+
func (vtemplateVersionNameValidator)ValidateString(ctx context.Context,req validator.StringRequest,resp*validator.StringResponse) {
22+
ifreq.ConfigValue.IsNull()||req.ConfigValue.IsUnknown() {
23+
return
24+
}
25+
26+
name:=req.ConfigValue.ValueString()
27+
ifv.err=codersdk.TemplateVersionNameValid(name);v.err!=nil {
28+
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
29+
req.Path,
30+
v.Description(ctx),
31+
name,
32+
))
33+
}
34+
}
35+
36+
var_ validator.Describer=templateVersionNameValidator{}
37+
38+
func (vtemplateVersionNameValidator)Description(_ context.Context)string {
39+
ifv.err!=nil {
40+
returnv.err.Error()
41+
}
42+
return"value must be a valid template version name"
43+
}
44+
45+
func (vtemplateVersionNameValidator)MarkdownDescription(ctx context.Context)string {
46+
returnv.Description(ctx)
47+
}

‎internal/provider/logger.gorenamed to‎internal/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageprovider
1+
packageinternal
22

33
import (
44
"context"

‎internal/provider/group_data_source.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/coder/coder/v2/codersdk"
8+
"github.com/coder/terraform-provider-coderd/internal"
89
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
910
"github.com/hashicorp/terraform-plugin-framework/datasource"
1011
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@@ -28,9 +29,9 @@ type GroupDataSource struct {
2829
// GroupDataSourceModel describes the data source data model.
2930
typeGroupDataSourceModelstruct {
3031
// ID or name and organization ID must be set
31-
IDUUID`tfsdk:"id"`
32-
Name types.String`tfsdk:"name"`
33-
OrganizationIDUUID`tfsdk:"organization_id"`
32+
IDinternal.UUID`tfsdk:"id"`
33+
Name types.String`tfsdk:"name"`
34+
OrganizationIDinternal.UUID`tfsdk:"organization_id"`
3435

3536
DisplayName types.String`tfsdk:"display_name"`
3637
AvatarURL types.String`tfsdk:"avatar_url"`
@@ -40,14 +41,14 @@ type GroupDataSourceModel struct {
4041
}
4142

4243
typeMemberstruct {
43-
IDUUID`tfsdk:"id"`
44-
Username types.String`tfsdk:"username"`
45-
Email types.String`tfsdk:"email"`
46-
CreatedAt types.Int64`tfsdk:"created_at"`
47-
LastSeenAt types.Int64`tfsdk:"last_seen_at"`
48-
Status types.String`tfsdk:"status"`
49-
LoginType types.String`tfsdk:"login_type"`
50-
ThemePreference types.String`tfsdk:"theme_preference"`
44+
IDinternal.UUID`tfsdk:"id"`
45+
Username types.String`tfsdk:"username"`
46+
Email types.String`tfsdk:"email"`
47+
CreatedAt types.Int64`tfsdk:"created_at"`
48+
LastSeenAt types.Int64`tfsdk:"last_seen_at"`
49+
Status types.String`tfsdk:"status"`
50+
LoginType types.String`tfsdk:"login_type"`
51+
ThemePreference types.String`tfsdk:"theme_preference"`
5152
}
5253

5354
func (d*GroupDataSource)Metadata(ctx context.Context,req datasource.MetadataRequest,resp*datasource.MetadataResponse) {
@@ -63,7 +64,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
6364
MarkdownDescription:"The ID of the group to retrieve. This field will be populated if a name and organization ID is supplied.",
6465
Optional:true,
6566
Computed:true,
66-
CustomType:UUIDType,
67+
CustomType:internal.UUIDType,
6768
Validators: []validator.String{
6869
stringvalidator.AtLeastOneOf(path.Expressions{
6970
path.MatchRoot("name"),
@@ -78,7 +79,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
7879
},
7980
"organization_id": schema.StringAttribute{
8081
MarkdownDescription:"The organization ID that the group belongs to. This field will be populated if an ID is supplied. Defaults to the provider default organization ID.",
81-
CustomType:UUIDType,
82+
CustomType:internal.UUIDType,
8283
Optional:true,
8384
Computed:true,
8485
},
@@ -102,7 +103,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
102103
NestedObject: schema.NestedAttributeObject{
103104
Attributes:map[string]schema.Attribute{
104105
"id": schema.StringAttribute{
105-
CustomType:UUIDType,
106+
CustomType:internal.UUIDType,
106107
Computed:true,
107108
},
108109
"username": schema.StringAttribute{
@@ -176,7 +177,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
176177
client:=d.data.Client
177178

178179
ifdata.OrganizationID.IsNull() {
179-
data.OrganizationID=UUIDValue(d.data.DefaultOrganizationID)
180+
data.OrganizationID=internal.UUIDValue(d.data.DefaultOrganizationID)
180181
}
181182

182183
var (
@@ -187,7 +188,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
187188
groupID:=data.ID.ValueUUID()
188189
group,err=client.Group(ctx,groupID)
189190
iferr!=nil {
190-
ifisNotFound(err) {
191+
ifinternal.IsNotFound(err) {
191192
resp.Diagnostics.AddWarning("Client Warning",fmt.Sprintf("Group with ID %s not found. Marking as deleted.",groupID.String()))
192193
resp.State.RemoveResource(ctx)
193194
return
@@ -196,19 +197,19 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
196197
return
197198
}
198199
data.Name=types.StringValue(group.Name)
199-
data.OrganizationID=UUIDValue(group.OrganizationID)
200+
data.OrganizationID=internal.UUIDValue(group.OrganizationID)
200201
}else {
201202
group,err=client.GroupByOrgAndName(ctx,data.OrganizationID.ValueUUID(),data.Name.ValueString())
202203
iferr!=nil {
203-
ifisNotFound(err) {
204+
ifinternal.IsNotFound(err) {
204205
resp.Diagnostics.AddWarning("Client Warning",fmt.Sprintf("Group with name %s not found in organization with ID %s. Marking as deleted.",data.Name.ValueString(),data.OrganizationID.ValueString()))
205206
resp.State.RemoveResource(ctx)
206207
return
207208
}
208209
resp.Diagnostics.AddError("Failed to get group by name and org ID",err.Error())
209210
return
210211
}
211-
data.ID=UUIDValue(group.ID)
212+
data.ID=internal.UUIDValue(group.ID)
212213
}
213214

214215
data.DisplayName=types.StringValue(group.DisplayName)
@@ -217,7 +218,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
217218
members:=make([]Member,0,len(group.Members))
218219
for_,member:=rangegroup.Members {
219220
members=append(members,Member{
220-
ID:UUIDValue(member.ID),
221+
ID:internal.UUIDValue(member.ID),
221222
Username:types.StringValue(member.Username),
222223
Email:types.StringValue(member.Email),
223224
CreatedAt:types.Int64Value(member.CreatedAt.Unix()),

‎internal/provider/group_data_source_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/coder/coder/v2/coderd/util/ptr"
1212
"github.com/coder/coder/v2/codersdk"
1313
"github.com/coder/terraform-provider-coderd/integration"
14+
"github.com/coder/terraform-provider-coderd/internal"
1415
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1516
"github.com/stretchr/testify/require"
1617
)
@@ -188,7 +189,7 @@ data "coderd_group" "test" {
188189
`
189190

190191
funcMap:= template.FuncMap{
191-
"orNull":printOrNull,
192+
"orNull":internal.PrintOrNull,
192193
}
193194

194195
buf:= strings.Builder{}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp