Skip to content

Commit

Permalink
Add description to spacelift_mounted_file
Browse files Browse the repository at this point in the history
Signed-off-by: peterdeme <[email protected]>
  • Loading branch information
peterdeme committed Feb 10, 2025
1 parent 5926d9a commit 4b61106
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/resources/mounted_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ resource "spacelift_mounted_file" "core-kubeconfig" {
### Optional

- `context_id` (String) ID of the context on which the mounted file is defined
- `description` (String) Free-form description of the mounted file
- `module_id` (String) ID of the module on which the mounted file is defined
- `stack_id` (String) ID of the stack on which the mounted file is defined
- `write_only` (Boolean) Indicates whether the content can be read back outside a Run. Defaults to `true`.
Expand Down
19 changes: 15 additions & 4 deletions spacelift/resource_mounted_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func resourceMountedFile() *schema.Resource {
Optional: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Description: "Free-form description of the mounted file",
Optional: true,
ForceNew: true,
},
"write_only": {
Type: schema.TypeBool,
Description: "Indicates whether the content can be read back outside a Run. Defaults to `true`.",
Expand All @@ -87,10 +93,11 @@ func resourceMountedFile() *schema.Resource {
func resourceMountedFileCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
variables := map[string]interface{}{
"config": structs.ConfigInput{
ID: toID(d.Get("relative_path")),
Type: structs.ConfigType("FILE_MOUNT"),
Value: toString(d.Get("content")),
WriteOnly: graphql.Boolean(d.Get("write_only").(bool)),
ID: toID(d.Get("relative_path")),
Type: structs.ConfigType("FILE_MOUNT"),
Value: toString(d.Get("content")),
WriteOnly: graphql.Boolean(d.Get("write_only").(bool)),
Description: toOptionalString(d.Get("description")),
},
}

Expand Down Expand Up @@ -195,6 +202,10 @@ func resourceMountedFileRead(ctx context.Context, d *schema.ResourceData, meta i
d.Set("relative_path", relativePath)
d.Set("write_only", element.WriteOnly)

if element.Description != nil {
d.Set("description", *element.Description)
}

if value := element.Value; value != nil {
d.Set("content", *value)
} else {
Expand Down
2 changes: 2 additions & 0 deletions spacelift/resource_mounted_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestMountedFileResource(t *testing.T) {
context_id = spacelift_context.test.id
content = base64encode("bacon is tasty")
relative_path = "bacon.txt"
description = "description text"
write_only = %t
}
`, randomID, writeOnly)
Expand All @@ -40,6 +41,7 @@ func TestMountedFileResource(t *testing.T) {
Attribute("checksum", Equals("fb13e7977b7548a324b598e155b5b5ba3dcca2dad5789abe1411a88fa544be9b")),
Attribute("context_id", Contains(randomID)),
Attribute("relative_path", Equals("bacon.txt")),
Attribute("description", Equals("description text")),
Attribute("write_only", Equals("true")),
),
},
Expand Down

0 comments on commit 4b61106

Please sign in to comment.