From 210eda9bb6442780fcf77deae6b8c9298d9a5f5d Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 24 Oct 2024 05:45:39 +0000 Subject: [PATCH] docs: add import examples --- docs/resources/group.md | 21 +++++++++++++--- docs/resources/template.md | 25 +++++++++++++++++--- docs/resources/user.md | 21 +++++++++++++--- examples/resources/coderd_group/import.sh | 11 +++++++++ examples/resources/coderd_template/import.sh | 15 ++++++++++++ examples/resources/coderd_user/import.sh | 11 +++++++++ internal/provider/group_resource.go | 3 +-- internal/provider/template_resource.go | 4 +--- internal/provider/user_resource.go | 3 +-- 9 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 examples/resources/coderd_group/import.sh create mode 100644 examples/resources/coderd_template/import.sh create mode 100644 examples/resources/coderd_user/import.sh diff --git a/docs/resources/group.md b/docs/resources/group.md index 1fca072..735881e 100644 --- a/docs/resources/group.md +++ b/docs/resources/group.md @@ -5,7 +5,6 @@ subcategory: "" description: |- A group on the Coder deployment. Creating groups requires an Enterprise license. - When importing, the ID supplied can be either a group UUID retrieved via the API or /. --- # coderd_group (Resource) @@ -14,8 +13,6 @@ A group on the Coder deployment. Creating groups requires an Enterprise license. -When importing, the ID supplied can be either a group UUID retrieved via the API or `/`. - ## Example Usage ```terraform @@ -62,3 +59,21 @@ resource "coderd_group" "group1" { ### Read-Only - `id` (String) Group ID. + +## Import + +Import is supported using the following syntax: + +```shell +# The ID supplied can be either a group UUID retrieved via the API +# or a fully qualified name: `/`. +$ terraform import coderd_group.example coder/developers +``` +Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used: + +```terraform +import { + to = coderd_group.example + id = "coder/developers" +} +``` diff --git a/docs/resources/template.md b/docs/resources/template.md index 81edc41..c0efc4b 100644 --- a/docs/resources/template.md +++ b/docs/resources/template.md @@ -5,7 +5,6 @@ subcategory: "" description: |- A Coder template. Logs from building template versions can be optionally streamed from the provisioner by setting the TF_LOG environment variable to INFO or higher. - When importing, the ID supplied can be either a template UUID retrieved via the API or /. --- # coderd_template (Resource) @@ -14,8 +13,6 @@ A Coder template. Logs from building template versions can be optionally streamed from the provisioner by setting the `TF_LOG` environment variable to `INFO` or higher. -When importing, the ID supplied can be either a template UUID retrieved via the API or `/`. - ## Example Usage ```terraform @@ -164,3 +161,25 @@ Optional: - `days_of_week` (Set of String) List of days of the week on which restarts are required. Restarts happen within the user's quiet hours (in their configured timezone). If no days are specified, restarts are not required. - `weeks` (Number) Weeks is the number of weeks between required restarts. Weeks are synced across all workspaces (and Coder deployments) using modulo math on a hardcoded epoch week of January 2nd, 2023 (the first Monday of 2023). Values of 0 or 1 indicate weekly restarts. Values of 2 indicate fortnightly restarts, etc. + +## Import + +Import is supported using the following syntax: + +```shell +# The ID supplied can be either a template UUID retrieved via the API +# or a fully qualified name: `/`. +$ terraform import coderd_template.example coder/dogfood +``` +Once imported, you'll need to manually declare in your config: +- The `versions` list, in order to specify the source directories for new versions of the template. +- (Enterprise) The `acl` attribute, in order to specify the users and groups that have access to the template. + +Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used: + +```terraform +import { + to = coderd_template.example + id = "coder/dogfood" +} +``` diff --git a/docs/resources/user.md b/docs/resources/user.md index 5fcb7eb..4f95850 100644 --- a/docs/resources/user.md +++ b/docs/resources/user.md @@ -4,15 +4,12 @@ page_title: "coderd_user Resource - terraform-provider-coderd" subcategory: "" description: |- A user on the Coder deployment. - When importing, the ID supplied can be either a user UUID or a username. --- # coderd_user (Resource) A user on the Coder deployment. -When importing, the ID supplied can be either a user UUID or a username. - ## Example Usage ```terraform @@ -65,3 +62,21 @@ resource "coderd_user" "admin" { ### Read-Only - `id` (String) User ID + +## Import + +Import is supported using the following syntax: + +```shell +# The ID supplied can be either a user UUID retrieved via the API +# or a username. +$ terraform import coderd_user.example developer +``` +Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used: + +```terraform +import { + to = coderd_user.example + id = "developer" +} +``` diff --git a/examples/resources/coderd_group/import.sh b/examples/resources/coderd_group/import.sh new file mode 100644 index 0000000..a49cac3 --- /dev/null +++ b/examples/resources/coderd_group/import.sh @@ -0,0 +1,11 @@ +# The ID supplied can be either a group UUID retrieved via the API +# or a fully qualified name: `/`. +$ terraform import coderd_group.example coder/developers +``` +Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used: + +```terraform +import { + to = coderd_group.example + id = "coder/developers" +} diff --git a/examples/resources/coderd_template/import.sh b/examples/resources/coderd_template/import.sh new file mode 100644 index 0000000..91892f6 --- /dev/null +++ b/examples/resources/coderd_template/import.sh @@ -0,0 +1,15 @@ +# The ID supplied can be either a template UUID retrieved via the API +# or a fully qualified name: `/`. +$ terraform import coderd_template.example coder/dogfood +``` +Once imported, you'll need to manually declare in your config: +- The `versions` list, in order to specify the source directories for new versions of the template. +- (Enterprise) The `acl` attribute, in order to specify the users and groups that have access to the template. + +Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used: + +```terraform +import { + to = coderd_template.example + id = "coder/dogfood" +} diff --git a/examples/resources/coderd_user/import.sh b/examples/resources/coderd_user/import.sh new file mode 100644 index 0000000..1257bab --- /dev/null +++ b/examples/resources/coderd_user/import.sh @@ -0,0 +1,11 @@ +# The ID supplied can be either a user UUID retrieved via the API +# or a username. +$ terraform import coderd_user.example developer +``` +Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used: + +```terraform +import { + to = coderd_user.example + id = "developer" +} diff --git a/internal/provider/group_resource.go b/internal/provider/group_resource.go index 5bd5a58..a7dcd6a 100644 --- a/internal/provider/group_resource.go +++ b/internal/provider/group_resource.go @@ -62,8 +62,7 @@ func (r *GroupResource) Metadata(ctx context.Context, req resource.MetadataReque func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ MarkdownDescription: "A group on the Coder deployment.\n\n" + - "Creating groups requires an Enterprise license.\n\n" + - "When importing, the ID supplied can be either a group UUID retrieved via the API or `/`.", + "Creating groups requires an Enterprise license.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ diff --git a/internal/provider/template_resource.go b/internal/provider/template_resource.go index 6c3acbb..d296df1 100644 --- a/internal/provider/template_resource.go +++ b/internal/provider/template_resource.go @@ -243,9 +243,7 @@ func (r *TemplateResource) Metadata(ctx context.Context, req resource.MetadataRe func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ MarkdownDescription: "A Coder template.\n\nLogs from building template versions can be optionally streamed from the provisioner " + - "by setting the `TF_LOG` environment variable to `INFO` or higher.\n\n" + - "When importing, the ID supplied can be either a template UUID retrieved via the API or `/`.", - + "by setting the `TF_LOG` environment variable to `INFO` or higher.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ MarkdownDescription: "The ID of the template.", diff --git a/internal/provider/user_resource.go b/internal/provider/user_resource.go index 5dc4203..a560df5 100644 --- a/internal/provider/user_resource.go +++ b/internal/provider/user_resource.go @@ -56,8 +56,7 @@ func (r *UserResource) Metadata(ctx context.Context, req resource.MetadataReques func (r *UserResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ - MarkdownDescription: "A user on the Coder deployment.\n\n" + - "When importing, the ID supplied can be either a user UUID or a username.", + MarkdownDescription: "A user on the Coder deployment.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{