Skip to content

Commit

Permalink
fix: missing tenantId on user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Aug 9, 2024
1 parent 0d6ab85 commit be6812c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion internal/provider/data_source_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func dataSourceServiceAccountRead(ctx context.Context, d *schema.ResourceData, m
var diags diag.Diagnostics

id := d.Get("id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(nil), id), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), id), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/data_source_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceUser() *schema.Resource {

ReadContext: dataSourceUserRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Computed: true,
},
"user_id": {
Description: "The user.",
Type: schema.TypeString,
Expand Down Expand Up @@ -66,8 +71,9 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interf
var diags diag.Diagnostics

userId := d.Get("user_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(nil), userId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), userId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
13 changes: 9 additions & 4 deletions internal/provider/resource_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func resourceServiceAccountCreate(ctx context.Context, d *schema.ResourceData, m
return diag.FromErr(err)
}

r, reqErr := c.request("POST", fmt.Sprintf("%s/users/service-accounts", apiRoot(nil)), body)
tenantId := c.TenantId

r, reqErr := c.request("POST", fmt.Sprintf("%s/users/service-accounts", apiRoot(tenantId)), body)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand All @@ -81,8 +83,9 @@ func resourceServiceAccountRead(ctx context.Context, d *schema.ResourceData, met
var diags diag.Diagnostics

id := d.Id()
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(nil), id), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), id), nil)
if reqErr != nil {
if reqErr.StatusCode == http.StatusNotFound {
d.SetId("")
Expand Down Expand Up @@ -111,8 +114,9 @@ func resourceServiceAccountUpdate(ctx context.Context, d *schema.ResourceData, m
}

id := d.Id()
tenantId := c.TenantId

r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/service-accounts/%s", apiRoot(nil), id), body)
r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/service-accounts/%s", apiRoot(tenantId), id), body)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand All @@ -133,8 +137,9 @@ func resourceServiceAccountDelete(ctx context.Context, d *schema.ResourceData, m
var diags diag.Diagnostics

id := d.Id()
tenantId := c.TenantId

_, reqErr := c.request("DELETE", fmt.Sprintf("%s/users/%s", apiRoot(nil), id), nil)
_, reqErr := c.request("DELETE", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), id), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
13 changes: 9 additions & 4 deletions internal/provider/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf
return diag.FromErr(err)
}

r, reqErr := c.request("POST", fmt.Sprintf("%s/users", apiRoot(nil)), body)
tenantId := c.TenantId

r, reqErr := c.request("POST", fmt.Sprintf("%s/users", apiRoot(tenantId)), body)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand All @@ -89,8 +91,9 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac
var diags diag.Diagnostics

userId := d.Id()
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(nil), userId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), userId), nil)
if reqErr != nil {
if reqErr.StatusCode == http.StatusNotFound {
d.SetId("")
Expand Down Expand Up @@ -119,8 +122,9 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf
}

userId := d.Id()
tenantId := c.TenantId

r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/%s", apiRoot(nil), userId), body)
r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), userId), body)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand All @@ -141,8 +145,9 @@ func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interf
var diags diag.Diagnostics

userId := d.Id()
tenantId := c.TenantId

_, reqErr := c.request("DELETE", fmt.Sprintf("%s/users/%s", apiRoot(nil), userId), nil)
_, reqErr := c.request("DELETE", fmt.Sprintf("%s/users/%s", apiRoot(tenantId), userId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
6 changes: 4 additions & 2 deletions internal/provider/resource_user_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func resourceUserPasswordCreate(ctx context.Context, d *schema.ResourceData, met
}

userId := d.Get("user_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/%s/password", apiRoot(nil), userId), body)
r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/%s/password", apiRoot(tenantId), userId), body)
if reqErr != nil {
if reqErr.StatusCode == http.StatusNotFound {
d.SetId("")
Expand All @@ -76,8 +77,9 @@ func resourceUserPasswordUpdate(ctx context.Context, d *schema.ResourceData, met
}

userId := d.Id()
tenantId := c.TenantId

r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/%s/password", apiRoot(nil), userId), body)
r, reqErr := c.request("PUT", fmt.Sprintf("%s/users/%s/password", apiRoot(tenantId), userId), body)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down

0 comments on commit be6812c

Please sign in to comment.