Skip to content

Commit 969ec95

Browse files
committed
feat(function_cron): add name attribute
1 parent 538c279 commit 969ec95

File tree

5 files changed

+1895
-710
lines changed

5 files changed

+1895
-710
lines changed

scaleway/resource_function_cron.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func resourceScalewayFunctionCron() *schema.Resource {
4343
Required: true,
4444
Description: "Functions arguments as json object to pass through during execution.",
4545
},
46+
"name": {
47+
Type: schema.TypeString,
48+
Optional: true,
49+
Description: "The name of the cron job.",
50+
},
4651
"status": {
4752
Type: schema.TypeString,
4853
Computed: true,
@@ -70,6 +75,7 @@ func resourceScalewayFunctionCronCreate(ctx context.Context, d *schema.ResourceD
7075
FunctionID: f.ID,
7176
Schedule: d.Get("schedule").(string),
7277
Region: region,
78+
Name: expandStringPtr(d.Get("name")),
7379
}
7480

7581
if args, ok := d.GetOk("args"); ok {
@@ -112,7 +118,7 @@ func resourceScalewayFunctionCronRead(ctx context.Context, d *schema.ResourceDat
112118

113119
_ = d.Set("function_id", newRegionalID(region, cron.FunctionID).String())
114120
_ = d.Set("schedule", cron.Schedule)
115-
121+
_ = d.Set("name", cron.Name)
116122
args, err := scw.EncodeJSONObject(*cron.Args, scw.NoEscape)
117123
if err != nil {
118124
return diag.FromErr(err)
@@ -138,6 +144,7 @@ func resourceScalewayFunctionCronUpdate(ctx context.Context, d *schema.ResourceD
138144
req := &function.UpdateCronRequest{
139145
Region: region,
140146
CronID: cron.ID,
147+
Name: expandStringPtr(d.Get("name")),
141148
}
142149

143150
shouldUpdate := false

scaleway/resource_function_cron_test.go

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestAccScalewayFunctionCron_Basic(t *testing.T) {
6969
}
7070
7171
resource scaleway_function_cron main {
72+
name = "tf-tests-cron-basic"
7273
function_id = scaleway_function.main.id
7374
schedule = "0 0 * * *"
7475
args = jsonencode({})
@@ -77,6 +78,73 @@ func TestAccScalewayFunctionCron_Basic(t *testing.T) {
7778
Check: resource.ComposeTestCheckFunc(
7879
testAccCheckScalewayFunctionCronExists(tt, "scaleway_function_cron.main"),
7980
resource.TestCheckResourceAttr("scaleway_function_cron.main", "schedule", "0 0 * * *"),
81+
resource.TestCheckResourceAttr("scaleway_function_cron.main", "name", "tf-tests-cron-basic"),
82+
),
83+
},
84+
},
85+
})
86+
}
87+
88+
func TestAccScalewayFunctionCron_NameUpdate(t *testing.T) {
89+
tt := NewTestTools(t)
90+
defer tt.Cleanup()
91+
92+
resource.ParallelTest(t, resource.TestCase{
93+
PreCheck: func() { testAccPreCheck(t) },
94+
ProviderFactories: tt.ProviderFactories,
95+
CheckDestroy: testAccCheckScalewayFunctionCronDestroy(tt),
96+
Steps: []resource.TestStep{
97+
{
98+
Config: `
99+
resource scaleway_function_namespace main {
100+
name = "tf-tests-function-cron-basic"
101+
}
102+
103+
resource scaleway_function main {
104+
name = "tf-tests-cron-basic"
105+
namespace_id = scaleway_function_namespace.main.id
106+
runtime = "node14"
107+
privacy = "private"
108+
handler = "handler.handle"
109+
}
110+
111+
resource scaleway_function_cron main {
112+
name = "tf-tests-cron-basic"
113+
function_id = scaleway_function.main.id
114+
schedule = "0 0 * * *"
115+
args = jsonencode({})
116+
}
117+
`,
118+
Check: resource.ComposeTestCheckFunc(
119+
testAccCheckScalewayFunctionCronExists(tt, "scaleway_function_cron.main"),
120+
resource.TestCheckResourceAttr("scaleway_function_cron.main", "schedule", "0 0 * * *"),
121+
resource.TestCheckResourceAttr("scaleway_function_cron.main", "name", "tf-tests-cron-basic"),
122+
),
123+
},
124+
{
125+
Config: `
126+
resource scaleway_function_namespace main {
127+
name = "tf-tests-function-cron-with-args"
128+
}
129+
130+
resource scaleway_function main {
131+
name = "tf-tests-cron-with-args"
132+
namespace_id = scaleway_function_namespace.main.id
133+
runtime = "node14"
134+
privacy = "private"
135+
handler = "handler.handle"
136+
}
137+
138+
resource scaleway_function_cron main {
139+
name = "name-changed"
140+
function_id = scaleway_function.main.id
141+
schedule = "0 0 * * *"
142+
args = jsonencode({test = "scw"})
143+
}
144+
`,
145+
Check: resource.ComposeTestCheckFunc(
146+
testAccCheckScalewayFunctionCronExists(tt, "scaleway_function_cron.main"),
147+
resource.TestCheckResourceAttr("scaleway_function_cron.main", "name", "name-changed"),
80148
),
81149
},
82150
},
@@ -107,15 +175,15 @@ func TestAccScalewayFunctionCron_WithArgs(t *testing.T) {
107175
}
108176
109177
resource scaleway_function_cron main {
178+
name = "tf-tests-cron-with-args"
110179
function_id = scaleway_function.main.id
111180
schedule = "0 0 * * *"
112181
args = jsonencode({test = "scw"})
113182
}
114183
`,
115184
Check: resource.ComposeTestCheckFunc(
116185
testAccCheckScalewayFunctionCronExists(tt, "scaleway_function_cron.main"),
117-
resource.TestCheckResourceAttr("scaleway_function_cron.main", "schedule", "0 0 * * *"),
118-
resource.TestCheckResourceAttr("scaleway_function_cron.main", "args", "{\"test\":\"scw\"}"),
186+
resource.TestCheckResourceAttr("scaleway_function_cron.main", "name", "tf-tests-cron-with-args"),
119187
),
120188
},
121189
},

0 commit comments

Comments
 (0)