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 Remote Operations broken for Terraform versions >= 0.15.0 #1628

Closed
blytheaw opened this issue Jun 11, 2021 · 3 comments
Closed

Comments

@blytheaw
Copy link

blytheaw commented Jun 11, 2021

I believe this is another occurrence of #705 where the error message used to detect remote operations has changed between versions 0.14.11 and 0.15.0 of Terraform.

This closely related to some of the issues that have been previously fixed like #704 and #915.

I have confirmed this in a test as follows. The below output is from a single PR, with each workspace locked to a specific Terraform version. The Terraform Cloud workspaces are also locked to those specific versions. The Terraform configuration in each is identical except for the remote backend configuration and simply creates a null resource for testing:

terraform {
  backend "remote" {
    organization = "my-tf-cloud-org"

    workspaces {
      name = "atlantis-remoteops-<tf-version>"
    }
  }

  required_version = "<tf-version>"
}

resource "null_resource" "test" {}

Atlantis Plan Output

Ran Plan for 2 projects:

  1. dir: atlantis-remoteops/0.14.11 workspace: default
  2. dir: atlantis-remoteops/0.15.0 workspace: default

1. dir: atlantis-remoteops/0.14.11 workspace: default

Show Output
Running plan in the remote backend. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.

Preparing the remote plan...

To view this run in a browser, visit:
https://app.terraform.io/app/my-tf-cloud-org/atlantis-remoteops-0-14-11/runs/run-M9FAiPzy53PyLfTM

Waiting for the plan to start...

Terraform v0.14.11
Configuring remote state backend...
Initializing Terraform configuration...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

  # null_resource.test will be created
+ resource "null_resource" "test" {
      + id = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
  • ▶️ To apply this plan, comment:
    • atlantis apply -d atlantis-remoteops/0.14.11
  • 🚮 To delete this plan click here
  • 🔁 To plan this project again, comment:
    • atlantis plan -d atlantis-remoteops/0.14.11
Plan: 1 to add, 0 to change, 0 to destroy.

2. dir: atlantis-remoteops/0.15.0 workspace: default

Plan Error

running "/home/atlantis/.atlantis/bin/terraform0.15.0 plan -input=false -refresh -no-color -out \"/home/atlantis/.atlantis/repos/MyGitHubOrg/MyGitHubRepo/221/default/atlantis-remoteops/0.15.0/default.tfplan\"" in "/home/atlantis/.atlantis/repos/MyGitHubOrg/MyGitHubRepo/221/default/atlantis-remoteops/0.15.0": exit status 1

Error: Saving a generated plan is currently not supported

The "remote" backend does not support saving the generated execution plan
locally at this time.

Additional Info

I found the error message string in the Terraform repo, and it hasn't changed in 3 years. In my testing with different local CLI versions, it appears that 0.15.0 removed an extra newline character at the end of the error output.

0.14.11:


Error: Saving a generated plan is currently not supported

The "remote" backend does not support saving the generated execution plan
locally at this time.


0.15.0


Error: Saving a generated plan is currently not supported

The "remote" backend does not support saving the generated execution plan
locally at this time.

I'm not certain, but it appears that the string Atlantis is using to check for this message includes two newlines, and this might be why it is no longer detecting it:

var remoteOpsErr012 = `Error: Saving a generated plan is currently not supported
The "remote" backend does not support saving the generated execution plan
locally at this time.
`

@alexkosj
Copy link

FWIW, I was experiencing this same behavior and found a solution by overriding the default TF commands to not include the '-out' param. I set the override via the ATLANTIS_REPO_CONFIG_JSON env var.

Here's a copy pasta of my config:

{
    "workflows": {
        "default": {
            "plan": {
                "steps": [{
                        "run": "terraform init -input=false -no-color"
                    },
                    {
                        "run": "terraform plan -input=false -no-color"
                    }
                ]
            },
            "apply": {
                "steps": [{
                    "run": "terraform apply -no-color"
                }]
            }
        }
    },
    "repos": [{
        "id": "/.*/",
        "allowed_overrides": [
            "workflow"
        ],
        "allow_custom_workflows": true
    }]
}

Anyway hope it helps -- good luck!

@eiTi3Aishieg
Copy link

This is still a problem. It is necessary to override ATLANTIS_REPO_CONFIG_JSON. If not done, using Terraform Cloud is straight up impossible, leading to errors.

I had to add -auto-approve on the apply to stop it from hanging in special cases.

{
  "workflows": {
    "default": {
      "plan": {
        "steps": [
          {
            "run": "terraform init -input=false -no-color"
          },
          {
            "run": "terraform plan -input=false -no-color"
          }
        ]
      },
      "apply": {
        "steps": [
          {
            "run": "terraform apply -auto-approve -input=false -no-color"
          }
        ]
      }
    }
  },
  "repos": [
    {
      "id": "/.*/",
      "allowed_overrides": [
        "workflow"
      ],
      "allow_custom_workflows": true
    }
  ]
}

@lilincmu
Copy link
Contributor

I'm not certain, but it appears that the string Atlantis is using to check for this message includes two newlines, and this might be why it is no longer detecting it

@blytheaw I think you're right. Closing the issue since the original issue on v0.15.0 should have been addressed by #1687

@alexkosj @AmiditeX Not sure which version of Terraform were you using, but for versions later than v1.1, I'm working on another fix in #2793

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants