Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module creates following resources.

- `github_repository`
- `github_repository_vulnerability_alerts`
- `github_repository_collaborator` (optional)
- `github_repository_collaborators` (optional)
- `github_repository_custom_property` (optional)
Expand Down Expand Up @@ -49,6 +50,7 @@ This module creates following resources.
| [github_repository_deploy_key.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key) | resource |
| [github_repository_file.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file) | resource |
| [github_repository_topics.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_topics) | resource |
| [github_repository_vulnerability_alerts.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_vulnerability_alerts) | resource |
| [github_team_repository.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_repository) | resource |

## Inputs
Expand Down
13 changes: 11 additions & 2 deletions modules/repository/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ locals {
# INFO: Use a separate resource
# - `topics`
# - `default_branch`
# - `vulnerability_alerts`
resource "github_repository" "this" {
name = var.name
description = var.description
Expand All @@ -28,8 +29,6 @@ resource "github_repository" "this" {
archived = var.archived
archive_on_destroy = var.archive_on_destroy

vulnerability_alerts = var.vulnerability_alerts


## Template
is_template = var.is_template
Expand Down Expand Up @@ -107,6 +106,16 @@ resource "github_repository" "this" {
}


###################################################
# Vulnerability Alerts for GitHub Repository
###################################################

resource "github_repository_vulnerability_alerts" "this" {
repository = github_repository.this.name
enabled = var.vulnerability_alerts
}
Comment on lines +113 to +116

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The github_repository_vulnerability_alerts resource in the GitHub provider does not support an enabled argument. To conditionally enable or disable vulnerability alerts, you should use the count meta-argument to conditionally create the resource based on var.vulnerability_alerts.

resource "github_repository_vulnerability_alerts" "this" {
  count      = var.vulnerability_alerts ? 1 : 0
  repository = github_repository.this.name
}



###################################################
# Custom Properties for GitHub Repository
###################################################
Expand Down
2 changes: 1 addition & 1 deletion modules/repository/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ output "files" {

output "vulnerability_alerts" {
description = "Whether the security alerts are enabled for vulnerable dpendencies."
value = github_repository.this.vulnerability_alerts
value = github_repository_vulnerability_alerts.this.enabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since the github_repository_vulnerability_alerts resource does not have an enabled attribute, and should be conditionally created using count, referencing github_repository_vulnerability_alerts.this.enabled directly will result in a Terraform evaluation error. Instead, you can check if the resource is created by checking the length of the resource list.

  value       = length(github_repository_vulnerability_alerts.this) > 0

}

output "deploy_keys" {
Expand Down
Loading