Skip to content

Commit 9c44fc4

Browse files
committed
feat(cockpit) : add push_url in cockpit ressource
1 parent 3cedb7b commit 9c44fc4

File tree

4 files changed

+199
-230
lines changed

4 files changed

+199
-230
lines changed

scaleway/helpers_cockpit.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
const (
1515
defaultCockpitTimeout = 5 * time.Minute
1616
)
17+
const (
18+
pathMetricsUrl = "/api/v1/push"
19+
pathLogsUrl = "/loki/api/v1/push"
20+
)
1721

1822
// cockpitAPI returns a new cockpit API.
1923
func cockpitAPI(m interface{}) (*cockpit.API, error) {
@@ -69,6 +73,14 @@ func flattenCockpitEndpoints(endpoints *cockpit.CockpitEndpoints) []map[string]i
6973
}
7074
}
7175

76+
func createCockpitPushUrl(endpoints *cockpit.CockpitEndpoints) []map[string]interface{} {
77+
return []map[string]interface{}{
78+
{
79+
"push_metrics_url": endpoints.MetricsURL + pathMetricsUrl,
80+
"push_logs_url": endpoints.LogsURL + pathLogsUrl,
81+
},
82+
}
83+
}
7284
func expandCockpitTokenScopes(raw interface{}) *cockpit.TokenScopes {
7385
if raw == nil || len(raw.([]interface{})) != 1 {
7486
return nil

scaleway/resource_cockpit.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ func resourceScalewayCockpit() *schema.Resource {
7070
},
7171
},
7272
},
73+
"push_url": {
74+
Type: schema.TypeList,
75+
Computed: true,
76+
Description: "Push_url",
77+
Elem: &schema.Resource{
78+
Schema: map[string]*schema.Schema{
79+
"push_metrics_url": {
80+
Type: schema.TypeString,
81+
Computed: true,
82+
Description: "Push url for grafana Mimir",
83+
},
84+
"push_logs_url": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
Description: "Push url for grafana locki",
88+
},
89+
},
90+
},
91+
},
7392
},
7493
}
7594
}
@@ -140,6 +159,7 @@ func resourceScalewayCockpitRead(ctx context.Context, d *schema.ResourceData, me
140159
_ = d.Set("project_id", res.ProjectID)
141160
_ = d.Set("plan_id", res.Plan.ID)
142161
_ = d.Set("endpoints", flattenCockpitEndpoints(res.Endpoints))
162+
_ = d.Set("push_url", createCockpitPushUrl(res.Endpoints))
143163

144164
return nil
145165
}

scaleway/resource_cockpit_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func TestAccScalewayCockpit_Basic(t *testing.T) {
8585
resource.TestCheckResourceAttrSet("scaleway_cockpit.main", "endpoints.0.alertmanager_url"),
8686
resource.TestCheckResourceAttrSet("scaleway_cockpit.main", "endpoints.0.grafana_url"),
8787
resource.TestCheckResourceAttrSet("scaleway_cockpit.main", "endpoints.0.traces_url"),
88+
resource.TestCheckResourceAttr("scaleway_cockpit.main", "push_url.0.push_logs_url", "https://logs.cockpit.fr-par.scw.cloud/loki/api/v1/push"),
89+
resource.TestCheckResourceAttr("scaleway_cockpit.main", "push_url.0.push_metrics_url", "https://metrics.cockpit.fr-par.scw.cloud/api/v1/push"),
90+
8891
resource.TestCheckResourceAttrPair("scaleway_cockpit.main", "project_id", "scaleway_account_project.project", "id"),
8992
),
9093
},

0 commit comments

Comments
 (0)