Skip to content

Commit cc25aef

Browse files
committed
feat(cockpit): add field grafana url (#2857)
1 parent 80279cd commit cc25aef

File tree

5 files changed

+693
-229
lines changed

5 files changed

+693
-229
lines changed

docs/resources/cockpit_grafana_user.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ This section lists the arguments that are supported:
4141
In addition to all arguments above, the following attributes are exported:
4242

4343
- `password` - The password of the Grafana user.
44+
- `grafana_url` - URL for Grafana.
45+
4446

4547
## Import
4648

internal/services/cockpit/grafana_user.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func ResourceCockpitGrafanaUser() *schema.Resource {
5050
Description: "The role of the Grafana user",
5151
ValidateDiagFunc: verify.ValidateEnum[cockpit.GrafanaUserRole](),
5252
},
53+
"grafana_url": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
Description: "The grafana URL",
57+
},
58+
5359
"project_id": account.ProjectIDSchema(),
5460
},
5561
}
@@ -109,9 +115,21 @@ func ResourceCockpitGrafanaUserRead(ctx context.Context, d *schema.ResourceData,
109115
return nil
110116
}
111117

118+
grafana, err := api.GetGrafana(&cockpit.GlobalAPIGetGrafanaRequest{
119+
ProjectID: projectID,
120+
}, scw.WithContext(ctx))
121+
if err != nil {
122+
if httperrors.Is404(err) {
123+
d.SetId("")
124+
return nil
125+
}
126+
return diag.FromErr(err)
127+
}
128+
112129
_ = d.Set("login", grafanaUser.Login)
113130
_ = d.Set("role", grafanaUser.Role)
114131
_ = d.Set("project_id", projectID)
132+
_ = d.Set("grafana_url", grafana.GrafanaURL)
115133

116134
return nil
117135
}

internal/services/cockpit/grafana_user_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestAccGrafanaUser_Basic(t *testing.T) {
4343
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "login", grafanaTestUsername),
4444
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "role", "editor"),
4545
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "password"),
46+
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "grafana_url"),
4647
),
4748
},
4849
{
@@ -86,6 +87,7 @@ func TestAccGrafanaUser_Update(t *testing.T) {
8687
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "login", grafanaTestUsername),
8788
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "role", "editor"),
8889
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "password"),
90+
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "grafana_url"),
8991
),
9092
},
9193
{
@@ -106,6 +108,7 @@ func TestAccGrafanaUser_Update(t *testing.T) {
106108
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "login", grafanaTestUsername),
107109
resource.TestCheckResourceAttr("scaleway_cockpit_grafana_user.main", "role", "viewer"),
108110
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "password"),
111+
resource.TestCheckResourceAttrSet("scaleway_cockpit_grafana_user.main", "grafana_url"),
109112
),
110113
},
111114
{

0 commit comments

Comments
 (0)