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

How to leverage plan -out and apply #271

Closed
yordis opened this issue Nov 12, 2022 · 2 comments
Closed

How to leverage plan -out and apply #271

yordis opened this issue Nov 12, 2022 · 2 comments

Comments

@yordis
Copy link

yordis commented Nov 12, 2022

Hey there, I am a bit confused about how I could set up the terraform plan -out and terraform apply [file name]

It may be beneficial to showcase some examples demonstrating how it could be accomplished.

I thought it would be trivial, but I haven't been able to make it work with artifacts or however I suppose to make it work.

Here is what I got so far:

env:
  tf_working_dir: home/infrastructure/github/testing-project

jobs:
  terraform:
    name: Terraform
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2.5.0

      - name: Get Terraform Version
        uses: straw-hat-team/github-actions-workflows/asdf/get-version@v1.5.1
        id: terraform-version
        with:
          plugin-name: terraform

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2.0.3
        with:
          terraform_version: ${{ steps.terraform-version.outputs.plugin-version }}
          terraform_wrapper: true

      - name: Terraform Format
        if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
        run: terraform fmt -check
        working-directory: ${{ env.tf_working_dir }}

      - name: Terraform Init
        run: terraform init -backend=true
        working-directory: ${{ env.tf_working_dir }}

      - name: Terraform Validate
        if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
        run: terraform validate
        working-directory: ${{ env.tf_working_dir }}

      - name: Terraform Plan
        if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
        run: terraform plan -input=false -out=${{ github.sha }}.tfplan
        working-directory: ${{ env.tf_working_dir }}

      - name: Upload terraform Plan Artifact
        if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
        uses: actions/upload-artifact@v3.1.1
        with:
          name: terraform-plan-${{ github.sha }}
          path: ${{ env.tf_working_dir }}/${{ github.sha }}.tfplan
          if-no-files-found: error

      - name: Download terraform Plan Artifact
        uses: actions/download-artifact@v3.0.1
        if: github.ref == 'refs/heads/master' && github.event_name == 'push'
        with:
          name: terraform-plan-${{ github.sha }}
          path: ${{ env.tf_working_dir }}/${{ github.sha }}.tfplan

      - name: terraform Apply
        if: github.ref == 'refs/heads/master' && github.event_name == 'push'
        run: terraform apply -auto-approve -input=false ${{ github.sha }}.tfplan
        working-directory: ${{ env.tf_working_dir }}

I am not sure what is going with github.sha but it changes by the time it gets into master so the artifact is not found. Maybe you know what I am doing wrong or what I should be doing.

Thanks in advanced.

@bflad
Copy link
Member

bflad commented Nov 29, 2023

Hi @yordis 👋 Thank you for raising this and sorry you are running into trouble here. Please note that this GitHub repository's issue tracker is only used for feature requests and bug reports for the setup-terraform GitHub action itself. Since this appears to be a GitHub Actions workflow question, my best recommendation would be to submit a topic in the Terraform section of HashiCorp Discuss or Actions section of GitHub Community Discussions, where there are many more people asking and answering usage questions such as these.

@bflad bflad closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants