Skip to content

Commit

Permalink
Merge pull request #96 from iLert/feature/deployment-pipeline
Browse files Browse the repository at this point in the history
Feature/deployment pipeline
  • Loading branch information
STLVRTX authored Nov 17, 2024
2 parents 3ffb306 + 13e1c84 commit 9dc39c5
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 17.11.2024, Version 2.11.0

- feature/deployment-pipeline in [#96](https://github.com/iLert/terraform-provider-ilert/pull/96)

## 01.10.2024, Version 2.10.0

- feature/alert-action-conditions-field in [#94](https://github.com/iLert/terraform-provider-ilert/pull/94)
Expand Down
16 changes: 16 additions & 0 deletions examples/deployment_pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Deployment pipeline example

This demos [deployment pipeline](https://docs.ilert.com/deployment-integrations).

This example will create a deployment pipeline resource 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_API_TOKEN=
```

```sh
terraform apply \
-var "api_token=${ILERT_API_TOKEN}" \
```
8 changes: 8 additions & 0 deletions examples/deployment_pipeline/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "ilert_deployment_pipeline" "example" {
name = "example"
integration_type = "GITHUB"
github {
branch_filter = ["main", "master"]
event_filter = ["release"]
}
}
13 changes: 13 additions & 0 deletions examples/deployment_pipeline/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
ilert = {
source = "iLert/ilert"
version = "~> 2.0"
}
}
}

provider "ilert" {
endpoint = var.endpoint
api_token = var.api_token
}
10 changes: 10 additions & 0 deletions examples/deployment_pipeline/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "api_token" {
description = "ilert API token used to configure the provider"
type = string
}

variable "endpoint" {
description = "ilert organization used to configure the provider"
type = string
default = "https://api.ilert.com"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
github.com/iLert/ilert-go/v3 v3.10.1
github.com/iLert/ilert-go/v3 v3.11.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iLert/ilert-go/v3 v3.10.1 h1:VNzm+WIBj8wgNOKNQFs/XEhTjoHR4IskbXiA/RKDQKY=
github.com/iLert/ilert-go/v3 v3.10.1/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0=
github.com/iLert/ilert-go/v3 v3.11.0 h1:h2FFGRO2fIaI6Ot24KXQ2/idUVBpcY2YBXbZaIUDiUU=
github.com/iLert/ilert-go/v3 v3.11.0/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down
65 changes: 65 additions & 0 deletions ilert/data_source_deployment_pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ilert

import (
"context"
"fmt"
"log"
"strconv"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/iLert/ilert-go/v3"
)

func dataSourceDeploymentPipeline() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceDeploymentPipelineRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceDeploymentPipelineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*ilert.Client)

log.Printf("[DEBUG] Reading ilert deployment pipeline")

searchName := d.Get("name").(string)

err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *resource.RetryError {
resp, err := client.SearchDeploymentPipeline(&ilert.SearchDeploymentPipelineInput{DeploymentPipelineName: &searchName})
if err != nil {
if _, ok := err.(*ilert.RetryableAPIError); ok {
time.Sleep(2 * time.Second)
return resource.RetryableError(fmt.Errorf("waiting for deployment pipeline with name '%s' to be read, error: %s", searchName, err.Error()))
}
return resource.NonRetryableError(fmt.Errorf("could not read a deployment pipeline with name: %s, error: %s", searchName, err.Error()))
}

found := resp.DeploymentPipeline

if found == nil {
return resource.NonRetryableError(
fmt.Errorf("unable to locate any deployment pipeline with the name: %s", searchName),
)
}

d.SetId(strconv.FormatInt(found.ID, 10))
d.Set("name", found.Name)

return nil
})

if err != nil {
return diag.FromErr(err)
}

return nil
}
2 changes: 2 additions & 0 deletions ilert/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func Provider() *schema.Provider {
"ilert_alert_source": dataSourceAlertSource(),
"ilert_connection": dataSourceConnection(),
"ilert_connector": dataSourceConnector(),
"ilert_deployment_pipeline": dataSourceDeploymentPipeline(),
"ilert_escalation_policy": dataSourceEscalationPolicy(),
"ilert_incident_template": dataSourceIncidentTemplate(),
"ilert_metric": dataSourceMetric(),
Expand All @@ -66,6 +67,7 @@ func Provider() *schema.Provider {
"ilert_automation_rule": resourceAutomationRule(),
"ilert_connection": resourceConnection(),
"ilert_connector": resourceConnector(),
"ilert_deployment_pipeline": resourceDeploymentPipeline(),
"ilert_escalation_policy": resourceEscalationPolicy(),
"ilert_incident_template": resourceIncidentTemplate(),
"ilert_metric": resourceMetric(),
Expand Down
Loading

0 comments on commit 9dc39c5

Please sign in to comment.