Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
fix validation
  • Loading branch information
yacut committed Oct 21, 2020
1 parent 206bd93 commit cc477e0
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
.terraform/
6 changes: 6 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=github
local_service?=alert_source
local_version?=0.1.5

default: build

Expand All @@ -12,6 +14,10 @@ tools:
build: fmtcheck
go install

build-local:
go build -o ./bin/terraform-provider-ilert
mv ./bin/terraform-provider-ilert ./examples/$(local_service)/.terraform/plugins/registry.terraform.io/ilert/ilert/$(local_version)/darwin_amd64/terraform-provider-ilert_v$(local_version)

fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w $(GOFMT_FILES)
Expand Down
19 changes: 19 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# iLert Provider Examples

This directory contains a set of examples of using various iLert resources with
Terraform. The examples each have their own README containing more details
on what the example does.

To run any example, clone the repository and run `terraform init`, `terraform plan`, and `terraform apply` within
the example's own directory.

For example:

```sh
git clone https://github.com/iLert/terraform-provider-ilert
cd terraform-provider-ilert/examples/alert_source
terraform init
terraform plan
terraform apply
...
```
21 changes: 21 additions & 0 deletions examples/alert_source/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Alert Source Example

This demos [alert sources](https://docs.ilert.com/getting-started/intro#alert-source-inbound-integration).

This example will create an alert source in the specified organization. See https://registry.terraform.io/providers/iLert/ilert/latest/docs for details on configuring [`providers.tf`](./providers.tf) accordingly.

Alternatively, you may use variables passed via command line:

```sh
export ILERT_ORGANIZATION=
export ILERT_USERNAME=
export ILERT_PASSWORD=
```

```sh
terraform apply \
-var "organization=${ILERT_ORGANIZATION}" \
-var "username=${ILERT_USERNAME}" \
-var "password=${ILERT_PASSWORD}" \
-var "escalation_policy=123456789
```
5 changes: 5 additions & 0 deletions examples/alert_source/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "ilert_alert_source" "example" {
name = "My Grafana Integration from terraform"
integration_type = "GRAFANA"
escalation_policy = var.escalation_policy_id
}
14 changes: 14 additions & 0 deletions examples/alert_source/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
ilert = {
source = "iLert/ilert"
version = "0.1.5"
}
}
}

provider "ilert" {
organization = var.organization
username = var.username
password = var.password
}
45 changes: 45 additions & 0 deletions examples/alert_source/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": 4,
"terraform_version": "0.13.4",
"serial": 7,
"lineage": "8c0378c7-c3c6-22e1-754c-3483bb89f9f2",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "ilert_alert_source",
"name": "example",
"provider": "provider[\"registry.terraform.io/ilert/ilert\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"active": true,
"autotask_metadata": [],
"dark_icon_url": "https://cdn.ilert.com/javax.faces.resource/source_icons/_dark/grafana.png.jsf?ln=images",
"email_filtered": false,
"email_predicates": [],
"email_resolve_filtered": false,
"email_resolve_predicates": [],
"escalation_policy": "2195678",
"filter_operator": "AND",
"heartbeat": [],
"icon_url": "https://cdn.ilert.com/javax.faces.resource/source_icons/grafana.png.jsf?ln=images",
"id": "2208782",
"incident_creation": "ONE_INCIDENT_PER_EMAIL",
"incident_priority_rule": "HIGH",
"integration_key": "il1gra1020fe0c6ef61f264937b782b84d9886cafd4c928ae1cf",
"integration_type": "GRAFANA",
"light_icon_url": "https://cdn.ilert.com/javax.faces.resource/source_icons/_light/grafana.png.jsf?ln=images",
"name": "My Grafana Integration from terraform",
"resolve_filter_operator": "AND",
"resolve_key_extractor": [],
"status": "ALL_RESOLVED",
"support_hours": []
},
"private": "bnVsbA=="
}
]
}
]
}
23 changes: 23 additions & 0 deletions examples/alert_source/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "organization" {
description = "iLert organization used to configure the provider"
type = string
default = "yacut"
}

variable "username" {
description = "iLert username used to configure the provider"
type = string
default = "yacut"
}

variable "password" {
description = "iLert password used to configure the provider"
type = string
default = "kZjgEKL4guyCTQY"
}

variable "escalation_policy_id" {
description = "iLert escalation policy id used for alert source"
type = number
default = 2195678
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/hcl/v2 v2.6.0 // indirect
github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/iLert/ilert-go v1.0.3
github.com/iLert/ilert-go v1.0.4
github.com/zclconf/go-cty v1.5.1 // indirect
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
golang.org/x/net v0.0.0-20201020065357-d65d470038a5 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ github.com/iLert/ilert-go v1.0.1/go.mod h1:P52Sxj8CCa8PfDRl95dtM5FsOzDc5SgETLRRo
github.com/iLert/ilert-go v1.0.2/go.mod h1:P52Sxj8CCa8PfDRl95dtM5FsOzDc5SgETLRRoWXsQOM=
github.com/iLert/ilert-go v1.0.3 h1:IR0s4d3bOXvJkkaSfrWyC3D/zsK34JbSSxOdvnDb3Rs=
github.com/iLert/ilert-go v1.0.3/go.mod h1:P52Sxj8CCa8PfDRl95dtM5FsOzDc5SgETLRRoWXsQOM=
github.com/iLert/ilert-go v1.0.4 h1:/6lExbPzhkMJ3Yy8Ln/rsLhHbmAsvtBLAY5mtQJCcXw=
github.com/iLert/ilert-go v1.0.4/go.mod h1:P52Sxj8CCa8PfDRl95dtM5FsOzDc5SgETLRRoWXsQOM=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down Expand Up @@ -408,6 +410,8 @@ golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6f
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201020065357-d65d470038a5 h1:KrxvpY64uUzANd9wKWr6ZAsufiii93XnvXaeikyCJ2g=
golang.org/x/net v0.0.0-20201020065357-d65d470038a5/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
Expand Down
28 changes: 12 additions & 16 deletions ilert/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,24 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("ILERT_ENDPOINT", ""),
},
"api_token": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_API_TOKEN", ""),
ConflictsWith: []string{"organization", "username", "password"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_API_TOKEN", ""),
},
"organization": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_ORGANIZATION", ""),
ConflictsWith: []string{"api_token"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_ORGANIZATION", ""),
},
"username": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_USERNAME", ""),
ConflictsWith: []string{"api_token"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_USERNAME", ""),
},
"password": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_PASSWORD", ""),
ConflictsWith: []string{"api_token"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ILERT_PASSWORD", ""),
},
},
DataSourcesMap: map[string]*schema.Resource{
Expand Down
Loading

0 comments on commit cc477e0

Please sign in to comment.