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

Terraform Cloud deploy with hard-coded workspace fails #295

Open
1 task done
johnseekins-pathccm opened this issue Oct 12, 2023 · 0 comments
Open
1 task done

Terraform Cloud deploy with hard-coded workspace fails #295

johnseekins-pathccm opened this issue Oct 12, 2023 · 0 comments
Labels

Comments

@johnseekins-pathccm
Copy link

johnseekins-pathccm commented Oct 12, 2023

Problem description

Trying to run an apply with dflook/terraform-apply@v1 and it consistently fails. Both fmt-check and validate actions do work correctly on the same repository.

I've tried forcing workspace to an empty string and leaving the variable out with similar results.

   ╷
  │ Error: failed to create backend alias to target "". The hostname is not in the correct format.
  │ 
  │ 
  ╵
  
  ╷
  │ Error: Invalid workspaces configuration
  │ 
  │   on service.tf line 7, in terraform:
  │    7:   cloud {
  │ 
  │ Specified workspace "name" conflicts with TF_WORKSPACE environment
  │ variable.

Actual offending Terraform code:

terraform {
  cloud {
    organization = "***"

    workspaces {
      name = "workspace-name"
    }
  }

Terraform version

1.6.1 (locally), 1.5.7 (remote)

Backend

Terraform Cloud

Workflow YAML

name: Terraform Apply

inputs:
  filter-paths:
    required: true
    type: string
  terraform-path:
    required: false
    default: terraform/
    type: string
  terraform-token:
    required: true
    type: string

runs:
  using: composite
  steps:
    - name: Checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: terraform files filter
      uses: tj-actions/changed-files@v39
      id: terraform-files
      with:
        files: ${{ inputs.filter-paths }}
    - name: Apply Terraform
      if: "steps.terraform-files.outputs.any_changed"
      uses: dflook/terraform-apply@v1
      with:
        path: ${{ inputs.terraform-path }}
        auto_approve: true
        workspace: ""
      env:
        TERRAFORM_CLOUD_TOKENS: app.terraform.io=${{ inputs.terraform-token }}


### Workflow log

```shell
Run dflook/terraform-apply@v1
  with:
    path: terraform/
    auto_approve: true
    parallelism: 0
    destroy: false
  env:
    TERRAFORM_CLOUD_TOKENS: app.terraform.io=***
/usr/bin/docker run --name danielflookterraformgithubactionssha256445be2ccdfef4d1d3bd258f00582319c886969b76c1b848925022f8cbe4c6c7b_5fa9b7 --label 94351b --workdir /github/workspace --rm -e "TERRAFORM_CLOUD_TOKENS" -e "INPUT_PATH" -e "INPUT_AUTO_APPROVE" -e "INPUT_WORKSPACE" -e "INPUT_BACKEND_CONFIG" -e "INPUT_BACKEND_CONFIG_FILE" -e "INPUT_VARIABLES" -e "INPUT_VAR" -e "INPUT_VAR_FILE" -e "INPUT_PARALLELISM" -e "INPUT_LABEL" -e "INPUT_TARGET" -e "INPUT_REPLACE" -e "INPUT_DESTROY" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "GITHUB_ACTION_PATH" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true --entrypoint "/entrypoints/apply.sh" -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/hubot/hubot":"/github/workspace" danielflook/terraform-github-actions@sha256:445be2ccdfef4d1d3bd258f00582319c886969b76c1b848925022f8cbe4c6c7b
Installing Terraform
  gpg: Signature made Tue Oct 10 16:10:49 2023 UTC
  gpg:                using RSA key 374EC75B485913604A831CC7C820C6D5CD27AB87
  gpg: Good signature from "HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>" [ultimate]
  terraform_1.6.1_linux_amd64.zip: OK
  Terraform version not specified, using the latest version
  Switched to Terraform v1.6.1
  Detected cloud backend
Initializing Terraform
  
  Initializing Terraform Cloud...
  ╷
  │ Error: failed to create backend alias to target "". The hostname is not in the correct format.
  │ 
  │ 
  ╵
  
  ╷
  │ Error: Invalid workspaces configuration
  │ 
  │   on service.tf line 7, in terraform:
  │    7:   cloud {
  │ 
  │ Specified workspace "name" conflicts with TF_WORKSPACE environment
  │ variable.
  │ 
  │ The 'workspaces' block configures how Terraform CLI maps its workspaces for
  │ this single
  │ configuration to workspaces within a Terraform Cloud organization. Two
  │ strategies are available:
  │ 
  │ tags - A set of tags used to select remote Terraform Cloud
  │ workspaces to be used for this single
  │ configuration. New workspaces will automatically be tagged with these tag
  │ values. Generally, this
  │ is the primary and recommended strategy to use.  This option conflicts with
  │ "name".
  │ 
  │ name - The name of a single Terraform Cloud workspace to be
  │ used with this configuration.
  │ When configured, only the specified workspace can be used. This option
  │ conflicts with "tags"
  │ and with the TF_WORKSPACE environment variable.

Has debug logging been enabled?

  • Yes, the ACTIONS_STEP_DEBUG secret was set to true when capturing the workflow log above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant