Skip to content

Commit

Permalink
Merge pull request #23322 from mattburgess/imagebuilder-pipeline-time…
Browse files Browse the repository at this point in the history
…zone

imagebuilder/image_pipeline: Add `schedule.timezone` parameter
  • Loading branch information
ewbankkit authored Feb 22, 2022
2 parents 9d1d43e + c453352 commit 3980f3e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/23322.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_imagebuilder_image_pipeline: Add `schedule.timezone` argument
````
16 changes: 16 additions & 0 deletions internal/service/imagebuilder/image_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ func ResourceImagePipeline() *schema.Resource {
Required: true,
ValidateFunc: validation.StringLenBetween(1, 1024),
},
"timezone": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.All(
validation.StringLenBetween(3, 100),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9]{2,}(?:\/[a-zA-z0-9-_+]+)*`), "")),
},
},
},
},
Expand Down Expand Up @@ -402,6 +410,10 @@ func expandPipelineSchedule(tfMap map[string]interface{}) *imagebuilder.Schedule
apiObject.ScheduleExpression = aws.String(v)
}

if v, ok := tfMap["timezone"].(string); ok && v != "" {
apiObject.Timezone = aws.String(v)
}

return apiObject
}

Expand Down Expand Up @@ -438,5 +450,9 @@ func flattenSchedule(apiObject *imagebuilder.Schedule) map[string]interface{} {
tfMap["schedule_expression"] = aws.StringValue(v)
}

if v := apiObject.Timezone; v != nil {
tfMap["timezone"] = aws.StringValue(v)
}

return tfMap
}
53 changes: 53 additions & 0 deletions internal/service/imagebuilder/image_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,43 @@ func TestAccImageBuilderImagePipeline_Schedule_scheduleExpression(t *testing.T)
})
}

func TestAccImageBuilderImagePipeline_Schedule_timezone(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_imagebuilder_image_pipeline.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, imagebuilder.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckImagePipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccImagePipelineScheduleTimezoneConfig(rName, "cron(1 0 * * ? *)", "Etc/UTC"),
Check: resource.ComposeTestCheckFunc(
testAccCheckImagePipelineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "schedule.#", "1"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.schedule_expression", "cron(1 0 * * ? *)"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.timezone", "Etc/UTC"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccImagePipelineScheduleTimezoneConfig(rName, "cron(1 0 * * ? *)", "America/Los_Angeles"),
Check: resource.ComposeTestCheckFunc(
testAccCheckImagePipelineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "schedule.#", "1"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.schedule_expression", "cron(1 0 * * ? *)"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.timezone", "America/Los_Angeles"),
),
},
},
})
}

func TestAccImageBuilderImagePipeline_status(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_imagebuilder_image_pipeline.test"
Expand Down Expand Up @@ -896,6 +933,22 @@ resource "aws_imagebuilder_image_pipeline" "test" {
`, rName, scheduleExpression))
}

func testAccImagePipelineScheduleTimezoneConfig(rName string, scheduleExpression string, timezone string) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseConfig(rName),
fmt.Sprintf(`
resource "aws_imagebuilder_image_pipeline" "test" {
image_recipe_arn = aws_imagebuilder_image_recipe.test.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn
name = %[1]q
schedule {
schedule_expression = %[2]q
timezone = %[3]q
}
}
`, rName, scheduleExpression, timezone))
}
func testAccImagePipelineStatusConfig(rName string, status string) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseConfig(rName),
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/imagebuilder_image_pipeline.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ The following arguments are optional:

* `pipeline_execution_start_condition` - (Optional) Condition when the pipeline should trigger a new image build. Valid values are `EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE` and `EXPRESSION_MATCH_ONLY`. Defaults to `EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE`.

* `timezone` - (Optional) The timezone that applies to the scheduling expression. For example, "Etc/UTC", "America/Los_Angeles" in the [IANA timezone format](https://www.joda.org/joda-time/timezones.html). If not specified this defaults to UTC.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down

0 comments on commit 3980f3e

Please sign in to comment.