Skip to content

Commit a6e0783

Browse files
committed
handle error in createPushURL
1 parent cd46b48 commit a6e0783

File tree

5 files changed

+1038
-6
lines changed

5 files changed

+1038
-6
lines changed

internal/services/cockpit/source.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ func ResourceCockpitSourceRead(ctx context.Context, d *schema.ResourceData, meta
117117
return diag.FromErr(err)
118118
}
119119

120+
pushURL, err := createCockpitPushURL(res.Type, res.URL)
121+
if err != nil {
122+
return diag.FromErr(err)
123+
}
124+
120125
_ = d.Set("name", res.Name)
121126
_ = d.Set("type", res.Type.String())
122127
_ = d.Set("url", res.URL)
@@ -126,7 +131,7 @@ func ResourceCockpitSourceRead(ctx context.Context, d *schema.ResourceData, meta
126131
_ = d.Set("created_at", types.FlattenTime(res.CreatedAt))
127132
_ = d.Set("updated_at", types.FlattenTime(res.UpdatedAt))
128133
_ = d.Set("project_id", res.ProjectID)
129-
_ = d.Set("push_url", createCockpitPushURL(res.Type, res.URL))
134+
_ = d.Set("push_url", pushURL)
130135

131136
return nil
132137
}

internal/services/cockpit/source_test.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/cockpit"
1313
)
1414

15-
func TestAccCockpitSource_Basic(t *testing.T) {
15+
func TestAccCockpitSource_Basic_metrics(t *testing.T) {
1616
tt := acctest.NewTestTools(t)
1717
defer tt.Cleanup()
1818

@@ -51,6 +51,45 @@ func TestAccCockpitSource_Basic(t *testing.T) {
5151
})
5252
}
5353

54+
func TestAccCockpitSource_Basic_logs(t *testing.T) {
55+
tt := acctest.NewTestTools(t)
56+
defer tt.Cleanup()
57+
58+
resource.ParallelTest(t, resource.TestCase{
59+
PreCheck: func() { acctest.PreCheck(t) },
60+
ProviderFactories: tt.ProviderFactories,
61+
CheckDestroy: isSourceDestroyed(tt),
62+
Steps: []resource.TestStep{
63+
{
64+
Config: `
65+
resource "scaleway_account_project" "project" {
66+
name = "tf_tests_cockpit_datasource_basic"
67+
}
68+
69+
resource "scaleway_cockpit_source" "main" {
70+
project_id = scaleway_account_project.project.id
71+
name = "my-source"
72+
type = "logs"
73+
}
74+
`,
75+
Check: resource.ComposeTestCheckFunc(
76+
isSourcePresent(tt, "scaleway_cockpit_source.main"),
77+
resource.TestCheckResourceAttr("scaleway_cockpit_source.main", "name", "my-source"),
78+
resource.TestCheckResourceAttr("scaleway_cockpit_source.main", "type", "logs"),
79+
resource.TestCheckResourceAttr("scaleway_cockpit_source.main", "region", "fr-par"),
80+
resource.TestCheckResourceAttrSet("scaleway_cockpit_source.main", "url"),
81+
resource.TestCheckResourceAttrSet("scaleway_cockpit_source.main", "push_url"),
82+
resource.TestCheckResourceAttrSet("scaleway_cockpit_source.main", "origin"),
83+
resource.TestCheckResourceAttrSet("scaleway_cockpit_source.main", "created_at"),
84+
resource.TestCheckResourceAttrSet("scaleway_cockpit_source.main", "updated_at"),
85+
resource.TestCheckResourceAttrSet("scaleway_cockpit_source.main", "synchronized_with_grafana"),
86+
resource.TestCheckResourceAttrPair("scaleway_cockpit_source.main", "project_id", "scaleway_account_project.project", "id"),
87+
),
88+
},
89+
},
90+
})
91+
}
92+
5493
func isSourcePresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
5594
return func(state *terraform.State) error {
5695
rs, ok := state.RootModule().Resources[n]

0 commit comments

Comments
 (0)