简体   繁体   中英

Terraform with Github Actions Pattern

I am trying to implement Github Actions for Terraform Plan and Apply using Github Pull Request and Merge features.

What I am not able to achieve is, reusing the workflow for every new component in the project.

For example, I have to add a new microservice in the project, I have created a Terraform module as below,

#new-microservice.tf
module "new-microservice" {
  source = "",
  name   = "foo",
  nlb    = true,
  few other details
}

So, when a new microservice needs to be added into the project, anyone can create new TF file with module block by changing the values of the attributes.

#one-more-microservice.tf
module "one-more-microservice" {
  source = "",
  name   = "bar",
  nlb    = false,
  few other details
}

So far, so good. Issue arrives when I want to isolate each of this microservice's resource states.

Each of this TF files will go into a separate directory in the Git repo so that TF state will be isolated.

But, with Github Actions, workflow yaml should be kept in .github/workflow directory of the Git repository.

How can I find the directory which has changes in the pull request and run the workflow inside that directory?

I tried searching in the Github Actions Marketplace, couldn't find anything concrete.

I don't want to create multiple jobs inside the plan and deploy workflow yaml files, one for microservice.

This is tricky because you're basically saying that you want one workflow to trigger on multiple repository pushes which is not currently a thing in github actions

Option 1: Create a Workflow Template that all it does is spin up on a service push and sends a workflow dispatcher event. You basically make an api call that triggers that workflow. The only caveat is that as of right now organizational workflow templates only work on public repos.

Option 2: Keep track of each service last build commit. This will allow you do to scans. The problem with this is that you will need to setup a workflow on a cronjob that will then go through a list of all your repos in your organization, and do the commit diff. If there is a commit diff available then you know to do what you need to do for your deployment. How to get list of organization repos

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM