esp.terraform.tfe_run (0.1.0) — module

Create, apply, discard or cancel a run

| "added in version" 0.1.0 of esp.terraform"

Authors: Krzysztof Lewandowski (@klewan)

Install collection

Install with ansible-galaxy collection install esp.terraform:==0.1.0


Add to requirements.yml

  collections:
    - name: esp.terraform
      version: 0.1.0

Description

Creates, applies, discards or cancels a run.

When creating a run, it takes the workspace’s most recently used configuration version.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Perform a plan and optionaly apply if the auto-apply setting is enabled on the workspace
  esp.terraform.tfe_run:
    url: 'https://terraform.example.com'
    token: '{{ token }}'
    organization: foo
    workspace: bar
    action: create
    attributes:
      "is-destroy": false
      "message": Queued manually via the Terraform Enterprise API    
    validate_certs: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Apply a run
  esp.terraform.tfe_run:
    url: 'https://terraform.example.com'
    token: '{{ token }}'
    organization: foo
    workspace: bar
    action: apply
    run: run-CZcmD7eagjhyX0vN
    comment: Applied via the Terraform Enterprise API
    validate_certs: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Cancel a run
  esp.terraform.tfe_run:
    url: 'https://terraform.example.com'
    token: '{{ token }}'
    organization: foo
    workspace: bar
    action: cancel
    run: run-CZcmD7eagjhyX0vN
    comment: Cancelled via the Terraform Enterprise API
    validate_certs: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a destroy plan - destroy all provisioned resources
  esp.terraform.tfe_run:
    url: 'https://terraform.example.com'
    token: '{{ token }}'
    organization: foo
    workspace: bar
    action: create
    attributes:
      "is-destroy": true
      "message": Destroy all provisioned resources
    validate_certs: no

Inputs

    
run:
    description:
    - The run ID to act on.
    - Required when C(action) is C(apply), C(discard), C(cancel), C(force-cancel), C(force-execute).
    required: false
    type: str

url:
    description:
    - Terraform Enterprise URL.
    required: false
    type: str

sleep:
    default: 5
    description:
    - Number of seconds to sleep between API retries.
    type: int

token:
    description:
    - All requests to Terraform Enterprise must be authenticated with a bearer token.
    - There are three kinds of token available, i.e. user tokens, team tokens and organization
      tokens.
    - See L(Authentication,https://www.terraform.io/docs/cloud/api/index.html#authentication).
    required: true
    type: str

action:
    choices:
    - create
    - apply
    - discard
    - cancel
    - force-cancel
    - force-execute
    description:
    - Type of action to perform on a run.
    required: true
    type: str

comment:
    description:
    - An optional comment on the run.
    - Applicable when C(action) is C(apply), C(discard), C(cancel), C(force-cancel), C(force-execute).
    required: false
    type: str

retries:
    default: 3
    description:
    - Number of retries to call Terraform API URL before failure.
    type: int

use_proxy:
    default: true
    description:
    - If C(no), it will not use a proxy, even if one is defined in an environment variable
      on the target hosts.
    type: bool

workspace:
    description:
    - The workspace name or ID to execute a run on.
    required: true
    type: str

attributes:
    description:
    - Definition of the attributes for the run.
    - Required when C(action=create).
    - "When creating a run, it takes the workspace\u2019s most recently used configuration\
      \ version."
    required: false
    suboptions:
      is-destroy:
        default: false
        description:
        - Specifies if this plan is a destroy plan, which will destroy all provisioned
          resources.
        type: bool
      message:
        description:
        - Specifies the message to be associated with this run.
        required: false
        type: str
      refresh:
        default: true
        description:
        - Specifies whether or not to refresh the state before a plan.
        type: bool
      refresh-only:
        default: false
        description:
        - Whether this run should use the refresh-only plan mode, which will refresh the
          state without modifying any resources.
        type: bool
      replace-addrs:
        description:
        - Specifies an optional list of resource addresses to be passed to the C(-replace)
          flag.
        type: list
      target-addrs:
        description:
        - Specifies an optional list of resource addresses to be passed to the C(-target)
          flag.
        type: list
    type: dict

organization:
    description:
    - Organization name.
    required: true
    type: str

validate_certs:
    default: true
    description:
    - If C(no), SSL certificates will not be validated.
    - This should only set to C(no) used on personally controlled sites using self-signed
      certificates.
    type: bool

Outputs

json:
  contains:
    data:
      description: Details on the run.
      returned: success
      sample:
        attributes:
          actions:
            is-cancelable: true
            is-confirmable: false
            is-discardable: false
            is-force-cancelable: false
          canceled-at: null
          created-at: '2021-06-30T20:48:44.319000+00:00'
          has-changes: false
          is-destroy: false
          message: Queued manually via the Terraform Enterprise API
          permissions:
            can-apply: true
            can-cancel: true
            can-comment: true
            can-discard: true
            can-force-cancel: true
            can-force-execute: true
            can-override-policy-check: true
          plan-only: false
          source: tfe-api
          status: pending
          status-timestamps:
            plan-queueable-at: '2021-06-30T20:48:44+00:00'
          target-addrs: null
          trigger-reason: manual
        id: run-xvoeNhZRn5U1uEcf
        links:
          self: /api/v2/runs/run-xvoeNhZRn5U1uEcf
        relationships:
          apply:
            data:
              id: apply-WYLWbu8jLcnngfmF
              type: applies
            links:
              related: /api/v2/runs/run-xvoeNhZRn5U1uEcf/apply
          plan:
            data:
              id: plan-nx55vouUHb7VrPVa
              type: plans
            links:
              related: /api/v2/runs/run-xvoeNhZRn5U1uEcf/plan
          workspace:
            data:
              id: ws-xt1dqgiDPEZpJazo
              type: workspaces
        type: runs
      type: dict
  description: Details on the run.
  returned: success
  type: dict