Giter Site home page Giter Site logo

suzuki-shunsuke / tfaction Goto Github PK

View Code? Open in Web Editor NEW
259.0 3.0 39.0 16.24 MB

Framework for Monorepo to build high level Terraform Workflows by GitHub Actions

Home Page: https://suzuki-shunsuke.github.io/tfaction/docs/

License: MIT License

TypeScript 76.45% Shell 19.37% HCL 2.01% JavaScript 2.17%
hacktoberfest

tfaction's Introduction

tfaction

Framework for Monorepo to build high level Terraform Workflows by GitHub Actions

Document

https://suzuki-shunsuke.github.io/tfaction/docs/

Source code

Who uses tfaction?

Note

If you want to add your company or organization to the list, please send a pull request or send a comment to the GitHub Discussion!

LICENSE

MIT

tfaction's People

Contributors

renovate[bot] avatar suzuki-shunsuke avatar renovate-bot avatar suzuki-shunsuke-app[bot] avatar kengotoda avatar dependabot[bot] avatar sshota0809 avatar exoego avatar kyontan avatar gr1m0h avatar bgpat avatar ponkio-o avatar cappyzawa avatar irotoris avatar rochana-atapattu avatar nikitacoeur avatar nari-ex avatar jintanda avatar ism-k avatar johnmanjiro13 avatar tk3fftk avatar int128 avatar florianmutter avatar

Stargazers

Vitor Araujo Boufleur avatar Raphael Rodrigues avatar  avatar frauniki avatar Yoshiki avatar gussan avatar sho avatar Shingo Sato avatar Edwin avatar hisui avatar Kim Dahlgren avatar BioErrorLog avatar Jooho Lee avatar  avatar Naka Masato avatar Junichiro Takagi avatar  avatar Yoshihiro Fukuhara avatar namihey avatar N.Yamamoto avatar Shota Iwami avatar hnkz avatar  avatar koyashiro avatar Yusei Yagi avatar Akari Yamabuki avatar Takumi Takahashi avatar  avatar Elena Huma avatar Sergio Valverde avatar Christian Bargmann avatar micnncim avatar Yuichi Goto avatar yutsuki miyashita avatar Ryo Takeuchi avatar Nex Zhu avatar  avatar eisho.uchikakoi avatar  avatar Fohte / Hayato Kawai avatar Hi120ki avatar tomo avatar Tak Nishigori avatar Yuta Mizui avatar Katsuki Niwa avatar Taylor Mulder avatar Takayuki Kasai avatar Hiroshi Muraoka avatar Takaharu Nakamura avatar sasezaki avatar  avatar Taku Ito avatar Alexey Mikhaylov avatar Francis Njambi avatar Junya Hayashi avatar Alexey Alekhin avatar Mike Ball avatar Meysam avatar NkiHrk avatar Yuta Nishimori avatar  avatar xztaityozx avatar GarupanOjisan avatar Daiki Matsuyama avatar Malena avatar  avatar Jérôme Foray avatar Shinji Nakamatsu avatar Martin Kutlák avatar Igor Zalutski avatar  avatar Hüseyin Hürkan KARAMAN avatar Honahuku avatar ega4432 avatar Jason Anderson avatar  avatar Shoei Watanabe avatar Katsuyuki Sakai avatar Ivanilson Junior avatar Daniel Urgell avatar Atr0phy avatar  avatar Suguru Goto avatar Ryosuke Kato avatar Takeshi Kondo avatar  avatar Takafumi Seino avatar i-s-23 avatar Masaki ISHIYAMA avatar Yuuki TSUBOUCHI avatar  avatar Hipolit Badowski avatar Yuma avatar Muslih Aqqad avatar  avatar SHIMIZU Taku avatar colorbox avatar Hironori Yamamoto avatar Kosuke Fujishiro avatar Nikita avatar

Watchers

 avatar Kostas Georgiou avatar  avatar

tfaction's Issues

Change configuration structure

target_groups:
- working_directory:
  target:
  jobs:
  - job_id: terraform-plan # GITHUB_JOB
    aws_assume_role_arn:
    secrets:
    # ...

Old tfplan.binary is not deleted in GCS when terraform plan fails

Hi! I found thing that seems like bug.

if [ "$code" = "1" ]; then
echo "===> Delete old plan file to prevent the accident" >&2
aws s3 rm "s3://$S3_BUCKET_NAME_PLAN_FILE/$PR_NUMBER/$TFACTION_TARGET/tfplan.binary" || :
exit 1
fi

In action terrafom-plan, when terraform plan fails old tfplan.binary is supposed to be deleted in case of S3. But it remains in case of GCS.

Is this a behavior you suppose? If not, I'm going to make PR.

Support skipping plan and apply in case of pull request by Renovate

Motivation

We would like to create and merge many pull requests by Renovate.
When we manage dependencies such as Terraform, Terraform Providers, tfsec, tflint, etc and create pull request per working directory, we have to handle many pull requests by Renovate.

I found that when we update tfsec and tflint we don't have to run terraform plan and terraform apply.
We only have to run tfsec and tflint.
On the other hand, when Terraform and Terraform Providers are updated, we have to run terraform plan and terraform apply.

By skipping terraform plan and terraform apply, we can efficiently update dependencies.

  • We can prevent unexpected changes from being applied
  • We can prevent CI failure due to terraform plan's unexpected changes
  • We can prevent API rate exceeded by terraform plan and terraform apply

How

Add the fields in tfaction-root.yaml.

  • skip_by_renovate
  • renovate_terraform_labels

When skip_terraform_by_renovate is true, in pull requests by Renovate terraform plan and terraform apply are skipped.
If commits by non Renovate are included in the pull request, terraform plan and terraform apply aren't skipped.
When pull request labels in renovate_terraform_labels are set, terraform plan and terraform apply are executed.

Example Configuration

tfaction-root.yaml

skip_terraform_by_renovate: true
renovate_terraform_labels:
- terraform

renovate.json

{
  "packageRules": [
    {
      "matchManagers": ["terraform", "terraform-version"],
      "addLabels": ["terraform"]
    },
    {
      "matchPackageNames": ["hashicorp/terraform"],
      "addLabels": ["terraform"]
    }
  ]
}

Support only creating branches and skipping creating pull requests

tfaction suports creating some types of pull requests.

  • Follow up Pull Request
  • Scaffold working directory Pull Request
  • Scaffold tfmigrate migration Pull Request

They are really useful, but they are created by GitHub App so you can pass 1 approval Required by approving your changes by yourself.
To solve the problem, we consider to create only branch and skip creating pull request.

Run test even if tfmigrate's migration across multiple state

Problem to solve

Currently, when you migrate state across multiple state with tfmigrate,
you have to set the pull request label ignore:*.
When this label is set, tfmigrate-plan and terraform-plan jobs aren't run against the working directory,
then tfsec and tflint aren't run.

docs: Inputs is nothing in export-secrets

Hello, thank you for creating awesome tool.

This is minor misprint I noticed when I read source code.

ACTUAL

  • export-secrets
    The secrets parameter is required while nothing is required in README.

secrets:
description: 'secrets context'
required: true

## Inputs
Nothing.

EXPECTED BEHAVIOR

The secrets parameter is required also in README.

I will create PR against this issue. Thank you.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/actionlint.yaml
  • suzuki-shunsuke/actionlint-workflow v1.0.1@813a6d08c08cfd7a08618a89a59bfe78e573597c
.github/workflows/prerelease-pr.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • tibdex/github-app-token v2.1.0@3beb63f4bd073e61482598c45c71c1019b59b73a
.github/workflows/release.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
.github/workflows/test.yaml
  • dorny/paths-filter v3.0.2@de90cc6fb38fc0963ad72b210f1f284cd68cea36
.github/workflows/watch-star.yaml
  • suzuki-shunsuke/watch-star-action v0.1.1@2b3d259ce2ea06d53270dfe33a66d5642c8010ca
.github/workflows/wc-create-pr-branch.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • tibdex/github-app-token v2.1.0@3beb63f4bd073e61482598c45c71c1019b59b73a
  • aquaproj/aqua-installer v3.0.1@6ce1f8848ec8e61f14d57bd5d7597057a6dd187c
.github/workflows/wc-deploy-schema.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • peaceiris/actions-gh-pages v4.0.0@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e
.github/workflows/wc-enable-auto-merge.yaml
  • suzuki-shunsuke/enable-auto-merge-action v0.1.0@ec074392e76cd1062925255cd82a86ea1c44b6fd
.github/workflows/wc-ghalint.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • aquaproj/aqua-installer v3.0.1@6ce1f8848ec8e61f14d57bd5d7597057a6dd187c
.github/workflows/wc-prettier.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/setup-node v4.0.3@1e60f620b9541d16bece96c5465dc8ee9832be0b
.github/workflows/wc-renovate-config-validator.yaml
  • suzuki-shunsuke/renovate-config-validator-workflow v0.2.3@4a378742d05b4e67aae34039d7c779ac913cd79d
.github/workflows/wc-test-get-target-config.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • aquaproj/aqua-installer v3.0.1@6ce1f8848ec8e61f14d57bd5d7597057a6dd187c
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • aquaproj/aqua-installer v3.0.1@6ce1f8848ec8e61f14d57bd5d7597057a6dd187c
.github/workflows/wc-test-list-working-dirs.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • aquaproj/aqua-installer v3.0.1@6ce1f8848ec8e61f14d57bd5d7597057a6dd187c
.github/workflows/wc-update-aqua-checksums.yaml
  • aquaproj/update-checksum-workflow v1.0.2@437067ad2fba9ba8ed8454cf207f2532432d4e28
apply/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
create-follow-up-pr/action.yaml
  • suzuki-shunsuke/tfaction main
create-scaffold-module-pr/action.yaml
  • suzuki-shunsuke/tfaction main
create-scaffold-pr/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
list-targets/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
list-working-dirs/action.yaml
  • suzuki-shunsuke/tfaction main
plan/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
scaffold-module/action.yaml
  • suzuki-shunsuke/tfaction main
scaffold-tfmigrate/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
scaffold-working-dir/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
set-drift-env/action.yaml
  • suzuki-shunsuke/tfaction main
setup/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • aquaproj/update-checksum-action v0.2.3@0fef5fa12e81e046bb29078f76b99bb29fa4e696
  • aws-actions/configure-aws-credentials v4.0.2@e3dd6a429d7300a6a4c196c26e071d42e0343502
  • suzuki-shunsuke/tfaction main
  • google-github-actions/auth v2.1.4@f112390a2df9932162083945e46d439060d66ec2
  • google-github-actions/auth v2.1.4@f112390a2df9932162083945e46d439060d66ec2
  • google-github-actions/setup-gcloud v2.1.1@f0990588f1e5b5af6827153b93673613abdc6ec7
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/github-action-terraform-init v1.1.1@a0f2e069f49737ab11fbd9b00b2149019703ba99
terraform-apply/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
terraform-plan/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
  • actions/upload-artifact v4.3.6@834a144ee995460fba8ed112a2fc961b36a5ec5a
test-module/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/trivy-config-action v0.2.2@6c7c845cbf76e5745c4d772719de7a34453ae81d
  • suzuki-shunsuke/github-action-tfsec v1.0.0@6b4afce3060c0d8865d269de0c5fabc90e1b20f7
  • suzuki-shunsuke/github-action-tflint v1.1.0@0b7fbc35b0d512749f35c3036df57c3a95d3e9e1
  • suzuki-shunsuke/github-action-terraform-fmt v0.2.2@bdc85c3536e31ae189339cc09c5a0f9768d0ffa7
tfmigrate-apply/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
tfmigrate-plan/action.yaml
  • suzuki-shunsuke/tfaction main
  • suzuki-shunsuke/tfaction main
update-drift-issue/action.yaml
  • suzuki-shunsuke/tfaction main
nodenv
.node-version
  • node 20.16.0
npm
check-terraform-skip/package.json
export-aws-secrets-manager/package.json
export-secrets/package.json
get-global-config/package.json
get-target-config/package.json
lib/package.json
list-changed-modules/package.json
list-module-callers/package.json
list-targets-with-changed-files/package.json
package.json
nvm
.nvmrc
  • node 20.16.0
regex
renovate.json5
  • aquaproj/aqua-renovate-config 2.3.1
  • aquaproj/aqua-renovate-config:file 2.3.1
.github/workflows/actionlint.yaml
  • aquaproj/aqua v2.30.0
.github/workflows/wc-create-pr-branch.yaml
  • aquaproj/aqua v2.30.0
.github/workflows/wc-ghalint.yaml
  • aquaproj/aqua v2.30.0
.github/workflows/wc-test-get-target-config.yaml
  • aquaproj/aqua v2.30.0
  • aquaproj/aqua v2.30.0
.github/workflows/wc-test-list-working-dirs.yaml
  • aquaproj/aqua v2.30.0
.github/workflows/wc-update-aqua-checksums.yaml
  • aquaproj/aqua v2.30.0
renovate.json5
  • aquaproj/aqua-renovate-config 2.3.1
  • aquaproj/aqua-renovate-config 2.3.1
aqua.yaml
  • aquaproj/aqua-registry v4.212.0
aqua/actionlint.yaml
  • rhysd/actionlint v1.7.1
aqua/cmdx.yaml
  • suzuki-shunsuke/cmdx v1.7.4
aqua/ghalint.yaml
  • suzuki-shunsuke/ghalint v0.2.12
aqua/ghcp.yaml
  • int128/ghcp v1.13.3
aqua/github-comment.yaml
  • suzuki-shunsuke/github-comment v6.2.0
aqua/pinact.yaml
  • suzuki-shunsuke/pinact v0.2.1
aqua/reviewdog.yaml
  • reviewdog/reviewdog v0.20.1

  • Check this box to trigger a request for Renovate to run again on this repository

Handle timeout and credential expiration

Terraform itself doesn't support timeout.
https://discuss.hashicorp.com/t/timeout-setting-for-terraform-binary/29627/2

tfcmt -var "target:$TFACTION_TARGET" apply -- terraform apply -auto-approve -no-color -input=false tfplan.binary

  • Support sending the signal
  • Support changing the timeout (By default 1 Hour)

create-follow-up-pr: Add configuration `renovate_follow_up_mentions`

renovate_follow_up_mentions:
- suzuki-shunsuke
- <org name>/<team name>

Problem to solve

When Renovate Pull Request was merged automatically and apply failed,
follow up pull request is created but no mention is set and no one is assigned.

How to solve

If pull request author is Renovate and GITHUB_ACTOR is bot, renovate_follow_up_mentions are mentioned and assigned.

Support getting AWS Secrets Manager's Secrets

e.g.

  terraform_plan_config:
    aws_secrets_manager:
    - secret_id: foo
      version_id:
      version_stage:
      aws_region: ap-northeast-1
      envs:
      - env_name: ATLAS_API_KEY
        secret_key: atlas_api_key
    - secret_id: bar
      version_id:
      version_stage:
      aws_region: ap-northeast-1
      envs:
      - env_name: BAR

Perhaps tfaction-root.yaml overwrites tfaction.yaml in working directory

Hi, I found kind of like a bug.

ACTUAL

https://suzuki-shunsuke.github.io/tfaction/docs/config/tfaction-yaml

In above document, It seems that tfaction.yaml in working directory overwrites tfaction-root.yaml.

You can override the configuration of tfaction-root.yaml by tfaction.yaml.

On the other hand, in the action get-target-config it seems that tfaction-root.yaml overwrites tfaction.yaml in working directory.

lib.setOutputs([
's3_bucket_name_plan_file',
's3_bucket_name_tfmigrate_history',
'gcs_bucket_name_plan_file',
'providers_lock_opts',
], [wdConfig, targetConfig, config]);
lib.setOutputs([
'aws_region',
'aws_assume_role_arn',
'gcp_service_account',
'gcp_workload_identity_provider',
], [jobConfig, wdConfig, rootJobConfig, targetConfig, config]);

As far as I read the codes, each variables mean like following.

  • jobConfig: terraform_(plan|apply)_config in tfaction.yaml
  • wdConfig: tfaction.yaml
  • rootJobConfig: terraform_(plan|apply)_config in matched target in tfaction-root.yaml
  • targetConfig: matched target in tfaction-root.yaml
  • config: tfaction-root.yaml

So the order of list in arguments to setOutputs seems incorrect.

EXPECTED

The order like following is correct?

    lib.setOutputs([
      's3_bucket_name_plan_file',
      's3_bucket_name_tfmigrate_history',
      'gcs_bucket_name_plan_file',
      'providers_lock_opts',
    ], [config, targetConfig, wdConfig]);
    lib.setOutputs([
      'aws_region',
      'aws_assume_role_arn',
      'gcp_service_account',
      'gcp_workload_identity_provider',
    ], [config, targetConfig, rootJobConfig, wdConfig, jobConfig]);

If it's correct I send the PR! Thank you for reading in advance.

Support Modules

  • List and test changed Modules
  • Create tag and release by GitHub Actions dispatch_workflow event
  • Scaffold Module

Module Location

Add a file tfaction_module.yaml in Module's root directory.

Test Module

Module Source

GitHub: https://www.terraform.io/language/modules/sources#github

Tag Format

module_<module name>_<version>

⚠️ Unfortunately, slash / seems to be unavailable in Terraform Modules Ref.

Create tag and release by GitHub Actions dispatch_workflow event

Inputs

  • module_path
  • version

Auto update

It is difficult to update Modules by Renovate.

We'll consider to create feature branches or pull requests to update Modules by GitHub Actions.

Make terraform option configureble by tfaction.yml

Hi, this is feature request for tfaction!

We are managing a lot of working directories, and I'm facing a problem like hashicorp/terraform-provider-aws#5171 .
To prevent this problem, I want to pass [--parallelism](https://www.terraform.io/docs/commands/plan.html#parallelism-n) flag to the terraform command, but currently it's not possible.

I'm thinking about adding configuration item to tfaction.yaml like:

terraform-option: --parallelism 10

And this is passed to

terraform plan -no-color -detailed-exitcode -out tfplan.binary -input=false
.

Thanks in advance!

Support changing configuration file path of tfsec and tflint

skip_create_pr.sh is always executed when terraform apply fails regardless of skip_create_pr option

Hi, I found a thing like a bag.

ACTUAL

Even if the skip_create_pr option (default: false) is set both false or true in tfaction-root.yaml, skip_create_pr.sh is always executed when terraform apply fails.

- run: bash ${{ github.action_path }}/skip_create_pr.sh

EXPECTED

When skip_create_pr option is set as false, main.sh is executed not but skip_create_pr.sh.

- run: bash ${{ github.action_path }}/main.sh

MY RESEARCH

This bug is caused by the following wrong condition.

- run: bash ${{ github.action_path }}/skip_create_pr.sh
shell: bash
if: steps.global-config.outputs.skip_create_pr
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_APP_TOKEN: ${{ inputs.github_app_token }}
TFACTION_TARGET_LABEL_PREFIX: ${{ steps.global-config.outputs.label_prefix_target }}
TFACTION_DRAFT_PR: ${{ steps.global-config.outputs.draft_pr }}
- run: bash ${{ github.action_path }}/main.sh
shell: bash
if: '! steps.global-config.outputs.skip_create_pr'
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_APP_TOKEN: ${{ inputs.github_app_token }}
TFACTION_DRAFT_PR: ${{ steps.global-config.outputs.draft_pr }}

According to this document, output is always dealt as string so it can't compare to boolean.

In above case, as long as steps.global-config.outputs.skip_create_pr is not null, the result of condition is always true.

Refference: GitHub Actions で真偽値を正しく扱う

I'm going to send PR!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.