Skip to content

Commit 527f127

Browse files
committed
feat(container_cron): add name #2363
1 parent 538c279 commit 527f127

File tree

3 files changed

+358
-211
lines changed

3 files changed

+358
-211
lines changed

scaleway/resource_container_cron.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ func resourceScalewayContainerCron() *schema.Resource {
5151
Computed: true,
5252
Description: "Cron job status.",
5353
},
54+
"name": {
55+
Type: schema.TypeString,
56+
Optional: true,
57+
Computed: true,
58+
Description: "Cron job name",
59+
},
5460
"region": regionSchema(),
5561
},
5662
}
@@ -73,6 +79,7 @@ func resourceScalewayContainerCronCreate(ctx context.Context, d *schema.Resource
7379
ContainerID: containerID,
7480
Region: region,
7581
Schedule: schedule,
82+
Name: expandStringPtr(d.Get("name")),
7683
Args: &jsonObj,
7784
}
7885

@@ -117,6 +124,7 @@ func resourceScalewayContainerCronRead(ctx context.Context, d *schema.ResourceDa
117124
_ = d.Set("schedule", cron.Schedule)
118125
_ = d.Set("args", args)
119126
_ = d.Set("status", cron.Status)
127+
_ = d.Set("name", cron.Name)
120128

121129
return nil
122130
}
@@ -148,6 +156,11 @@ func resourceScalewayContainerCronUpdate(ctx context.Context, d *schema.Resource
148156
req.Args = &jsonObj
149157
}
150158

159+
if d.HasChange("name") {
160+
req.Name = scw.StringPtr(d.Get("name").(string))
161+
shouldUpdate = true
162+
}
163+
151164
if shouldUpdate {
152165
cron, err := api.UpdateCron(req, scw.WithContext(ctx))
153166
if err != nil {

scaleway/resource_container_cron_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestAccScalewayContainerCron_Basic(t *testing.T) {
2929
}
3030
3131
resource scaleway_container_cron main {
32+
name = "hello"
3233
container_id = scaleway_container.main.id
3334
schedule = "5 4 * * *" #cron at 04:05
3435
args = jsonencode({test = "scw"})
@@ -38,6 +39,31 @@ func TestAccScalewayContainerCron_Basic(t *testing.T) {
3839
testAccCheckScalewayContainerCronExists(tt, "scaleway_container_cron.main"),
3940
resource.TestCheckResourceAttr("scaleway_container_cron.main", "schedule", "5 4 * * *"),
4041
resource.TestCheckResourceAttr("scaleway_container_cron.main", "args", "{\"test\":\"scw\"}"),
42+
resource.TestCheckResourceAttr("scaleway_container_cron.main", "name", "hello"),
43+
),
44+
},
45+
{
46+
Config: `
47+
resource scaleway_container_namespace main {
48+
}
49+
50+
resource scaleway_container main {
51+
name = "my-container-with-cron-tf"
52+
namespace_id = scaleway_container_namespace.main.id
53+
}
54+
55+
resource scaleway_container_cron main {
56+
name = "salut"
57+
container_id = scaleway_container.main.id
58+
schedule = "5 4 * * *" #cron at 04:05
59+
args = jsonencode({test = "scw"})
60+
}
61+
`,
62+
Check: resource.ComposeTestCheckFunc(
63+
testAccCheckScalewayContainerCronExists(tt, "scaleway_container_cron.main"),
64+
resource.TestCheckResourceAttr("scaleway_container_cron.main", "schedule", "5 4 * * *"),
65+
resource.TestCheckResourceAttr("scaleway_container_cron.main", "args", "{\"test\":\"scw\"}"),
66+
resource.TestCheckResourceAttr("scaleway_container_cron.main", "name", "salut"),
4167
),
4268
},
4369
},

0 commit comments

Comments
 (0)