Skip to content

Commit d6e4a29

Browse files
0x2b3bfa0casperdcl
andauthored
Add resource tagging support (#599)
* Add resource tagging support * Apply arguable suggestions from code review Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org>
1 parent a31151a commit d6e4a29

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

docs/resources/task.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ resource "iterative_task" "example" {
6565
- `storage.output` - (Optional) Results directory (**relative to `workdir`**) to download (default: no download).
6666
- `environment` - (Optional) Map of environment variable names and values for the task script. Empty string values are replaced with local environment values. Empty values may also be combined with a [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) name to import all matching variables.
6767
- `timeout` - (Optional) Maximum number of seconds to run before instances are force-terminated. The countdown is reset each time TPI auto-respawns a spot instance.
68+
- `tags` - (Optional) Map of tags for the created cloud resources.
6869
- `name` - (Optional) _Discouraged and may be removed in future - change the resource name instead, i.e. `resource "iterative_task" "some_other_example_name"`._ Deterministic task name (e.g. `name="Hello, World!"` always produces `id="tpi-hello-world-5kz6ldls-57wo7rsp"`).
6970

7071
-> **Note:** `output` is relative to `workdir`, so `storage { workdir = "foo", output = "bar" }` means "upload `./foo/`, change working directory to the uploaded folder, run `script`, and download `bar` (i.e. `./foo/bar`)".

iterative/resource_task.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ func resourceTask() *schema.Resource {
156156
Type: schema.TypeString,
157157
},
158158
},
159+
"tags": {
160+
Type: schema.TypeMap,
161+
ForceNew: true,
162+
Optional: true,
163+
Elem: &schema.Schema{
164+
Type: schema.TypeString,
165+
},
166+
},
159167
"timeout": {
160168
Type: schema.TypeInt,
161169
ForceNew: true,
@@ -283,6 +291,11 @@ func resourceTaskDelete(ctx context.Context, d *schema.ResourceData, m interface
283291
}
284292

285293
func resourceTaskBuild(ctx context.Context, d *schema.ResourceData, m interface{}) (task.Task, error) {
294+
tags := make(map[string]string)
295+
for name, value := range d.Get("tags").(map[string]interface{}) {
296+
tags[name] = value.(string)
297+
}
298+
286299
v := make(map[string]*string)
287300
for name, value := range d.Get("environment").(map[string]interface{}) {
288301
v[name] = nil
@@ -309,6 +322,7 @@ func resourceTaskBuild(ctx context.Context, d *schema.ResourceData, m interface{
309322
Update: d.Timeout(schema.TimeoutUpdate),
310323
Delete: d.Timeout(schema.TimeoutDelete),
311324
},
325+
Tags: tags,
312326
}
313327

314328
directory := ""

0 commit comments

Comments
 (0)