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

Run terraform workflows from local CLI command without a VCS #671

Open
billyshambrook opened this issue Jun 12, 2019 · 8 comments
Open

Run terraform workflows from local CLI command without a VCS #671

billyshambrook opened this issue Jun 12, 2019 · 8 comments
Labels
feature New functionality/enhancement help wanted Good feature for contributors needs discussion Large change that needs review from community/maintainers

Comments

@billyshambrook
Copy link

Before creating the PR it can be helpful to run a plan while you are locally editing the terraform. One thing that is annoying is that if you are using workspaces in atlantis via the atlantis.yml config, there is currently no way of enforcing a specific workspace when running locally using the standard terraform cli, unless you are using the new terraform remote backend that only works with TFE.

What I would like to propose is a local sub command that would allow you to use the Atlantis cli to run a plan locally, using the config provided in the atlantis.yaml.

atlantis local plan -p dev

This would then run the same logic as it would if you submitted a pr comment...

atlantis -p dev

@kipkoan
Copy link
Contributor

kipkoan commented Jun 12, 2019 via email

@lkysow lkysow added the feature New functionality/enhancement label Jun 12, 2019
@mdeeks
Copy link

mdeeks commented Nov 16, 2020

Hashicorp advises both directories (with modules) and workspaces in their guide: https://learn.hashicorp.com/tutorials/terraform/organize-configuration (about half way down)

To separate environments with potential configuration differences, use a directory structure. Use workspaces for environments that do not greatly deviate from one another, to avoid duplicating your configurations. Try both methods in the sections below to help you understand which will serve your infrastructure best.

We almost exclusively use workspaces. A local atlantis would be extremely helpful for us.

@red8888
Copy link

red8888 commented Aug 30, 2021

This seems like it would be a non-trivial effort and overlap with tf enterprise, but it would be amazing to have.

Maybe this is outside the scope of what was asked but if you could remotely execute atlantis that would be ideal. So you arent running it locally your hitting an api and atlantis is running terraform and returning the results (I think thats how tf enterprise works). That would be nice too for things like secrets- if atlantis is deployed through k8s for example and has all the secrets injected.

Maybe this could be done by scripting out kubectl exec calls or something too I guess

@nitrocode
Copy link
Member

This would be pretty nice to have so devs do not have to rely on the PR process to run a plan if the project is complicated.

projects:
- name: my-service-ue2-dev
  dir: components/terraform/my-service
  workspace: ue2-dev
  workflow: myworkflow
  autoplan:
    when_modified: ["**/*.tf", "tfvars/ue2-dev.tfvars"]

workflows:
  myworkflow:
    steps:
      - run: "..."
  myworkflow-new:
    steps:
      - run: "..."

Maybe atlantis local or a completely separate atlantis-cli

atlantis plan --project my-service-ue2-dev
atlantis plan --project my-service-ue2-dev --workflow myworkflow-new
atlantis plan --project my-service-ue2-dev --workflow myworkflow-new --dry-run
atlantis apply --project my-service-ue2-dev --workflow myworkflow-new --dry-run

A separate CLI would be easier to implement since it would only need to read the local repository's atlantis.yaml file

@jamengual jamengual added help wanted Good feature for contributors needs discussion Large change that needs review from community/maintainers labels Sep 1, 2022
@jamengual
Copy link
Contributor

now with the API this could be very possible BUT the authentication will have to be done by the user as in using an oauth2 proxy or something like that

@nitrocode
Copy link
Member

nitrocode commented Sep 6, 2022

I don't believe the user would have to authenticate if all the commands are done locally. All the user would need to have is the atlantis.yaml configuration file and the unique project name and any overrides.

For example, from the above, if the user ran this locally

atlantis plan --project my-service-ue2-dev --dry-run

It should show the following commands (use cd or -chdir depending on the terraform version)

cd components/terraform/my-service
terraform workspace select ue2-dev
terraform init
terraform plan
cd -

but perhaps this could issue can be separated into a local or remote subcommand? Where the local would only locally run the terraform workflows and remote would communicate with the atlantis API and then would require authentication as you mentioned.

atlantis local plan --project my-service-ue2-dev --dry-run
atlantis remote plan --project my-service-ue2-dev --dry-run

@jamengual
Copy link
Contributor

local will have to have a full implementation of atlantis minus the VCS integration I guess and the remote will interact with a full deployed atlantis and then it will need auth somehow

@red8888
Copy link

red8888 commented Oct 13, 2022

Auth to the atlantis api would require some effort, but maybe it could default to no auth and users just control access via firewalling.

But looking at this again I realize I dont really want Atlantis local I want private terraform enterprise.

Speaking for myself I dont need any of the VCS stuff. What I want is a command to upload/scp/whatever files in my cwd to the location where terraform is executed remotely. I switch to my branch before running the command, the command itself is not VCS aware.

So thinking about a simple implementation:

  • A k8s deployment with ssh port open. Container has terraform and any other tools I need installed
  • The script/cli command first scps files into cwd into the running container
  • Then it kubectl execs into the running container and calls terraform

Obvious security issues because you'd need admin perms.

@nitrocode nitrocode changed the title Atlantis Local Command Run terraform workflows from local CLI command without a VCS Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement help wanted Good feature for contributors needs discussion Large change that needs review from community/maintainers
Projects
None yet
Development

No branches or pull requests

7 participants