-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add support to create to add tags for issue #166 #167
base: master
Are you sure you want to change the base?
Conversation
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.
Good start but several changes needed.
Additionally, you need to update documentation and remove the binary file you checked in.
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
ForceNew: true, |
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.
Is ForceNew: true
needed here? It does seem you can update the feature flag without needing to recreate the feature flag itself.
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.
You cant actually remove tags from a feature flag, only add new ones. At least that's how it was when i tested it.
@@ -50,6 +50,15 @@ func resourceSplitSplit() *schema.Resource { | |||
Optional: true, | |||
Computed: true, | |||
}, | |||
|
|||
"tags":{ | |||
Type: schema.TypeList, |
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 for tags
.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is the path always /tags/0
?
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.
If doing Tags, yes. For other operations other paths are needed.
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", | ||
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()) | ||
} | ||
|
||
|
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.
This entire method needs to be extracted into a separate method that is called by both resourceSplitSplitUpdate
and resourceSplitSplitCreate
. With what you have now, the only time tags
will be added to the feature flag is during creation.
@@ -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 comment
The 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.
#166