metadata:
  name: terraformExecute
  description: Executes Terraform
  longDescription: |
    This step executes the terraform binary with the given command, and is able to fetch additional variables from vault.
spec:
  inputs:
    secrets:
      - name: cliConfigFileCredentialsId
        description: Jenkins 'Secret file' credentials ID containing terraform CLI configuration. You can find more details about it in the [Terraform documentation](https://www.terraform.io/docs/cli/config/config-file.html#credentials).
        type: jenkins
    params:
      - name: command
        type: string
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        default: plan
      - name: terraformSecrets
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        type: string
        resourceRef:
          - type: vaultSecretFile
            name: terraformFileVaultSecretName
            default: terraform
      - name: globalOptions
        type: "[]string"
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: additionalArgs
        type: "[]string"
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: init
        type: bool
        descriptions: Executes terraform init prior to the configured command.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        default: false
      - name: cliConfigFile
        type: string
        description: Path to the terraform CLI configuration file (https://www.terraform.io/docs/cli/config/config-file.html#credentials).
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        secret: true
        resourceRef:
          - name: cliConfigFileCredentialsId
            type: secret
          - type: vaultSecretFile
            name: cliConfigFileVaultSecretName
            default: terraform
      - name: workspace
        type: string
        descriptions: Name of the terraform workspace to operate on.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
  containers:
    - name: terraform
      image: hashicorp/terraform:1.0.10
      options:
        - name: --entrypoint
          value: ''
      env:
        - name: TF_IN_AUTOMATION
          value: piper
  outputs:
    resources:
      - name: commonPipelineEnvironment
        type: piperEnvironment
        params:
          - name: custom/terraformOutputs
            type: 'map[string]interface{}'
