@@ -31,13 +31,15 @@ func TestAccCockpitSource_Basic_metrics(t *testing.T) {
3131 project_id = scaleway_account_project.project.id
3232 name = "my-source"
3333 type = "metrics"
34+ retention_days = 31
3435 }
3536 ` ,
3637 Check : resource .ComposeTestCheckFunc (
3738 isSourcePresent (tt , "scaleway_cockpit_source.main" ),
3839 resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "name" , "my-source" ),
3940 resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "type" , "metrics" ),
4041 resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "region" , "fr-par" ),
42+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "retention_days" , "31" ),
4143 resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "url" ),
4244 resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "push_url" ),
4345 resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "origin" ),
@@ -70,13 +72,57 @@ func TestAccCockpitSource_Basic_logs(t *testing.T) {
7072 project_id = scaleway_account_project.project.id
7173 name = "my-source"
7274 type = "logs"
75+ retention_days = 31
76+
77+ }
78+ ` ,
79+ Check : resource .ComposeTestCheckFunc (
80+ isSourcePresent (tt , "scaleway_cockpit_source.main" ),
81+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "name" , "my-source" ),
82+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "type" , "logs" ),
83+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "region" , "fr-par" ),
84+ resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "url" ),
85+ resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "push_url" ),
86+ resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "origin" ),
87+ resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "created_at" ),
88+ resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "updated_at" ),
89+ resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "synchronized_with_grafana" ),
90+ resource .TestCheckResourceAttrPair ("scaleway_cockpit_source.main" , "project_id" , "scaleway_account_project.project" , "id" ),
91+ ),
92+ },
93+ },
94+ })
95+ }
96+
97+ func TestAccCockpitSource_retention_days (t * testing.T ) {
98+ tt := acctest .NewTestTools (t )
99+ defer tt .Cleanup ()
100+
101+ resource .ParallelTest (t , resource.TestCase {
102+ PreCheck : func () { acctest .PreCheck (t ) },
103+ ProviderFactories : tt .ProviderFactories ,
104+ CheckDestroy : isSourceDestroyed (tt ),
105+ Steps : []resource.TestStep {
106+ {
107+ Config : `
108+ resource "scaleway_account_project" "project" {
109+ name = "tf_tests_cockpit_datasource_basic"
110+ }
111+
112+ resource "scaleway_cockpit_source" "main" {
113+ project_id = scaleway_account_project.project.id
114+ name = "my-source"
115+ type = "logs"
116+ retention_days = 13
117+
73118 }
74119 ` ,
75120 Check : resource .ComposeTestCheckFunc (
76121 isSourcePresent (tt , "scaleway_cockpit_source.main" ),
77122 resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "name" , "my-source" ),
78123 resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "type" , "logs" ),
79124 resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "region" , "fr-par" ),
125+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "retention_days" , "13" ),
80126 resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "url" ),
81127 resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "push_url" ),
82128 resource .TestCheckResourceAttrSet ("scaleway_cockpit_source.main" , "origin" ),
@@ -90,6 +136,75 @@ func TestAccCockpitSource_Basic_logs(t *testing.T) {
90136 })
91137}
92138
139+ func TestAccCockpitSource_Update (t * testing.T ) {
140+ tt := acctest .NewTestTools (t )
141+ defer tt .Cleanup ()
142+
143+ resource .ParallelTest (t , resource.TestCase {
144+ PreCheck : func () { acctest .PreCheck (t ) },
145+ ProviderFactories : tt .ProviderFactories ,
146+ CheckDestroy : isSourceDestroyed (tt ),
147+ Steps : []resource.TestStep {
148+ // Initial creation
149+ {
150+ Config : `
151+ resource "scaleway_account_project" "project" {
152+ name = "tf_tests_cockpit_source_update"
153+ }
154+
155+ resource "scaleway_cockpit_source" "main" {
156+ project_id = scaleway_account_project.project.id
157+ name = "initial-name"
158+ type = "logs"
159+ retention_days = 10
160+ }
161+ ` ,
162+ Check : resource .ComposeTestCheckFunc (
163+ isSourcePresent (tt , "scaleway_cockpit_source.main" ),
164+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "name" , "initial-name" ),
165+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "retention_days" , "10" ),
166+ ),
167+ },
168+ {
169+ Config : `
170+ resource "scaleway_account_project" "project" {
171+ name = "tf_tests_cockpit_source_update"
172+ }
173+
174+ resource "scaleway_cockpit_source" "main" {
175+ project_id = scaleway_account_project.project.id
176+ name = "initial-name"
177+ type = "logs"
178+ retention_days = 20
179+ }
180+ ` ,
181+ Check : resource .ComposeTestCheckFunc (
182+ isSourcePresent (tt , "scaleway_cockpit_source.main" ),
183+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "retention_days" , "20" ),
184+ ),
185+ },
186+ {
187+ Config : `
188+ resource "scaleway_account_project" "project" {
189+ name = "tf_tests_cockpit_source_update"
190+ }
191+
192+ resource "scaleway_cockpit_source" "main" {
193+ project_id = scaleway_account_project.project.id
194+ name = "updated-name"
195+ type = "logs"
196+ retention_days = 20
197+ }
198+ ` ,
199+ Check : resource .ComposeTestCheckFunc (
200+ isSourcePresent (tt , "scaleway_cockpit_source.main" ),
201+ resource .TestCheckResourceAttr ("scaleway_cockpit_source.main" , "name" , "updated-name" ),
202+ ),
203+ },
204+ },
205+ })
206+ }
207+
93208func isSourcePresent (tt * acctest.TestTools , n string ) resource.TestCheckFunc {
94209 return func (state * terraform.State ) error {
95210 rs , ok := state .RootModule ().Resources [n ]
0 commit comments