- Notifications
You must be signed in to change notification settings - Fork3
feat: add coderd_template resource#35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletionsdocs/resources/template.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "coderd_template Resource - coderd" | ||
subcategory: "" | ||
description: |- | ||
A Coder template | ||
--- | ||
# coderd_template (Resource) | ||
A Coder template | ||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
### Required | ||
- `acl` (Attributes) Access control list for the template. (see [below for nested schema](#nestedatt--acl)) | ||
- `name` (String) The name of the template. | ||
- `versions` (Attributes List) (see [below for nested schema](#nestedatt--versions)) | ||
### Optional | ||
- `allow_user_auto_start` (Boolean) | ||
- `allow_user_auto_stop` (Boolean) | ||
- `description` (String) A description of the template. | ||
- `display_name` (String) The display name of the template. Defaults to the template name. | ||
- `icon` (String) Relative path or external URL that specifes an icon to be displayed in the dashboard. | ||
- `organization_id` (String) The ID of the organization. Defaults to the provider's default organization | ||
### Read-Only | ||
- `id` (String) The ID of the template. | ||
<a id="nestedatt--acl"></a> | ||
### Nested Schema for `acl` | ||
Required: | ||
- `groups` (Attributes Set) (see [below for nested schema](#nestedatt--acl--groups)) | ||
- `users` (Attributes Set) (see [below for nested schema](#nestedatt--acl--users)) | ||
<a id="nestedatt--acl--groups"></a> | ||
### Nested Schema for `acl.groups` | ||
Required: | ||
- `id` (String) | ||
- `role` (String) | ||
<a id="nestedatt--acl--users"></a> | ||
### Nested Schema for `acl.users` | ||
Required: | ||
- `id` (String) | ||
- `role` (String) | ||
<a id="nestedatt--versions"></a> | ||
### Nested Schema for `versions` | ||
Required: | ||
- `directory` (String) A path to the directory to create the template version from. Changes in the directory contents will trigger the creation of a new template version. | ||
Optional: | ||
- `active` (Boolean) Whether this version is the active version of the template. Only one version can be active at a time. | ||
- `message` (String) A message describing the changes in this version of the template. Messages longer than 72 characters will be truncated. | ||
- `name` (String) The name of the template version. Automatically generated if not provided. | ||
- `provisioner_tags` (Attributes Set) Provisioner tags for the template version. (see [below for nested schema](#nestedatt--versions--provisioner_tags)) | ||
- `tf_vars` (Attributes Set) Terraform variables for the template version. (see [below for nested schema](#nestedatt--versions--tf_vars)) | ||
Read-Only: | ||
- `directory_hash` (String) | ||
- `id` (String) | ||
<a id="nestedatt--versions--provisioner_tags"></a> | ||
### Nested Schema for `versions.provisioner_tags` | ||
Required: | ||
- `name` (String) | ||
- `value` (String) | ||
<a id="nestedatt--versions--tf_vars"></a> | ||
### Nested Schema for `versions.tf_vars` | ||
Required: | ||
- `name` (String) | ||
- `value` (String) |
1 change: 1 addition & 0 deletionsgo.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletionsgo.sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletionsintegration/integration_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletionsintegration/template-test/example-template-2/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
variable "name" { | ||
type = string | ||
} | ||
resource "local_file" "a" { | ||
filename = "${path.module}/a.txt" | ||
content = "hello ${var.name}" | ||
} | ||
output "a" { | ||
value = local_file.a.content | ||
} |
12 changes: 12 additions & 0 deletionsintegration/template-test/example-template/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
variable "name" { | ||
type = string | ||
} | ||
resource "local_file" "a" { | ||
filename = "${path.module}/a.txt" | ||
content = "hello ${var.name}" | ||
} | ||
output "a" { | ||
value = local_file.a.content | ||
} |
1 change: 1 addition & 0 deletionsintegration/template-test/example-template/terraform.tfvars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name = "world" |
67 changes: 67 additions & 0 deletionsintegration/template-test/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
terraform { | ||
required_providers { | ||
coderd = { | ||
source = "coder/coderd" | ||
version = ">=0.0.0" | ||
} | ||
} | ||
} | ||
resource "coderd_user" "ethan" { | ||
username = "ethan" | ||
name = "Ethan Coolguy" | ||
email = "test@coder.com" | ||
roles = ["owner", "template-admin"] | ||
login_type = "password" | ||
password = "SomeSecurePassword!" | ||
suspended = false | ||
} | ||
data "coderd_organization" "default" { | ||
is_default = true | ||
} | ||
resource "coderd_template" "sample" { | ||
name = "example-template" | ||
allow_user_auto_stop = false | ||
allow_user_auto_start = false | ||
acl = { | ||
groups = [ | ||
{ | ||
id = data.coderd_organization.default.id | ||
role = "use" | ||
} | ||
] | ||
users = [ | ||
{ | ||
id = resource.coderd_user.ethan.id | ||
role = "admin" | ||
} | ||
] | ||
} | ||
versions = [ | ||
{ | ||
name = "latest" | ||
directory = "./example-template" | ||
active = true | ||
tf_vars = [ | ||
{ | ||
name = "name" | ||
value = "world" | ||
}, | ||
] | ||
}, | ||
{ | ||
name = "legacy" | ||
directory = "./example-template-2" | ||
active = false | ||
tf_vars = [ | ||
{ | ||
name = "name" | ||
value = "ethan" | ||
}, | ||
] | ||
} | ||
] | ||
} |
45 changes: 45 additions & 0 deletionsinternal/provider/logger.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package provider | ||
import ( | ||
"context" | ||
"cdr.dev/slog" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
var _ slog.Sink = &tfLogSink{} | ||
type tfLogSink struct { | ||
tfCtx context.Context | ||
} | ||
func newTFLogSink(tfCtx context.Context) *tfLogSink { | ||
return &tfLogSink{ | ||
tfCtx: tfCtx, | ||
} | ||
} | ||
func (s *tfLogSink) LogEntry(ctx context.Context, e slog.SinkEntry) { | ||
var logFn func(ctx context.Context, msg string, additionalFields ...map[string]interface{}) | ||
switch e.Level { | ||
case slog.LevelDebug: | ||
logFn = tflog.Debug | ||
case slog.LevelInfo: | ||
logFn = tflog.Info | ||
case slog.LevelWarn: | ||
logFn = tflog.Warn | ||
default: | ||
logFn = tflog.Error | ||
} | ||
logFn(s.tfCtx, e.Message, mapToFields(e.Fields)) | ||
} | ||
func (s *tfLogSink) Sync() {} | ||
func mapToFields(m slog.Map) map[string]interface{} { | ||
fields := make(map[string]interface{}, len(m)) | ||
for _, v := range m { | ||
fields[v.Name] = v.Value | ||
} | ||
return fields | ||
} |
2 changes: 1 addition & 1 deletioninternal/provider/organization_data_source_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsinternal/provider/provider.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.