Add support to create to add tags for issue #166#167
Add support to create to add tags for issue #166#167da-pingwing wants to merge 1 commit intodavidji99:masterfrom
Conversation
davidji99
left a comment
There was a problem hiding this comment.
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.
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.
You cant actually remove tags from a feature flag, only add new ones. At least that's how it was when i tested it.
| }, | ||
|
|
||
| "tags":{ | ||
| Type: schema.TypeList, |
There was a problem hiding this comment.
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.
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.
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.
| "split_split.foobar", "description", "my split description"), | ||
| resource.TestCheckResourceAttrSet( | ||
| "split_split.foobar", "traffic_type_id"), | ||
| resource.TestCheckResourceAttrSet( |
There was a problem hiding this comment.
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