From 416c80f6ff82d03a551f501047e7c2a88fea585e Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Thu, 14 Nov 2024 18:08:12 +0000 Subject: [PATCH 1/8] starting --- internal/provider/provisioner_key_resource.go | 150 ++++++++++++++++++ .../provider/provisioner_key_resource_test.go | 74 +++++++++ 2 files changed, 224 insertions(+) create mode 100644 internal/provider/provisioner_key_resource.go create mode 100644 internal/provider/provisioner_key_resource_test.go diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go new file mode 100644 index 0000000..d4a621a --- /dev/null +++ b/internal/provider/provisioner_key_resource.go @@ -0,0 +1,150 @@ +package provider + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/coder/coder/v2/codersdk" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &ProvisionerKeyResource{} + +func NewProvisionerKeyResource() resource.Resource { + return &ProvisionerKeyResource{} +} + +// ProvisionerKeyResource defines the resource implementation. +type ProvisionerKeyResource struct { + *CoderdProviderData +} + +// ProvisionerKeyResourceModel describes the resource data model. +type ProvisionerKeyResourceModel struct { + OrganizationID UUID `tfsdk:"organization_id"` + Name types.String `tfsdk:"name"` + Tags types.Map `tfsdk:"tags"` + Key types.String `tfsdk:"key"` +} + +func (r *ProvisionerKeyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_provisioner_key" +} + +func (r *ProvisionerKeyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "A provisioner key for a Coder deployment.", + + Attributes: map[string]schema.Attribute{ + "organization_id": schema.StringAttribute{ + CustomType: UUIDType, + MarkdownDescription: "The organization that provisioners connected with this key will be connected to.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the key.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "tags": schema.MapAttribute{ + ElementType: types.StringType, + MarkdownDescription: "The tags that the provisioner will accept jobs for.", + PlanModifiers: []planmodifier.Map{ + mapplanmodifier.RequiresReplace(), + }, + }, + "key": schema.StringAttribute{ + MarkdownDescription: "A provisionerkey key for Coder.", + Computed: true, + Sensitive: true, + }, + }, + } +} + +func (r *ProvisionerKeyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + data, ok := req.ProviderData.(*CoderdProviderData) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *CoderdProviderData, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.CoderdProviderData = data +} + +func (r *ProvisionerKeyResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Read Terraform plan data into the model + var data ProvisionerKeyResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + createKeyResult, err := r.Client.CreateProvisionerKey(ctx, data.OrganizationID.ValueUUID(), codersdk.CreateProvisionerKeyRequest{ + Name: data.Name.ValueString(), + Tags: map[string]string{}, + }) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create provisioner_key, got error: %s", err)) + return + } + + data.Key = types.StringValue(createKeyResult.Key) + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ProvisionerKeyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + // Read Terraform prior state data into the model + var data ProvisionerKeyResourceModel + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + // Provisioner keys are immutable, no reading necessary. + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ProvisionerKeyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Provisioner keys are immutable, updating is always invalid. + resp.Diagnostics.Append(diag.NewErrorDiagnostic("invalid update", "terraform is attempting to update a resource which must be replaced")) +} + +func (r *ProvisionerKeyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + // Read Terraform prior state data into the model + var data ProvisionerKeyResourceModel + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + err := r.Client.DeleteProvisionerKey(ctx, data.OrganizationID.ValueUUID(), data.Name.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete provisionerkey, got error: %s", err)) + return + } +} diff --git a/internal/provider/provisioner_key_resource_test.go b/internal/provider/provisioner_key_resource_test.go new file mode 100644 index 0000000..e2d13d6 --- /dev/null +++ b/internal/provider/provisioner_key_resource_test.go @@ -0,0 +1,74 @@ +package provider + +import ( + "context" + "os" + "strings" + "testing" + "text/template" + + "github.com/coder/terraform-provider-coderd/integration" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/require" +) + +func TestAccLicenseResource(t *testing.T) { + if os.Getenv("TF_ACC") == "" { + t.Skip("Acceptance tests are disabled.") + } + ctx := context.Background() + client := integration.StartCoder(ctx, t, "license_acc", false) + + license := os.Getenv("CODER_ENTERPRISE_LICENSE") + if license == "" { + t.Skip("No license found for license resource tests, skipping") + } + + cfg1 := testAccLicenseResourceconfig{ + URL: client.URL.String(), + Token: client.SessionToken(), + License: license, + } + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: cfg1.String(t), + }, + }, + }) +} + +type testAccLicenseResourceconfig struct { + URL string + Token string + License string +} + +func (c testAccLicenseResourceconfig) String(t *testing.T) string { + t.Helper() + tpl := ` +provider coderd { + url = "{{.URL}}" + token = "{{.Token}}" +} + +resource "coderd_license" "test" { + license = "{{.License}}" +} +` + funcMap := template.FuncMap{ + "orNull": PrintOrNull, + } + + buf := strings.Builder{} + tmpl, err := template.New("licenseResource").Funcs(funcMap).Parse(tpl) + require.NoError(t, err) + + err = tmpl.Execute(&buf, c) + require.NoError(t, err) + return buf.String() +} From 2500b9cdc576b382bb8148f3b1a57e76b728b8ab Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 15 Nov 2024 01:53:28 +0000 Subject: [PATCH 2/8] bad tests but passing :^) --- internal/provider/license_resource_test.go | 6 +- internal/provider/provider.go | 1 + internal/provider/provisioner_key_resource.go | 3 + .../provider/provisioner_key_resource_test.go | 56 +++++++++++++------ 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/internal/provider/license_resource_test.go b/internal/provider/license_resource_test.go index e2d13d6..9a4abc7 100644 --- a/internal/provider/license_resource_test.go +++ b/internal/provider/license_resource_test.go @@ -24,7 +24,7 @@ func TestAccLicenseResource(t *testing.T) { t.Skip("No license found for license resource tests, skipping") } - cfg1 := testAccLicenseResourceconfig{ + cfg1 := testAccLicenseResourceConfig{ URL: client.URL.String(), Token: client.SessionToken(), License: license, @@ -42,13 +42,13 @@ func TestAccLicenseResource(t *testing.T) { }) } -type testAccLicenseResourceconfig struct { +type testAccLicenseResourceConfig struct { URL string Token string License string } -func (c testAccLicenseResourceconfig) String(t *testing.T) string { +func (c testAccLicenseResourceConfig) String(t *testing.T) string { t.Helper() tpl := ` provider coderd { diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 7b7d165..b8b9fa7 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -139,6 +139,7 @@ func (p *CoderdProvider) Resources(ctx context.Context) []func() resource.Resour NewWorkspaceProxyResource, NewLicenseResource, NewOrganizationResource, + NewProvisionerKeyResource, } } diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go index d4a621a..f3d71aa 100644 --- a/internal/provider/provisioner_key_resource.go +++ b/internal/provider/provisioner_key_resource.go @@ -47,18 +47,21 @@ func (r *ProvisionerKeyResource) Schema(ctx context.Context, req resource.Schema "organization_id": schema.StringAttribute{ CustomType: UUIDType, MarkdownDescription: "The organization that provisioners connected with this key will be connected to.", + Required: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, }, "name": schema.StringAttribute{ MarkdownDescription: "The name of the key.", + Required: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, }, "tags": schema.MapAttribute{ ElementType: types.StringType, + Optional: true, MarkdownDescription: "The tags that the provisioner will accept jobs for.", PlanModifiers: []planmodifier.Map{ mapplanmodifier.RequiresReplace(), diff --git a/internal/provider/provisioner_key_resource_test.go b/internal/provider/provisioner_key_resource_test.go index e2d13d6..2cd46d3 100644 --- a/internal/provider/provisioner_key_resource_test.go +++ b/internal/provider/provisioner_key_resource_test.go @@ -8,26 +8,38 @@ import ( "text/template" "github.com/coder/terraform-provider-coderd/integration" + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/require" ) -func TestAccLicenseResource(t *testing.T) { +func TestAccProvisionerKeyResource(t *testing.T) { if os.Getenv("TF_ACC") == "" { t.Skip("Acceptance tests are disabled.") } ctx := context.Background() - client := integration.StartCoder(ctx, t, "license_acc", false) + client := integration.StartCoder(ctx, t, "license_acc", true) + orgs, err := client.Organizations(ctx) + require.NoError(t, err) + firstOrg := orgs[0].ID license := os.Getenv("CODER_ENTERPRISE_LICENSE") if license == "" { t.Skip("No license found for license resource tests, skipping") } - cfg1 := testAccLicenseResourceconfig{ - URL: client.URL.String(), - Token: client.SessionToken(), - License: license, + cfg1 := testAccProvisionerKeyResourceConfig{ + URL: client.URL.String(), + Token: client.SessionToken(), + + OrganizationID: firstOrg, + Name: "example-provisioner-key", + } + + cfg2 := cfg1 + cfg2.Name = "different-provisioner-key" + cfg2.Tags = map[string]string{ + "wibble": "wobble", } resource.Test(t, resource.TestCase{ @@ -38,17 +50,23 @@ func TestAccLicenseResource(t *testing.T) { { Config: cfg1.String(t), }, + { + Config: cfg2.String(t), + }, }, }) } -type testAccLicenseResourceconfig struct { - URL string - Token string - License string +type testAccProvisionerKeyResourceConfig struct { + URL string + Token string + + OrganizationID uuid.UUID + Name string + Tags map[string]string } -func (c testAccLicenseResourceconfig) String(t *testing.T) string { +func (c testAccProvisionerKeyResourceConfig) String(t *testing.T) string { t.Helper() tpl := ` provider coderd { @@ -56,16 +74,20 @@ provider coderd { token = "{{.Token}}" } -resource "coderd_license" "test" { - license = "{{.License}}" +resource "coderd_provisioner_key" "test" { + organization_id = "{{.OrganizationID}}" + name = "{{.Name}}" + + tags = { + {{- range $key, $value := .Tags}} + {{$key}} = "{{$value}}" + {{- end}} + } } ` - funcMap := template.FuncMap{ - "orNull": PrintOrNull, - } buf := strings.Builder{} - tmpl, err := template.New("licenseResource").Funcs(funcMap).Parse(tpl) + tmpl, err := template.New("provisionerKeyResource").Parse(tpl) require.NoError(t, err) err = tmpl.Execute(&buf, c) From 26eab193881fb17f3ed6937950d5b760b296011c Mon Sep 17 00:00:00 2001 From: Kayla Washburn-Love Date: Fri, 15 Nov 2024 11:18:03 -0700 Subject: [PATCH 3/8] `AddError` Co-authored-by: Ethan <39577870+ethanndickson@users.noreply.github.com> --- internal/provider/provisioner_key_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go index f3d71aa..b56decd 100644 --- a/internal/provider/provisioner_key_resource.go +++ b/internal/provider/provisioner_key_resource.go @@ -134,7 +134,7 @@ func (r *ProvisionerKeyResource) Read(ctx context.Context, req resource.ReadRequ func (r *ProvisionerKeyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // Provisioner keys are immutable, updating is always invalid. - resp.Diagnostics.Append(diag.NewErrorDiagnostic("invalid update", "terraform is attempting to update a resource which must be replaced")) + resp.Diagnostics.AddError("Invalid Update", "Terraform is attempting to update a resource which must be replaced") } func (r *ProvisionerKeyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { From a139d317d667d428bca05e7ce1a9abb2a60a5861 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 15 Nov 2024 18:21:38 +0000 Subject: [PATCH 4/8] beep boop --- internal/provider/provisioner_key_resource.go | 1 - internal/provider/provisioner_key_resource_test.go | 5 ----- 2 files changed, 6 deletions(-) diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go index b56decd..6aa2f1b 100644 --- a/internal/provider/provisioner_key_resource.go +++ b/internal/provider/provisioner_key_resource.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier" diff --git a/internal/provider/provisioner_key_resource_test.go b/internal/provider/provisioner_key_resource_test.go index 2cd46d3..d88e9b8 100644 --- a/internal/provider/provisioner_key_resource_test.go +++ b/internal/provider/provisioner_key_resource_test.go @@ -23,11 +23,6 @@ func TestAccProvisionerKeyResource(t *testing.T) { require.NoError(t, err) firstOrg := orgs[0].ID - license := os.Getenv("CODER_ENTERPRISE_LICENSE") - if license == "" { - t.Skip("No license found for license resource tests, skipping") - } - cfg1 := testAccProvisionerKeyResourceConfig{ URL: client.URL.String(), Token: client.SessionToken(), From f92075623cb15cdb7239c5a9f2f566426d38de37 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 15 Nov 2024 20:09:20 +0000 Subject: [PATCH 5/8] fill tags, check for replacement --- internal/provider/provisioner_key_resource.go | 4 +- .../provider/provisioner_key_resource_test.go | 41 +++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go index 6aa2f1b..e1bccf4 100644 --- a/internal/provider/provisioner_key_resource.go +++ b/internal/provider/provisioner_key_resource.go @@ -103,9 +103,11 @@ func (r *ProvisionerKeyResource) Create(ctx context.Context, req resource.Create return } + var tags map[string]string + resp.Diagnostics.Append(data.Tags.ElementsAs(ctx, &tags, false)...) createKeyResult, err := r.Client.CreateProvisionerKey(ctx, data.OrganizationID.ValueUUID(), codersdk.CreateProvisionerKeyRequest{ Name: data.Name.ValueString(), - Tags: map[string]string{}, + Tags: tags, }) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create provisioner_key, got error: %s", err)) diff --git a/internal/provider/provisioner_key_resource_test.go b/internal/provider/provisioner_key_resource_test.go index d88e9b8..87e95ec 100644 --- a/internal/provider/provisioner_key_resource_test.go +++ b/internal/provider/provisioner_key_resource_test.go @@ -7,9 +7,11 @@ import ( "testing" "text/template" + "github.com/coder/coder/v2/coderd/util/ptr" "github.com/coder/terraform-provider-coderd/integration" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/stretchr/testify/require" ) @@ -27,15 +29,17 @@ func TestAccProvisionerKeyResource(t *testing.T) { URL: client.URL.String(), Token: client.SessionToken(), - OrganizationID: firstOrg, - Name: "example-provisioner-key", + OrganizationID: &firstOrg, + Name: ptr.Ref("example-provisioner-key"), } cfg2 := cfg1 - cfg2.Name = "different-provisioner-key" - cfg2.Tags = map[string]string{ + cfg2.Tags = ptr.Ref(map[string]string{ "wibble": "wobble", - } + }) + + cfg3 := cfg2 + cfg3.Name = ptr.Ref("different-provisioner-key") resource.Test(t, resource.TestCase{ IsUnitTest: true, @@ -47,6 +51,27 @@ func TestAccProvisionerKeyResource(t *testing.T) { }, { Config: cfg2.String(t), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace), + }, + }, + }, + { + Config: cfg2.String(t), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace), + }, + }, + }, + { + Config: cfg3.String(t), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace), + }, + }, }, }, }) @@ -56,9 +81,9 @@ type testAccProvisionerKeyResourceConfig struct { URL string Token string - OrganizationID uuid.UUID - Name string - Tags map[string]string + OrganizationID *uuid.UUID + Name *string + Tags *map[string]string } func (c testAccProvisionerKeyResourceConfig) String(t *testing.T) string { From b606af1e7839eac8db2e3d4636d79b4cdfdea83c Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 15 Nov 2024 20:55:19 +0000 Subject: [PATCH 6/8] nevermind about pointers --- .../provider/provisioner_key_resource_test.go | 32 +++++++++---------- internal/provider/template_resource_test.go | 6 ++-- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/internal/provider/provisioner_key_resource_test.go b/internal/provider/provisioner_key_resource_test.go index 87e95ec..9c89647 100644 --- a/internal/provider/provisioner_key_resource_test.go +++ b/internal/provider/provisioner_key_resource_test.go @@ -7,11 +7,13 @@ import ( "testing" "text/template" - "github.com/coder/coder/v2/coderd/util/ptr" "github.com/coder/terraform-provider-coderd/integration" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/stretchr/testify/require" ) @@ -20,7 +22,7 @@ func TestAccProvisionerKeyResource(t *testing.T) { t.Skip("Acceptance tests are disabled.") } ctx := context.Background() - client := integration.StartCoder(ctx, t, "license_acc", true) + client := integration.StartCoder(ctx, t, "provisioner_key_acc", true) orgs, err := client.Organizations(ctx) require.NoError(t, err) firstOrg := orgs[0].ID @@ -29,17 +31,17 @@ func TestAccProvisionerKeyResource(t *testing.T) { URL: client.URL.String(), Token: client.SessionToken(), - OrganizationID: &firstOrg, - Name: ptr.Ref("example-provisioner-key"), + OrganizationID: firstOrg, + Name: "example-provisioner-key", } cfg2 := cfg1 - cfg2.Tags = ptr.Ref(map[string]string{ + cfg2.Tags = map[string]string{ "wibble": "wobble", - }) + } cfg3 := cfg2 - cfg3.Name = ptr.Ref("different-provisioner-key") + cfg3.Name = "different-provisioner-key" resource.Test(t, resource.TestCase{ IsUnitTest: true, @@ -56,13 +58,8 @@ func TestAccProvisionerKeyResource(t *testing.T) { plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace), }, }, - }, - { - Config: cfg2.String(t), - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace), - }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue("coderd_provisioner_key.test", tfjsonpath.New("tags").AtMapKey("wibble"), knownvalue.StringExact("wobble")), }, }, { @@ -81,13 +78,14 @@ type testAccProvisionerKeyResourceConfig struct { URL string Token string - OrganizationID *uuid.UUID - Name *string - Tags *map[string]string + OrganizationID uuid.UUID + Name string + Tags map[string]string } func (c testAccProvisionerKeyResourceConfig) String(t *testing.T) string { t.Helper() + tpl := ` provider coderd { url = "{{.URL}}" diff --git a/internal/provider/template_resource_test.go b/internal/provider/template_resource_test.go index b9d7ae3..c844da0 100644 --- a/internal/provider/template_resource_test.go +++ b/internal/provider/template_resource_test.go @@ -424,7 +424,7 @@ func TestAccTemplateResourceEnterprise(t *testing.T) { t.Skip("Acceptance tests are disabled.") } ctx := context.Background() - client := integration.StartCoder(ctx, t, "template_acc", true) + client := integration.StartCoder(ctx, t, "template_resource_acc", true) firstUser, err := client.User(ctx, codersdk.Me) require.NoError(t, err) @@ -565,7 +565,7 @@ func TestAccTemplateResourceAGPL(t *testing.T) { t.Skip("Acceptance tests are disabled.") } ctx := context.Background() - client := integration.StartCoder(ctx, t, "template_acc", false) + client := integration.StartCoder(ctx, t, "template_resource_agpl_acc", false) firstUser, err := client.User(ctx, codersdk.Me) require.NoError(t, err) @@ -689,7 +689,7 @@ resource "coderd_template" "sample" { }` ctx := context.Background() - client := integration.StartCoder(ctx, t, "template_acc", false) + client := integration.StartCoder(ctx, t, "template_resource_variables_acc", false) cfg = fmt.Sprintf(cfg, client.URL.String(), client.SessionToken()) From adf93d55900ee61d1ba539a6a3d1e9210723669a Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 15 Nov 2024 20:56:36 +0000 Subject: [PATCH 7/8] docs --- docs/resources/provisioner_key.md | 29 +++++++++++++++++++ internal/provider/provisioner_key_resource.go | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 docs/resources/provisioner_key.md diff --git a/docs/resources/provisioner_key.md b/docs/resources/provisioner_key.md new file mode 100644 index 0000000..06e6ff9 --- /dev/null +++ b/docs/resources/provisioner_key.md @@ -0,0 +1,29 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "coderd_provisioner_key Resource - terraform-provider-coderd" +subcategory: "" +description: |- + A provisioner key for a Coder deployment. +--- + +# coderd_provisioner_key (Resource) + +A provisioner key for a Coder deployment. + + + + +## Schema + +### Required + +- `name` (String) The name of the key. +- `organization_id` (String) The organization that provisioners connected with this key will be connected to. + +### Optional + +- `tags` (Map of String) The tags that the provisioner will accept jobs for. + +### Read-Only + +- `key` (String, Sensitive) A provisionerkey key for Coder. diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go index e1bccf4..79a03fd 100644 --- a/internal/provider/provisioner_key_resource.go +++ b/internal/provider/provisioner_key_resource.go @@ -59,9 +59,9 @@ func (r *ProvisionerKeyResource) Schema(ctx context.Context, req resource.Schema }, }, "tags": schema.MapAttribute{ + MarkdownDescription: "The tags that the provisioner will accept jobs for.", ElementType: types.StringType, Optional: true, - MarkdownDescription: "The tags that the provisioner will accept jobs for.", PlanModifiers: []planmodifier.Map{ mapplanmodifier.RequiresReplace(), }, From d307dff4b844b9194afe75113389ad9df1b73dfa Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 15 Nov 2024 21:04:27 +0000 Subject: [PATCH 8/8] tweak descriptions --- docs/resources/provisioner_key.md | 4 ++-- internal/provider/provisioner_key_resource.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/resources/provisioner_key.md b/docs/resources/provisioner_key.md index 06e6ff9..d64b724 100644 --- a/docs/resources/provisioner_key.md +++ b/docs/resources/provisioner_key.md @@ -22,8 +22,8 @@ A provisioner key for a Coder deployment. ### Optional -- `tags` (Map of String) The tags that the provisioner will accept jobs for. +- `tags` (Map of String) The tags that provisioners connected with this key will accept jobs for. ### Read-Only -- `key` (String, Sensitive) A provisionerkey key for Coder. +- `key` (String, Sensitive) The acquired provisioner key diff --git a/internal/provider/provisioner_key_resource.go b/internal/provider/provisioner_key_resource.go index 79a03fd..5904df0 100644 --- a/internal/provider/provisioner_key_resource.go +++ b/internal/provider/provisioner_key_resource.go @@ -59,7 +59,7 @@ func (r *ProvisionerKeyResource) Schema(ctx context.Context, req resource.Schema }, }, "tags": schema.MapAttribute{ - MarkdownDescription: "The tags that the provisioner will accept jobs for.", + MarkdownDescription: "The tags that provisioners connected with this key will accept jobs for.", ElementType: types.StringType, Optional: true, PlanModifiers: []planmodifier.Map{ @@ -67,7 +67,7 @@ func (r *ProvisionerKeyResource) Schema(ctx context.Context, req resource.Schema }, }, "key": schema.StringAttribute{ - MarkdownDescription: "A provisionerkey key for Coder.", + MarkdownDescription: "The acquired provisioner key", Computed: true, Sensitive: true, },