Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

da-pingwing
Copy link

Copy link
Owner

@davidji99 davidji99 left a 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,
Copy link
Owner

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.

Copy link
Author

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,
Copy link
Owner

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",
Copy link
Owner

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?

Copy link
Author

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.

Comment on lines +122 to +155
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())
}


Copy link
Owner

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(
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants