-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from iLert/feature/deployment-pipeline
Feature/deployment pipeline
- Loading branch information
Showing
12 changed files
with
582 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" \ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.