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 6, 2025
1 parent d91d086 commit 269df4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 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
14 changes: 14 additions & 0 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 @@ -94,6 +100,10 @@ func resourceMountedFileCreate(ctx context.Context, d *schema.ResourceData, meta
},
}

if desc, ok := d.GetOk("description"); ok {
variables["description"] = desc
}

if contextID, ok := d.GetOk("context_id"); ok {
variables["context"] = toID(contextID)
return resourceMountedFileCreateContext(ctx, d, meta.(*internal.Client), variables)
Expand Down Expand Up @@ -195,6 +205,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 269df4d

Please sign in to comment.