Skip to content

Commit

Permalink
update env segment resource to accept optional comment/title
Browse files Browse the repository at this point in the history
  • Loading branch information
davidji99 committed Mar 18, 2024
1 parent fe39161 commit 7deb4b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type EnvironmentRequest struct {
type EnvironmentSegmentKeysRequest struct {
Keys []string `json:"keys"`
Comment string `json:"comment,omitempty"`
Title string `json:"title,omitempty"`
}

// List all environments.
Expand Down
22 changes: 22 additions & 0 deletions split/resource_split_environment_segment_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ func resourceSplitEnvironmentSegmentKeys() *schema.Resource {
MinItems: 1,
MaxItems: 10000,
},

"comment": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"title": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -85,6 +97,16 @@ func resourceSplitEnvironmentSegmentKeysCreate(ctx context.Context, d *schema.Re
environmentID := getEnvironmentID(d)
segmentName := d.Get("segment_name").(string)

if v, ok := d.GetOk("comment"); ok {
opts.Comment = v.(string)
log.Printf("[DEBUG] new env segment key comment is : %v", opts.Comment)
}

if v, ok := d.GetOk("title"); ok {
opts.Title = v.(string)
log.Printf("[DEBUG] new env segment key title is : %v", opts.Title)
}

if v, ok := d.GetOk("keys"); ok {
vL := v.(*schema.Set).List()
keys := make([]string, 0)
Expand Down
6 changes: 6 additions & 0 deletions split/resource_split_environment_segment_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func TestAccSplitEnvironmentSegmentKeys_Basic(t *testing.T) {
// "split_environment_segment_keys.foobar", "keys.#.1", "tester2"),
resource.TestCheckResourceAttrSet(
"split_environment_segment_keys.foobar", "environment_id"),
resource.TestCheckResourceAttr(
"split_environment_segment_keys.foobar", "comment", "test comment"),
resource.TestCheckResourceAttr(
"split_environment_segment_keys.foobar", "title", "test title"),
),
},
{
Expand Down Expand Up @@ -90,6 +94,8 @@ resource "split_environment_segment_keys" "foobar" {
environment_id = split_environment.foobar.id
segment_name = split_segment_environment_association.foobar.segment_name
keys = ["tester1", "tester2"]
title = "test title"
comment = "test comment"
}
`, workspaceID, environmentName, trafficTypeName, segmentName, production)
Expand Down

0 comments on commit 7deb4b9

Please sign in to comment.