Skip to content

Commit

Permalink
fix: Use URN returned by the API for me_identity_group
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Amstutz committed May 6, 2024
1 parent 73c1182 commit af53cd5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
8 changes: 7 additions & 1 deletion ovh/data_me_identity_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -37,6 +38,10 @@ func dataSourceMeIdentityGroup() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"urn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -46,7 +51,7 @@ func dataSourceMeIdentityGroupRead(ctx context.Context, d *schema.ResourceData,

group := d.Get("name").(string)

endpoint := fmt.Sprintf("/me/identity/group/%s", group)
endpoint := fmt.Sprintf("/me/identity/group/%s", url.PathEscape(group))

var resp MeIdentityGroupResponse
err := config.OVHClient.GetWithContext(
Expand All @@ -68,6 +73,7 @@ func dataSourceMeIdentityGroupRead(ctx context.Context, d *schema.ResourceData,
d.Set("creation", resp.Creation)
d.Set("description", resp.Description)
d.Set("role", resp.Role)
d.Set("urn", resp.URN)

return nil
}
4 changes: 0 additions & 4 deletions ovh/helpers/urn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package helpers

import "fmt"

const (
VPSkind string = "vps"
)

func ServiceURN(plate, kind, name string) string {
return fmt.Sprintf("urn:v1:%s:resource:%s:%s", plate, kind, name)
}
10 changes: 5 additions & 5 deletions ovh/resource_me_identity_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -66,7 +67,7 @@ func resourceMeIdentityGroupRead(ctx context.Context, d *schema.ResourceData, me

identityGroup := &MeIdentityGroupResponse{}

endpoint := fmt.Sprintf("/me/identity/group/%s", d.Id())
endpoint := fmt.Sprintf("/me/identity/group/%s", url.PathEscape(d.Id()))
if err := config.OVHClient.GetWithContext(ctx, endpoint, identityGroup); err != nil {
return diag.FromErr(helpers.CheckDeleted(d, err, endpoint))
}
Expand All @@ -76,8 +77,7 @@ func resourceMeIdentityGroupRead(ctx context.Context, d *schema.ResourceData, me
d.Set("creation", identityGroup.Creation)
d.Set("description", identityGroup.Description)
d.Set("role", identityGroup.Role)

d.Set("urn", fmt.Sprintf("urn:v1:%s:identity:group:%s/%s", config.Plate, config.Account, identityGroup.Name))
d.Set("urn", identityGroup.URN)

return nil
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func resourceMeIdentityGroupUpdate(ctx context.Context, d *schema.ResourceData,
Role: role,
}
err := config.OVHClient.PutWithContext(ctx,
fmt.Sprintf("/me/identity/group/%s", d.Id()),
fmt.Sprintf("/me/identity/group/%s", url.PathEscape(d.Id())),
params,
nil,
)
Expand All @@ -134,7 +134,7 @@ func resourceMeIdentityGroupDelete(ctx context.Context, d *schema.ResourceData,
config := meta.(*Config)

err := config.OVHClient.DeleteWithContext(ctx,
fmt.Sprintf("/me/identity/group/%s", d.Id()),
fmt.Sprintf("/me/identity/group/%s", url.PathEscape(d.Id())),
nil,
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions ovh/types_me.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ type MeIdentityGroupResponse struct {
Creation string `json:"creation"`
Description string `json:"description"`
LastUpdate string `json:"lastUpdate"`
URN string `json:"urn"`
}

type MeIdentityGroupCreateOpts struct {
Expand Down

0 comments on commit af53cd5

Please sign in to comment.