Skip to content
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

SH-183 Add example of fetching on-call users' emails #90

Merged
merged 2 commits into from
Jun 5, 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
17 changes: 17 additions & 0 deletions examples/on_call_calendars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This directory contains a sample Terraform configuration for extracting current on-call
user's email address for your primary on-call calendar, and a secondary one (fetched by name)

## Usage

```shell script
git clone https://github.com/BetterStackHQ/terraform-provider-better-uptime && \
cd terraform-provider-better-uptime/examples/on_call_calendars

echo '# See variables.tf for more.
betteruptime_api_token = "XXXXXXXXXXXXXXXXXXXXXXXX"
betteruptime_secondary_calendar_name = "My secondary calendar"
' > terraform.tfvars

terraform init
terraform apply
```
9 changes: 9 additions & 0 deletions examples/on_call_calendars/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "betteruptime" {
api_token = var.betteruptime_api_token
}

data "betteruptime_on_call_calendar" "primary" {}

data "betteruptime_on_call_calendar" "secondary" {
name = var.betteruptime_secondary_calendar_name
}
12 changes: 12 additions & 0 deletions examples/on_call_calendars/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
locals {
primary_on_calls = data.betteruptime_on_call_calendar.primary.on_call_users
secondary_on_calls = data.betteruptime_on_call_calendar.secondary.on_call_users
}

output "on_call_primary" {
value = length(local.primary_on_calls) > 0 ? local.primary_on_calls[0].email : "Nobody on call!"
}

output "on_call_secondary" {
value = local.secondary_on_calls != null ? (length(local.secondary_on_calls) > 0 ? local.secondary_on_calls[0].email : "Nobody on call!") : "Secondary calendar not found!"
}
17 changes: 17 additions & 0 deletions examples/on_call_calendars/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "betteruptime_api_token" {
type = string
description = <<EOF
Better Stack Uptime API Token
(https://betterstack.com/docs/uptime/api/getting-started-with-uptime-api/#obtaining-an-uptime-api-token)
EOF
# The value can be omitted if BETTERUPTIME_API_TOKEN env var is set.
default = null
}

variable "betteruptime_secondary_calendar_name" {
type = string
description = <<EOF
The name of your secondary on-call calendar.
EOF
default = "Secondary calendar"
}
10 changes: 10 additions & 0 deletions examples/on_call_calendars/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.13"
required_providers {
betteruptime = {
source = "BetterStackHQ/better-uptime"
# https://github.com/BetterStackHQ/terraform-provider-better-uptime/blob/master/CHANGELOG.md
version = ">= 0.9.0"
}
}
}
Loading