Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/cockpit_grafana_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ This section lists the arguments that are supported:
In addition to all arguments above, the following attributes are exported:

- `password` - The password of the Grafana user.
- `grafana_url` - URL for Grafana.


## Import

Expand Down
18 changes: 18 additions & 0 deletions internal/services/cockpit/grafana_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func ResourceCockpitGrafanaUser() *schema.Resource {
Description: "The role of the Grafana user",
ValidateDiagFunc: verify.ValidateEnum[cockpit.GrafanaUserRole](),
},
"grafana_url": {
Type: schema.TypeString,
Computed: true,
Description: "The grafana URL",
},

"project_id": account.ProjectIDSchema(),
},
}
Expand Down Expand Up @@ -109,9 +115,21 @@ func ResourceCockpitGrafanaUserRead(ctx context.Context, d *schema.ResourceData,
return nil
}

grafana, err := api.GetGrafana(&cockpit.GlobalAPIGetGrafanaRequest{
ProjectID: projectID,
}, scw.WithContext(ctx))
if err != nil {
if httperrors.Is404(err) {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

_ = d.Set("login", grafanaUser.Login)
_ = d.Set("role", grafanaUser.Role)
_ = d.Set("project_id", projectID)
_ = d.Set("grafana_url", grafana.GrafanaURL)

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions internal/services/cockpit/grafana_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestAccGrafanaUser_Basic(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "login", grafanaTestUsername),
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "role", "editor"),
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "password"),
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "grafana_url"),
),
},
{
Expand Down Expand Up @@ -86,6 +87,7 @@ func TestAccGrafanaUser_Update(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "login", grafanaTestUsername),
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "role", "editor"),
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "password"),
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "grafana_url"),
),
},
{
Expand All @@ -106,6 +108,7 @@ func TestAccGrafanaUser_Update(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "login", grafanaTestUsername),
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "role", "viewer"),
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "password"),
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "grafana_url"),
),
},
{
Expand Down
Loading
Loading