From 39c246e1f30da43e7539f04a76fcbb33d59d4d64 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 10 Oct 2023 21:05:28 +0000 Subject: [PATCH] feat: add `coder_file` resource --- docs/resources/file.md | 30 ++++++++++++++++++++++++++ provider/file.go | 49 ++++++++++++++++++++++++++++++++++++++++++ provider/provider.go | 1 + 3 files changed, 80 insertions(+) create mode 100644 docs/resources/file.md create mode 100644 provider/file.go diff --git a/docs/resources/file.md b/docs/resources/file.md new file mode 100644 index 00000000..5644bb8d --- /dev/null +++ b/docs/resources/file.md @@ -0,0 +1,30 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "coder_file Resource - terraform-provider-coder" +subcategory: "" +description: |- + Use this resource to place a file inside of a workspace. +--- + +# coder_file (Resource) + +Use this resource to place a file inside of a workspace. + + + + +## Schema + +### Required + +- `agent_id` (String) The "id" property of a "coder_agent" resource to associate with. +- `content` (String) The content of the file to place in the workspace. +- `path` (String) The path of the file to place in the workspace. + +### Optional + +- `mode` (Number) The mode of the file to place in the workspace. + +### Read-Only + +- `id` (String) The ID of this resource. diff --git a/provider/file.go b/provider/file.go new file mode 100644 index 00000000..6d8cfc93 --- /dev/null +++ b/provider/file.go @@ -0,0 +1,49 @@ +package provider + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func fileResource() *schema.Resource { + return &schema.Resource{ + Description: "Use this resource to place a file inside of a workspace.", + CreateContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { + rd.SetId(uuid.NewString()) + return nil + }, + ReadContext: schema.NoopContext, + DeleteContext: schema.NoopContext, + Schema: map[string]*schema.Schema{ + "agent_id": { + Type: schema.TypeString, + Description: `The "id" property of a "coder_agent" resource to associate with.`, + ForceNew: true, + Required: true, + }, + "path": { + Type: schema.TypeString, + Description: "The path of the file to place in the workspace.", + ForceNew: true, + Required: true, + }, + "content": { + Type: schema.TypeString, + Description: "The content of the file to place in the workspace.", + ForceNew: true, + Required: true, + }, + "mode": { + Type: schema.TypeInt, + Description: "The mode of the file to place in the workspace.", + ForceNew: true, + Optional: true, + ValidateFunc: validation.IntBetween(0, 0777), + }, + }, + } +} diff --git a/provider/provider.go b/provider/provider.go index 6556146e..3df18404 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -78,6 +78,7 @@ func New() *schema.Provider { "coder_agent": agentResource(), "coder_agent_instance": agentInstanceResource(), "coder_app": appResource(), + "coder_file": fileResource(), "coder_metadata": metadataResource(), "coder_script": scriptResource(), },