Github Actions run terraform init in multiple directories

Viewed 248

I have 3 Terraform directories:

test_1
test_2
test_3

I would like to run terraform init in each of these directories. Is there a way to do this with a loop instead of specifying it 3 individual times?

I have the below code that runs it once inside only test_1 directory.

defaults:
  run:
    working-directory: test_1
jobs:
  terraform-plan:
    name: "Terraform"
    runs-on: ubuntu-latest
    steps:
      - name: "Run - Terraform Init"
        run: terraform init
1 Answers

Here's an idea.

defaults:
  run:
    working-directory: root_dir
jobs:
  terraform-plan:
    name: Terraform
    runs-on: ubuntu-latest
    steps:
      - name: Run - Terraform Init
        run: |
          find -mindepth 1 -maxdepth 1 -type d -exec terraform init \;

Keep in mind this needs to be done in parent dir of those test dirs.

Related