-
Notifications
You must be signed in to change notification settings - Fork 67
/
schema_tag.go
74 lines (63 loc) · 1.75 KB
/
schema_tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package octopusdeploy
import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tagsets"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func getTagSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"canonical_tag_name": {
Computed: true,
Type: schema.TypeString,
},
"color": {
Required: true,
Type: schema.TypeString,
},
"description": getDescriptionSchema("tag"),
"name": getNameSchema(true),
"sort_order": {
Computed: true,
Optional: true,
Type: schema.TypeInt,
},
"tag_set_id": {
Description: "The ID of the associated tag set.",
Required: true,
Type: schema.TypeString,
},
"tag_set_space_id": {
Description: "The Space ID of the associated tag set. Required if the tag set is not in the same space as what is configured on the provider",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
}
}
func expandTag(d *schema.ResourceData) *tagsets.Tag {
color := d.Get("color").(string)
name := d.Get("name").(string)
tag := tagsets.NewTag(name, color)
tag.ID = d.Id()
if v, ok := d.GetOk("canonical_tag_name"); ok {
tag.CanonicalTagName = v.(string)
}
if v, ok := d.GetOk("description"); ok {
tag.Description = v.(string)
}
if v, ok := d.GetOk("sort_order"); ok {
tag.SortOrder = v.(int)
}
return tag
}
func setTag(ctx context.Context, d *schema.ResourceData, tag *tagsets.Tag, tagSet *tagsets.TagSet) error {
d.Set("canonical_tag_name", tag.CanonicalTagName)
d.Set("color", tag.Color)
d.Set("description", tag.Description)
d.Set("name", tag.Name)
d.Set("sort_order", tag.SortOrder)
d.Set("tag_set_id", tagSet.GetID())
d.Set("tag_set_space_id", tagSet.SpaceID)
d.SetId(tag.ID)
return nil
}