LoginSignup
0
0

More than 3 years have passed since last update.

Terraform✖️CodePipeline でプルリクエストからのマージに対応する

Posted at

はたです。最近TerraformでAWS構築する機会が増えています。
ついでにCI/CD環境をAWSのCode系サービスで実現しているのですが、プルリクエストからのマージをフックしてCodePipelineを走らせるにはどうすればいいのかな?を調べたので備忘録します。

https://www.terraform.io/docs/providers/aws/r/codepipeline_webhook.html
https://developer.github.com/v3/activity/events/types/#pullrequestevent

簡単に紹介するため aws_codepipeline_webhook の記述だけ記載します。
ポイントはfilterですね。
上記URLにGithubのpull request event詳細がわかるので、それを参考にfilterの設定をしています

任意のブランチ(今回はdevelop)のプルリクエストがマージされた(プルリクが閉じられmergedフラグがtrue)の場合のaws_codepipeline_webhookの書き方

resource "aws_codepipeline_webhook" "webhook" {
  name            = "test-webhook"
  target_pipeline = aws_codepipeline.codepipeline.name
  target_action   = "Source"
  authentication  = "GITHUB_HMAC"

  authentication_configuration {
    secret_token = "xxxxxxxxxxxxx"
  }

  filter {
    json_path    = "$.action"
    match_equals = "closed"
  }

  filter {
    json_path    = "$.pull_request.merged"
    match_equals = "true"
  }

  filter {
    json_path    = "$.pull_request.base.ref"
    match_equals = "develop"
  }
}

今回はここまで、良いTerraform生活を。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0