Skip to content

feat(container_cron): add name #2366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/resources/container_cron.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource scaleway_container main {

resource scaleway_container_cron main {
container_id = scaleway_container.main.id
name = "my-cron-name"
schedule = "5 4 1 * *" #cron at 04:05 on day-of-month 1
args = jsonencode(
{
Expand All @@ -54,13 +55,15 @@ resource scaleway_container_cron main {

## Argument Reference

The following arguments are required:
The following arguments are supported:

- `schedule` - (Required) Cron format string, e.g. @hourly, as schedule time of its jobs to be created and
executed.
- `container_id` - (Required) The container ID to link with your cron.
- `args` - (Required) The key-value mapping to define arguments that will be passed to your container’s event object
during
- `name` - (Optional) The name of the container cron. If not provided, the name is generated.
during

## Attributes Reference

Expand Down
13 changes: 13 additions & 0 deletions scaleway/resource_container_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func resourceScalewayContainerCron() *schema.Resource {
Computed: true,
Description: "Cron job status.",
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Cron job name",
},
"region": regionSchema(),
},
}
Expand All @@ -73,6 +79,7 @@ func resourceScalewayContainerCronCreate(ctx context.Context, d *schema.Resource
ContainerID: containerID,
Region: region,
Schedule: schedule,
Name: expandStringPtr(d.Get("name")),
Args: &jsonObj,
}

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

return nil
}
Expand Down Expand Up @@ -148,6 +156,11 @@ func resourceScalewayContainerCronUpdate(ctx context.Context, d *schema.Resource
req.Args = &jsonObj
}

if d.HasChange("name") {
req.Name = scw.StringPtr(d.Get("name").(string))
shouldUpdate = true
}

if shouldUpdate {
cron, err := api.UpdateCron(req, scw.WithContext(ctx))
if err != nil {
Expand Down
26 changes: 26 additions & 0 deletions scaleway/resource_container_cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccScalewayContainerCron_Basic(t *testing.T) {
}

resource scaleway_container_cron main {
name = "tf-tests-container-cron-basic"
container_id = scaleway_container.main.id
schedule = "5 4 * * *" #cron at 04:05
args = jsonencode({test = "scw"})
Expand All @@ -38,6 +39,31 @@ func TestAccScalewayContainerCron_Basic(t *testing.T) {
testAccCheckScalewayContainerCronExists(tt, "scaleway_container_cron.main"),
resource.TestCheckResourceAttr("scaleway_container_cron.main", "schedule", "5 4 * * *"),
resource.TestCheckResourceAttr("scaleway_container_cron.main", "args", "{\"test\":\"scw\"}"),
resource.TestCheckResourceAttr("scaleway_container_cron.main", "name", "tf-tests-container-cron-basic"),
),
},
{
Config: `
resource scaleway_container_namespace main {
}

resource scaleway_container main {
name = "my-container-with-cron-tf"
namespace_id = scaleway_container_namespace.main.id
}

resource scaleway_container_cron main {
name = "tf-tests-container-cron-basic-changed"
container_id = scaleway_container.main.id
schedule = "5 4 * * *" #cron at 04:05
args = jsonencode({test = "scw"})
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayContainerCronExists(tt, "scaleway_container_cron.main"),
resource.TestCheckResourceAttr("scaleway_container_cron.main", "schedule", "5 4 * * *"),
resource.TestCheckResourceAttr("scaleway_container_cron.main", "args", "{\"test\":\"scw\"}"),
resource.TestCheckResourceAttr("scaleway_container_cron.main", "name", "tf-tests-container-cron-basic-changed"),
),
},
},
Expand Down
Loading