Skip to content

Commit

Permalink
Required weekday field for teamcity_build_trigger_schedule with weekl…
Browse files Browse the repository at this point in the history
…y schedule (#14)

For teamcity_build_trigger_schedule resources, if the schedule is weekly, the weekday field must be set
  • Loading branch information
rjh-yext authored Dec 6, 2022
1 parent 95dcbb4 commit e8756c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion teamcity/resource_build_trigger_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package teamcity

import (
"fmt"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -194,7 +195,10 @@ func resourceBuildTriggerScheduleCreate(d *schema.ResourceData, meta interface{}
timezone := d.Get("timezone").(string)
rules := expandStringSlice(d.Get("rules").([]interface{}))
schedule := d.Get("schedule").(string)
weekday, _ := parseWeekday(d.Get("weekday").(string))
weekday, err := parseWeekday(d.Get("weekday").(string))
if err != nil {
return err
}

opt, err := expandTriggerScheduleOptions(d)
if err != nil {
Expand All @@ -210,6 +214,13 @@ func resourceBuildTriggerScheduleCreate(d *schema.ResourceData, meta interface{}
}
}

if strings.EqualFold(schedule, "weekly") {
triggerWeekday, ok := d.GetOk("weekday")
if !ok {
return fmt.Errorf("weekday is required if a schedule of weekly is chosen")
}
}

dt, err := api.NewTriggerSchedule(schedule, buildConfigID, weekday, uint(hour), uint(minute), timezone, rules, cronSchedule, opt)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions teamcity/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package teamcity

import (
"fmt"
"strings"
"time"
)

var daysOfWeek = map[string]time.Weekday{}

func init() {
for d := time.Sunday; d <= time.Saturday; d++ {
daysOfWeek[d.String()] = d
daysOfWeek[strings.ToLower(d.String())] = d
}
}

func parseWeekday(v string) (time.Weekday, error) {
if d, ok := daysOfWeek[v]; ok {
if d, ok := daysOfWeek[strings.ToLower(v)]; ok {
return d, nil
}

Expand Down

0 comments on commit e8756c8

Please sign in to comment.