Skip to content

Commit

Permalink
feat(cockpit): add field grafana url
Browse files Browse the repository at this point in the history
  • Loading branch information
jremy42 committed Dec 20, 2024
1 parent 5d65352 commit 7287f4e
Show file tree
Hide file tree
Showing 5 changed files with 693 additions and 229 deletions.
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

0 comments on commit 7287f4e

Please sign in to comment.