- Notifications
You must be signed in to change notification settings - Fork22
feat: addcoder_devcontainer
resource#368
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
+174 −0
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
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
29 changes: 29 additions & 0 deletionsdocs/resources/devcontainer.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,29 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "coder_devcontainer Resource - terraform-provider-coder" | ||
subcategory: "" | ||
description: |- | ||
Define a Dev Container the agent should know of and attempt to autostart (minimum Coder version: v2.21). | ||
--- | ||
# coder_devcontainer (Resource) | ||
Define a Dev Container the agent should know of and attempt to autostart (minimum Coder version: v2.21). | ||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
### Required | ||
- `agent_id` (String) The `id` property of a `coder_agent` resource to associate with. | ||
- `workspace_folder` (String) The workspace folder to for the Dev Container. | ||
### Optional | ||
- `config_path` (String) The path to the Dev Container configuration file (devcontainer.json). | ||
### Read-Only | ||
- `id` (String) The ID of this resource. |
46 changes: 46 additions & 0 deletionsprovider/devcontainer.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,46 @@ | ||
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 devcontainerResource() *schema.Resource { | ||
return &schema.Resource{ | ||
SchemaVersion: 1, | ||
Description: "Define a Dev Container the agent should know of and attempt to autostart (minimum Coder version: v2.21).", | ||
CreateContext: func(_ context.Context, rd *schema.ResourceData, _ 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, | ||
}, | ||
"workspace_folder": { | ||
Type: schema.TypeString, | ||
Description: "The workspace folder to for the Dev Container.", | ||
ForceNew: true, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
"config_path": { | ||
Type: schema.TypeString, | ||
Description: "The path to the Dev Container configuration file (devcontainer.json).", | ||
ForceNew: true, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} |
98 changes: 98 additions & 0 deletionsprovider/devcontainer_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package provider_test | ||
import ( | ||
"regexp" | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
funcTestDevcontainer(t*testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
ProviderFactories:coderFactory(), | ||
IsUnitTest:true, | ||
Steps: []resource.TestStep{{ | ||
Config:` | ||
provider "coder" { | ||
} | ||
resource "coder_devcontainer" "example" { | ||
agent_id = "king" | ||
workspace_folder = "/workspace" | ||
config_path = "/workspace/devcontainer.json" | ||
} | ||
`, | ||
Check:func(state*terraform.State)error { | ||
require.Len(t,state.Modules,1) | ||
require.Len(t,state.Modules[0].Resources,1) | ||
script:=state.Modules[0].Resources["coder_devcontainer.example"] | ||
require.NotNil(t,script) | ||
t.Logf("script attributes: %#v",script.Primary.Attributes) | ||
forkey,expected:=rangemap[string]string{ | ||
"agent_id":"king", | ||
"workspace_folder":"/workspace", | ||
"config_path":"/workspace/devcontainer.json", | ||
} { | ||
require.Equal(t,expected,script.Primary.Attributes[key]) | ||
} | ||
returnnil | ||
}, | ||
}}, | ||
}) | ||
} | ||
funcTestDevcontainerNoConfigPath(t*testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
ProviderFactories:coderFactory(), | ||
IsUnitTest:true, | ||
Steps: []resource.TestStep{{ | ||
Config:` | ||
provider "coder" { | ||
} | ||
resource "coder_devcontainer" "example" { | ||
agent_id = "king" | ||
workspace_folder = "/workspace" | ||
} | ||
`, | ||
Check:func(state*terraform.State)error { | ||
require.Len(t,state.Modules,1) | ||
require.Len(t,state.Modules[0].Resources,1) | ||
script:=state.Modules[0].Resources["coder_devcontainer.example"] | ||
require.NotNil(t,script) | ||
t.Logf("script attributes: %#v",script.Primary.Attributes) | ||
forkey,expected:=rangemap[string]string{ | ||
"agent_id":"king", | ||
"workspace_folder":"/workspace", | ||
} { | ||
require.Equal(t,expected,script.Primary.Attributes[key]) | ||
} | ||
returnnil | ||
}, | ||
}}, | ||
}) | ||
} | ||
funcTestDevcontainerNoWorkspaceFolder(t*testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
ProviderFactories:coderFactory(), | ||
IsUnitTest:true, | ||
Steps: []resource.TestStep{{ | ||
Config:` | ||
provider "coder" { | ||
} | ||
resource "coder_devcontainer" "example" { | ||
agent_id = "" | ||
} | ||
`, | ||
ExpectError:regexp.MustCompile(`The argument "workspace_folder" is required, but no definition was found.`), | ||
}}, | ||
}) | ||
} |
1 change: 1 addition & 0 deletionsprovider/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.
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.