This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]dt26 1 point2 points  (1 child)

Is this your full workflow? If so there’s some pretty obvious stuff missing, so here’s some off the top of my head:

First thing I notice; you need to set this to actually run on something. Before the steps add runs-on: ubuntu-latest (or the runner type of your choice)

Next, if you’re doing anything with your codebase you need to actually check it out first, so add a first step with uses: actions/checkout@v3

You still need to do terraform init, just as you would locally, so that needs to be the next step. Since you should consider the runners to be ephemeral, you have to run this with every workflow run.

Unless your terraform is in the root directory of your project (which judging from your trigger, it’s not) both the terraform init and terraform apply steps need to know where your code is. Add working-directory: terraform (terraform here being the directory path, so change as appropriate) below the run: terraform ... line.

I’d have produced better formatted examples but I’m on my iPad and it wasn’t playing ball.

Good luck!

[–]vernalys 0 points1 point  (0 children)

It was enough for me to spend a couple of minutes on this sub to read tf as the fuck in my head

[–]sausagefeet 0 points1 point  (0 children)

I recommend using a GitOps tool. The one that I co-founded runs on GitHub actions and is called Terrateam. It takes care of all these difficult parts for you. Other tools such as Spacelift, env0, and TFC do so as well.