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

reintroduce spinnaker_pipeline_document pipeline data source #36

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e025e22
implement spinnaker_pipeline_document data source
pasternak Mar 20, 2019
87dee8f
add preconditions to stages
pasternak Apr 1, 2019
e037006
a bit of code refactoring
pasternak Apr 2, 2019
0526bd1
add ForceNew to application within resource_application
pasternak Apr 3, 2019
45033e1
Options is actually a list of maps
vjanelle May 16, 2019
e6b3f8f
split pipeline stage in a set of separate structs
pasternak Jul 23, 2019
f52adcb
add new spinnaker_pipelines data source
pasternak Jul 23, 2019
ce66173
override stage by id, not name
pasternak Jul 23, 2019
d121baa
add (runJob,deploy,patch)Manifest stage types
pasternak Jul 23, 2019
cf85d7c
get spinnaker_pipeline_document tests aligned with the data source
pasternak Jul 23, 2019
58a6cbf
Add initial documentation for the spinnaker_pipeline_document
pasternak Jul 23, 2019
d1a8ddb
add findArtifactsFromResource stage type
pasternak Aug 1, 2019
8f9db17
default pipeline parameter to empty string
pasternak Aug 2, 2019
25d9349
Add docs related to data.spinnaker_pipeline_document
pasternak Aug 19, 2019
e9e9ee2
for k8s v2 default cloud_provider to kubernetes
pasternak Aug 20, 2019
7cae269
Add support for multiple documents in a single yaml manifest
Aug 28, 2019
cfd8f64
Create and append each manifest individually
Aug 28, 2019
9bb1392
Notificationsssssssssssssss
jwoodsw Sep 4, 2019
e5b80c7
Added cron trigger support
jwoodsw Sep 4, 2019
39932cb
Fix lint and tests.
jwoodsw Sep 4, 2019
139c3d9
implement lock and disable pipeline
pasternak Oct 3, 2019
96c9254
Add failure_message field to a precondition stage
Oct 9, 2019
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ resource "spinnaker_pipeline" "terraform_example" {
application = "${spinnaker_application.my_app.application}"
name = "Example Pipeline"
pipeline = file("pipelines/example.json")
lock = true
disable = true
}
```

Expand All @@ -96,6 +98,11 @@ resource "spinnaker_pipeline" "terraform_example" {
* `application` - Application name
* `name` - Pipeline name
* `pipeline` - Pipeline JSON in string format, example `file(pipelines/example.json)`
* `lock` - Lock the edit of pipelines in the UI
* `disable` - Disable a pipeline for the execution


## Data source

### `spinnaker_pipeline_template`

Expand Down Expand Up @@ -132,3 +139,6 @@ resource "spinnaker_pipeline_template_config" "terraform_example" {
#### Argument Reference

* `pipeline_config` - A yaml formated [DCD Spec pipeline configuration](https://github.com/spinnaker/dcd-spec/blob/master/PIPELINE_TEMPLATES.md#configurations)


### [`spinnaker_pipeline_document`](docs/data.spinnaker_pipeline_document.md)
97 changes: 97 additions & 0 deletions docs/data.spinnaker_pipeline_document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Data Source: spinnaker_pipeline_document

Generates a spinnaker pipeline definition in JSON format


This is a data source which can be used to construct a JSON representation of a Spinnaker pipeline, for use
with either another document or the `spinnaker_pipeline` resource.

```hcl
data "spinnaker_pipeline_document" "example" {
description = "Description or the example pipeline"
wait = false
limit_concurrent = false

parameter {
description = "The description of the parameter"
default = "default value"
name = "PARAMETER1"
required = true
}

parameter {
name = "ENVIRONMENT"
required = false
options = [
"prod",
"preprod",
]
}

stage {
name = "Evaluate variables"
fail_on_failed_expression = true
id = 1
type = "evaluateVariables"

variables {
VARIABLE_NAME = "$${parameters.PARAMETER1}"
OTHER_VARIABLE = "$${parameters.ENVIRONMENT.toString().equals("preprod") ? "notProd" : "notPreprod" }
}
}
}

resource "spinnaker_pipeline" "example" {
application = "app1"
name = "example"
pipeline = "${data.spinnaker_pipeline_document.example.json}"
}

```

Using this data source to generate policy documents is optional. It is also valid to use literal JSON strings within your configuration, or to use the file interpolation function to read a raw JSON policy document from a file.


## Argument Reference

The following arguments are supported:

- `description` (optional) - A description of the Pipeline
- `wait` (optional) - Do not automatically cancel pipelines waiting in queue. If concurrent pipeline execution is disabled, then the pipelines that are in the waiting queue will get canceled when the next execution starts. Defaults to `false`
- `limit_concurrent` (optional) - Disable concurrent pipeline executions (only run one at a time). Defaults to `false`.
- `parameter` (optional) - A nested configuration block (described below) configuring one _parameter_ to be included in the pipeline document.
- `stage` (optional) - A nested configuration block (described below) configuring one _stage_ to be included in the pipeline document.
- `source_json` (optional) - A JSON formated string containing a base for the pipeline document. Might contain parameters, stages etc. The document, can override the source json. For _parameter_ by defining new parameter with the same name. For _stage_ by defining new stage with the same id.
- `override_json` (optional) - A JSON formated string containing an override for the pipeline document. Might contain parameters, stages etc. The document, can override the source json. For _parameter_ by defining new parameter with the same name. For _stage_ by defining new stage with the same id.

Each document configuration can have one or more `parameter` blocks, which each accept the following arguments:
- `description` (optional) - A description for the parameter.
- `default` (optional) - A default value.
- `name` - The name of the Parameter.
- `required` (optional) - A switch to set the parameter to be required for the execution. Defaults to `false`
- `options` (optional) - An array with allowed values for the Parameter.

Each document configuration can have one or more `stage` blocks, which each accept the following arguments:
- `name` - A name of the stage.
- `id` (optional) - An ID of the stage in the pipeline. Being used to order the stages and build the dependencies. If not provided it calculetes the number by the order in the HCL.
- `depends_on` (optional) - A list of the _id_ the stage depends on.
- `type` - A type of the stage (described below).
- `stage_enabled` (optional) - A block consisting of `expression` key controlling the execution pipeline. Can use SPEL to control if either stage will be run or not.
- `fail_on_failed_expression` (optional) - Fails the pipeline if the expression in the stage fails.
- `continue_pipeline` (optional) - Ignores the failure. Continues of downstream stages.
- `fail_pipeline` (optional) - Halts the entire pipeline. Immediately halts execution of all running stages and fails the entire execution.
- `complete_other_branches_then_fail` (optional) - Halt this stage and fail the pipeline once other branches complete. Prevents any stages that depend on this stage from running, but allows other branches of the pipeline to run. The pipeline will be marked as failed once complete.
- `timeout` (optional) - Sets the custom timeout for the stage execution.

Depends on the specified `type` field _stage_ block can accept multiple different arguments:

- [runJob (Runs a container.)](spinnaker_pipeline_document/runJob.md)
- [evaluateVariables (Evaluates variables for use in SpEL.)](spinnaker_pipeline_document/evaluateVariables.md)
- [checkPreconditions (Checks for preconditions before continuing.)](spinnaker_pipeline_document/checkPreconditions.md)
- [manualJudgment (Waits for user approval before continuing.)](spinnaker_pipeline_document/manualJudgment.md)
- [runJobManifest (Run a Kubernetes Job manifest yaml/json file.)](spinnaker_pipeline_document/runJobManifest.md)
- [deployManifest (Deploy a Kubernetes manifest yaml/json file.)](spinnaker_pipeline_document/deployManifest.md)
- [patchManifest (Patch a Kubernetes object in place.)](spinnaker_pipeline_document/patchManifest.md)
- [findArtifactsFromResource (Finds artifact from Kubernetes resource.)](spinnaker_pipeline_document/findArtifactsFromResource.md)
- [pipeline (Runs a pipeline)](spinnaker_pipeline_document/pipeline.md)
- [wait (Waits a specified period of time.)](spinnaker_pipeline_document/wait.md)
32 changes: 32 additions & 0 deletions docs/spinnaker_pipeline_document/checkPreconditions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Checks for preconditions before continuing.


```hcl
data "spinnaker_pipeline_document" "example" {
stage {
name = "...."
type = "checkPreconditions"

precondition {
context {
expression = "$${#stage("plan")["outputs"]["jobStatus"]["logs"].toString().split("PLAN_EXITSTATUS")[1].equals("0")}"
failure_message = "This is a failure message"
}

fail_pipeline = false
type = "expression"
}
}
}
```

## Argument Reference

The following arguments are supported:

- `precondition` - A nested configuration block (described below) configuring precondition for the stage.
- `context` - A nested configuration block with the `expression` setting (only supported at this stage)
- `expression` - A SpEL expression returing either `true` or `false`
- `failure_message` - This failure message will be shown to the user if the precondition evaluates to false.
- `fail_pipeline` - If set to `true` the overall pipeline will fail whenever this precondition is false.
- `type` - the type of the precondition. At this stage only `expression` is being supported.
27 changes: 27 additions & 0 deletions docs/spinnaker_pipeline_document/deployManifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Deploy a Kubernetes manifest yaml/json file.

```hcl
data "spinnaker_pipeline_document" "example" {
stage {
name = "...."
namespace = "default"
account = "spinnaker-registered-kubernetes-account"

manifest = "${data.template_file.example.rendered}"

moniker {
app = "${spinnaker_application.app.application}"
}
}
}
```

## Argument Reference

The following arguments are supported:

- `namespace` - The namespace the pod will be deployed into.
- `account` - The name of the kubernetes spinnaker account name to deploy the pod to.
- `cloud_provider` (optional) - The clouddriver's driver name. Defaults to `kubernetes`
- `source` - The field specifies the source of the manifest. At this stage only `text` is being supported.
- `moniker` (optional) - Configures custom moniker for the runJob. Used for custom annotations, see [docs](https://www.spinnaker.io/reference/providers/kubernetes-v2/#moniker)
23 changes: 23 additions & 0 deletions docs/spinnaker_pipeline_document/evaluateVariables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Evaluate variables

Evaluates variables for use in SpEL.

```hcl
data "spinnaker_pipeline_document" "example" {
stage {
name = "...."

variables {
VAR = "some SpEL expression here"
}

type = "evaluateVariables"
}
}
```

## Argument Reference

The following arguments are supported:

- `variables` - A nested configuration block. Consists of Key/Value set.
25 changes: 25 additions & 0 deletions docs/spinnaker_pipeline_document/findArtifactsFromResource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Finds artifact from Kubernetes resource.

```hcl
data "spinnaker_pipeline_document" "example" {
stage {
account = "kubernetes-account-name-registered-with-spinnaker"

namespace = "kube-system"
kind = "configmap"
manifest = "aws-auth"

type = "findArtifactsFromResource"
}
}
```

## Argument Reference

The following arguments are supported:

- `account` - The name of the kubernetes account registered with the spinnaker
- `cloud_provider` (optional) - The clouddriver's driver. Defaults to `kubernetes`
- `namespace` - The namespace to look into for the artifact
- `kind` - The kind of the kubernetes resource.
- `manifest` - The object to query for.
20 changes: 20 additions & 0 deletions docs/spinnaker_pipeline_document/manualJudgment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Waits for user approval before continuing.


```hcl
data "spinnaker_pipeline_document" "example" {
stage {
name = "...."
instructions = "Are you sure you want to proceed?"
judgment_inputs = ["Continue", "Exit"]
type = "manualJudgment"
}
}
```

## Argument Reference

The following arguments are supported:

- `instructions` - A string to display for the manual judgment step.
- `judgment_inputs` - An array of available options for the stage.
20 changes: 20 additions & 0 deletions docs/spinnaker_pipeline_document/patchManifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Patch a Kubernetes object in place.

```hcl
data "spinnaker_pipeline_document" "example" {
stage {
type = "patchManifest"
location = "kube-system"
mode = "static"
patch_body = "${data.template_file.template.rendered}"
}
}
```

## Argument Reference

The following arguments are supported:

- `locatiom` - The namespace the object to patch reside within
- `mode` - The patchManifest type, see [docs](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/)
- `patch_body` - The JSON rendered patch manifest. For more see [here](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/)
22 changes: 22 additions & 0 deletions docs/spinnaker_pipeline_document/pipeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Runs external pipeline.

```hcl
data "spinnaker_pipeline_document" "example" {
stage {
application = "name of the application, pipeline resides within"
pipeline = "id"

pipeline_parameters = {
PIPELINE_PARAMETER1 = "$${parameters["PARAMETER1"]}"
}
}
}
```

## Argument Reference

The following arguments are supported:

- `application` - The name of the application, where the pipeline is being setup.
- `pipeline` - The pipeline's UUID. Can be sourced either via data source or referenced by resource id.
- `pipeline_parameters` - The Key/Value of the parameters to be passed down the chain to the pipeline.
78 changes: 78 additions & 0 deletions docs/spinnaker_pipeline_document/runJob.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Run Job (kubernetes v1 provider)

Creates a kubernetes Job using kubernetes v1 provider.

```hcl
data "spinnaker_pipeline_document" "example" {
stage {
name = "example"
namespace = "default"
account = "spinnaker-registered-account"
cloud_provider = "kubernetes"
cloud_provider_type = "kubernetes"

container {
name = "the-name-of-the-container"
image_pull_policy = "ALWAYS"

command = [
"/path/to/the/command.sh",
]

args = [
"arg1",
"arg2",
]

env {
VARIABLE = "$${parameters.PARAM}"
VARIABLE2 = "VALUE"
}

image {
account = "gcr"
id = "gcr.io/$${parameters.IMAGE}"
registry = "gcr.io"
repository = "$${parameters.REPO}"
tag = "latest"
}

ports {
container = 80
name = "http"
protocol = "TCP"
}
}

type = "runJob"
}
}
```

## Argument Reference

The following arguments are supported:

- `name` - The human readable name of the stage.
- `namespace` - The kubernetes namespace to execute the container within.
- `account` - The kubernetes account name registered with the spinnaker.
- `cloud_provider` - The clouddriver's driver. Should default to `kubernetes`
- `cloud_provider_type` - The clouddriver's driver.
- `container` - A nested configuration block (described below) configuring one _container_to be included in the stage definition.

Each document configuration can have one ot more `container` blocks, which each accept the following arguments:
- `name` - the unique name of the container.
- `image_pull_policy` (optional) - the image pull policy, for more see [here](https://kubernetes.io/docs/concepts/containers/images/#updating-images)
- `command` (optional) - an list of commands to run in the container.
- `args` (optional) - a list of arguments to be passed to the commands.
- `env` (optional) - a nested configuration of key/value for passing env variables to the container.
- `image` - a nested configuration block for defining image source.
- `account` - the account of the image
- `id` - An ID of the image
- `registry` - An image registry url
- `repository` - A repository path within the given registry
- `tag` - A tag of the image. Defaults to `latest`
- `ports` (optional) - A nested configuration block.
- `container` - A port to be exposed on the container end.
- `name` - The name of the port
- `protocol` - The supported protocol for the port
Loading