-
Notifications
You must be signed in to change notification settings - Fork 10
Add support to create to add tags for issue #166 #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ package api | |
|
||
type Tag struct { | ||
Name *string `json:"name"` | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,15 @@ func resourceSplitSplit() *schema.Resource { | |
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"tags":{ | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
ForceNew: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cant actually remove tags from a feature flag, only add new ones. At least that's how it was when i tested it. |
||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -110,6 +119,40 @@ func resourceSplitSplitCreate(ctx context.Context, d *schema.ResourceData, meta | |
|
||
log.Printf("[DEBUG] Created split %v", s.GetID()) | ||
|
||
tagsRaw := d.Get("tags").([]interface{}) | ||
tags := make([]string, len(tagsRaw)) | ||
log.Printf("[DEBUG] Creating Tag amount: %v", len(tags)) | ||
|
||
if len(tags) > 0 { | ||
log.Printf("[DEBUG] Creating Tags %v",tags) | ||
// Create object | ||
operations := []api.SplitUpdateFlagRequest{} | ||
for _, tag := range tagsRaw { | ||
operation := api.SplitUpdateFlagRequest{ | ||
Op: "add", | ||
Path: "/tags/0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the path always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If doing Tags, yes. For other operations other paths are needed. |
||
Value: api.SplitTag{ | ||
Name: tag.(string), | ||
}, | ||
} | ||
operations = append(operations, operation) | ||
} | ||
|
||
log.Printf("[DEBUG] Operations: %v", &operations) | ||
s, _, updateForTagErr := client.Splits.UpdateSplit(workspaceID, opts.Name, &operations) | ||
if updateForTagErr != nil { | ||
diags = append(diags, diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: fmt.Sprintf("Unable to update split flags %v", opts.Name), | ||
Detail: createErr.Error(), | ||
}) | ||
return diags | ||
} | ||
|
||
log.Printf("[DEBUG] Updated split %v", s.GetID()) | ||
} | ||
|
||
|
||
Comment on lines
+122
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire method needs to be extracted into a separate method that is called by both |
||
d.SetId(s.GetID()) | ||
d.Set("workspace_id", workspaceID) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ func TestAccSplitSplit_Basic(t *testing.T) { | |
"split_split.foobar", "description", "my split description"), | ||
resource.TestCheckResourceAttrSet( | ||
"split_split.foobar", "traffic_type_id"), | ||
resource.TestCheckResourceAttrSet( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to add a testcase in this file that adds tags to the feature flag instead of just checking if it is read. |
||
["split.testtag"], "tags"), | ||
), | ||
}, | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeSet
might better here unless order is important fortags
.