opsgenie / terraform-provider-opsgenie

Terraform OpsGenie provider
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs
Mozilla Public License 2.0
104 stars 137 forks source link

opsgenie_schedule_rotation time_restriction doesn't allow to set a rotation between 12 pm to 11:59 am #190

Open deshdeep-airwallex opened 4 years ago

deshdeep-airwallex commented 4 years ago

Terraform Version

Terraform v0.12.29

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Resource

resource "opsgenie_schedule_rotation" "main" {
  name        = "${var.team_name}-${var.rotation_type}-rotation"
  schedule_id = opsgenie_schedule.main.id
  start_date  = var.rotation_start_date
  type        = var.rotation_type
  length      = var.rotation_length

  dynamic "participant" {
    for_each = data.opsgenie_user.members

    content {
      type = "user"
      id   = participant.value.id
    }
  }

  time_restriction {
    type = "time-of-day"

    restriction {
      start_hour = var.rotation_start_hour
      start_min  = var.rotation_start_minute
      end_hour   = var.rotation_end_hour
      end_min    = var.rotation_end_minute
    }
  }
}

Terraform Input

module "ops_genie" {
  source = "git::https://terraform-opsgenie.git?ref=master"

  environment      = var.environment
  team_name        = "Team Name"
  team_description = "Team description"
  opsgenie_api_key = var.opsgenie_api_key

  users = var.opsgenie_users

  rotation_type       = "weekly"
  rotation_start_date = var.oncall_rotation_start_date
  rotation_start_hour = var.oncall_rotation_start_hour
  rotation_end_hour   = var.oncall_rotation_end_hour
}

Debug Output

image

Expected Behavior

Should allow to set a rotation between 12 pm to 11:59 am

Actual Behavior

As debug output above

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Is it possible to create time_restriction as both dynamic and optional object? I tried something like this but couldn't get it working.

Terraform opsgenie_schedule_rotation resource

resource "opsgenie_schedule_rotation" "main" {
  name        = "${var.team_name}-${var.rotation_type}-rotation"
  schedule_id = opsgenie_schedule.main.id
  start_date  = var.rotation_start_date
  type        = var.rotation_type
  length      = var.rotation_length

  dynamic "participant" {
    for_each = data.opsgenie_user.members

    content {
      type = "user"
      id   = participant.value.id
    }
  }

  dynamic "time_restriction" {
    for_each = try(var.time_restriction, [])
    content {
      type = time_restriction.value.type
      dynamic "restriction" {
        for_each = try(["time_restriction.restriction"], [])
        content {
          start_hour = time_restriction.restriction.value.start_hour
          start_min  = time_restriction.restriction.value.start_minute
          end_hour   = time_restriction.restriction.value.end_hour
          end_min    = time_restriction.restriction.value.end_minute
        }
      }
    }
  }
}
jaceq commented 4 years ago

@deshdeep-airwallex You don't show any values, what are you trying to set? show a full plan. As for second question it's a terraform question and not provider specific , I'd advice to look into terraform repo for help (but overall nested dynamic block do seem to be possible)

EDIT: in your second question do you mean a conditional block? if yes, have a look At this article -> in order to make combine conditional with dynamic modify the non-empty list given to foreach.       Interested in terraform? Check out my articles!