Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support AWS EventBridge #4188

Merged
merged 40 commits into from
Oct 28, 2024
Merged

feat: support AWS EventBridge #4188

merged 40 commits into from
Oct 28, 2024

Conversation

npalm
Copy link
Collaborator

@npalm npalm commented Oct 17, 2024

Description

This PR introduces the AWS EventBridge. The EventBridge can be enabled with the options webhook_mode, which can be set to either direct or eventbridge. In the direct mode the olds way of handling is still applied. When setting the mode to eventbridge events will publshed on the AWS EventBridge, which is not limited only to the event workflow_job with statues queued via a target rule events relevant for scaling a snet to the dispatcher lambda to distrute to a SQS queue for sacling.

Todo

  • Refactor lambda and add EventBridge
  • Refactor webhook module (TF) to support EventBridge
  • Test example default
  • Test example multi runner
  • Adjust docs
  • Reduce permissions on webhook and dispatcher lambda for eventbridge mode
  • Add configuration for allowed events on the EventBridge
  • Add support for CMK (encruption) to EventBridge Add support for CMK (encryption) for the EventBridge #4192

MIgration directions

The change is backwards compatible but will recreate resources managed by the internal module webhook. The only resource contianing data is the CloudWatch LogGroup. To retain the log geroup you can run a terraform state move. Or add a moved block to your deployemnt.

Migrating to this version

With module defaults or eventbridge is not eanavbled

# log group
moved {
   from = module.<runner-module-name>.module.webhook.aws_cloudwatch_log_group.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_cloudwatch_log_group.webhook
}

# lambda
moved {
   from = module.<runner-module-name>.module.webhook.aws_lambda_function.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_lambda_function.webhook
}

Or with webhook_mode = eventbridge

# log group
moved {
   from = module.<runner-module-name>.module.webhook.aws_cloudwatch_log_group.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_cloudwatch_log_group.webhook
}

# lambda
moved {
   from = module.<runner-module-name>.module.webhook.aws_lambda_function.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_lambda_function.webhook
}

When switching between direct and eventbridge

When enable mode eventbridge

# log group
moved {
  from = module.runners.module.webhook.module.direct[0].aws_cloudwatch_log_group.webhook
  to = module.runners.module.webhook.module.eventbridge[0].aws_cloudwatch_log_group.webhook
}

# lambda
moved {
  from = module.runners.module.webhook.module.direct[0].aws_lambda_function.webhook
  to = module.runners.module.webhook.module.eventbridge[0].aws_lambda_function.webhook
}

Or vice versa for moving from eventbride to webhook

@npalm npalm marked this pull request as draft October 17, 2024 07:00
examples/default/main.tf Outdated Show resolved Hide resolved
@npalm npalm force-pushed the npalm/eventbridge branch from 8f71cbc to 0c342d6 Compare October 17, 2024 07:49
@npalm npalm changed the title feat: support event bridge feat: support AWS EventBridge Oct 17, 2024
Co-authored-by: Marco Pas <[email protected]>
mpas
mpas previously requested changes Oct 22, 2024
docs/configuration.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
modules/multi-runner/README.md Outdated Show resolved Hide resolved
modules/webhook/policies/lambda-ssm.json Show resolved Hide resolved
modules/webhook/policies.tf Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@mpas mpas self-requested a review October 22, 2024 07:54
@ShivaSDP
Copy link

@npalm

Test Results for 'default' and 'multi-runner' example deployment:

I have followed the steps below to verify the functionality of both the 'default' and 'multi-runner' examples.:

  • Deployed both the default and multi-runner configurations using the latest code from the main branch (testing one at a time)

  • Ran a workflow job to ensure the initial setup was working fine.

  • Checked out the PR changes and proceeded with the following steps:
    * Rebuilt all the lambdas by running yarn dist.
    * Applied Terraform on the default example first and ran a test build successfully.
    * Enabled EventBridge mode and applied the Terraform changes again.
    * Verified that the sample build workflow executed successfully, confirming new instances were created and used correctly.

Repeated the above steps for the multi-runner configuration.

I also verified that the EC2 instances shut down automatically after job completion, in line with the expected behavior for ephemeral (direct) configurations.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
docs/configuration.md Outdated Show resolved Hide resolved
docs/configuration.md Outdated Show resolved Hide resolved
examples/default/main.tf Outdated Show resolved Hide resolved
modules/multi-runner/variables.tf Outdated Show resolved Hide resolved
modules/webhook/README.md Outdated Show resolved Hide resolved
modules/webhook/README.md Outdated Show resolved Hide resolved
modules/webhook/variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
@npalm npalm requested a review from stuartp44 October 24, 2024 11:14
stuartp44
stuartp44 previously approved these changes Oct 25, 2024
@npalm npalm dismissed mpas’s stale review October 28, 2024 15:54

github is van het padje

@npalm npalm merged commit 9607ca6 into main Oct 28, 2024
4 checks passed
@npalm npalm deleted the npalm/eventbridge branch October 28, 2024 16:44
npalm pushed a commit that referenced this pull request Oct 28, 2024
🤖 I have created a release *beep* *boop*
---


##
[5.18.0](philips-labs/terraform-aws-github-runner@v5.17.3...v5.18.0)
(2024-10-28)


### Features

* support AWS EventBridge
([#4188](https://github.com/philips-labs/terraform-aws-github-runner/issues/4188))
([9607ca6](philips-labs/terraform-aws-github-runner@9607ca6))

### Migration directions

This release is adding optional the
[EventBridge](https://philips-labs.github.io/terraform-aws-github-runner/configuration/#eventbridge)
as option to the webhook. No matter if the feature is enabled or not
resources are moved internally. Which will destroy all webhook related
resources update to this verions.

To retain data for the Loggroup of the webhook or mmetrics for the
webhook the resources not to be moved in the Terraform state. You can
add HCL moved blocked to your deployment to instruct Terraform to move
the resources instead of re-create.

<details>

<summary>Examples Terraform `moved` blockes</summary>


#### With module defaults or eventbridge is not eanavbled

```hcl
# log group
moved {
   from = module.<runner-module-name>.module.webhook.aws_cloudwatch_log_group.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_cloudwatch_log_group.webhook
}

# lambda
moved {
   from = module.<runner-module-name>.module.webhook.aws_lambda_function.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_lambda_function.webhook
}

```

#### With EventBridge enabled

```hcl
# log group
moved {
   from = module.<runner-module-name>.module.webhook.aws_cloudwatch_log_group.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_cloudwatch_log_group.webhook
}

# lambda
moved {
   from = module.<runner-module-name>.module.webhook.aws_lambda_function.webhook
   to = module.<runner-module-name>.module.webhook.module.direct[0].aws_lambda_function.webhook
}
```

#### Ater upgrade swithcing between webhook to EventBridge

When enable mode `eventbridge`

```hcl
# log group
moved {
  from = module.runners.module.webhook.module.direct[0].aws_cloudwatch_log_group.webhook
  to = module.runners.module.webhook.module.eventbridge[0].aws_cloudwatch_log_group.webhook
}

# lambda
moved {
  from = module.runners.module.webhook.module.direct[0].aws_lambda_function.webhook
  to = module.runners.module.webhook.module.eventbridge[0].aws_lambda_function.webhook
}
```

Or vice versa for moving from `eventbride` to `webhook`

</details>



---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: forest-releaser[bot] <80285352+forest-releaser[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants