Skip to content

Commit

Permalink
✨ add missing discover settings to github resource (#196)
Browse files Browse the repository at this point in the history
Closes #184

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
  • Loading branch information
afiune authored Jan 10, 2025
1 parent 79522ea commit f402176
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/resources/integration_github.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ resource "mondoo_integration_github" "gh_integration" {
# repository_allow_list= ["repo1", "repo2"]
# repository_deny_list = ["repo1", "repo2"]
# configure discovery options
discovery = {
terraform = true
k8s_manifests = true
}
credentials = {
token = var.github_token
}
Expand All @@ -52,6 +58,7 @@ resource "mondoo_integration_github" "gh_integration" {

### Optional

- `discovery` (Attributes) (see [below for nested schema](#nestedatt--discovery))
- `repository` (String) GitHub repository.
- `repository_allow_list` (List of String) List of GitHub repositories to scan.
- `repository_deny_list` (List of String) List of GitHub repositories to exclude from scanning.
Expand All @@ -67,3 +74,12 @@ resource "mondoo_integration_github" "gh_integration" {
Required:

- `token` (String, Sensitive) Token for GitHub integration.


<a id="nestedatt--discovery"></a>
### Nested Schema for `discovery`

Optional:

- `k8s_manifests` (Boolean) Enable discovery of Kubernetes manifests.
- `terraform` (Boolean) Enable discovery of Terraform configurations.
6 changes: 6 additions & 0 deletions examples/resources/mondoo_integration_github/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ resource "mondoo_integration_github" "gh_integration" {
# repository_allow_list= ["repo1", "repo2"]
# repository_deny_list = ["repo1", "repo2"]

# configure discovery options
discovery = {
terraform = true
k8s_manifests = true
}

credentials = {
token = var.github_token
}
Expand Down
31 changes: 31 additions & 0 deletions internal/provider/integration_github_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ type integrationGithubResourceModel struct {
RepositoryAllowList types.List `tfsdk:"repository_allow_list"`
RepositoryDenyList types.List `tfsdk:"repository_deny_list"`

Discovery *integrationGithubDiscoveryModel `tfsdk:"discovery"`

// credentials
Credential *integrationGithubCredentialModel `tfsdk:"credentials"`
}

type integrationGithubDiscoveryModel struct {
// Discover Terraform files in the repositories. (Optional.)
Terraform types.Bool `tfsdk:"terraform"`
// Discover k8s manifests in the repositories. (Optional.)
K8sManifests types.Bool `tfsdk:"k8s_manifests"`
}

type integrationGithubCredentialModel struct {
Token types.String `tfsdk:"token"`
}
Expand All @@ -69,6 +78,11 @@ func (m integrationGithubResourceModel) GetConfigurationOptions() *mondoov1.Gith
opts.Token = mondoov1.NewStringPtr(mondoov1.String(token))
}

if m.Discovery != nil {
opts.DiscoverTerraform = mondoov1.NewBooleanPtr(mondoov1.Boolean(m.Discovery.Terraform.ValueBool()))
opts.DiscoverK8sManifests = mondoov1.NewBooleanPtr(mondoov1.Boolean(m.Discovery.K8sManifests.ValueBool()))
}

ctx := context.Background()
var listAllow []mondoov1.String
allowlist, _ := m.RepositoryAllowList.ToListValue(ctx)
Expand Down Expand Up @@ -144,6 +158,19 @@ func (r *integrationGithubResource) Schema(ctx context.Context, req resource.Sch
}...),
},
},
"discovery": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"terraform": schema.BoolAttribute{
MarkdownDescription: "Enable discovery of Terraform configurations.",
Optional: true,
},
"k8s_manifests": schema.BoolAttribute{
MarkdownDescription: "Enable discovery of Kubernetes manifests.",
Optional: true,
},
},
},
"credentials": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -326,6 +353,10 @@ func (r *integrationGithubResource) ImportState(ctx context.Context, req resourc
Repository: types.StringValue(integration.ConfigurationOptions.GithubConfigurationOptions.Repository),
RepositoryAllowList: allowList,
RepositoryDenyList: denyList,
Discovery: &integrationGithubDiscoveryModel{
Terraform: types.BoolValue(integration.ConfigurationOptions.GitlabConfigurationOptions.DiscoverTerraform),
K8sManifests: types.BoolValue(integration.ConfigurationOptions.GitlabConfigurationOptions.DiscoverK8sManifests),
},
Credential: &integrationGithubCredentialModel{
Token: types.StringPointerValue(nil),
},
Expand Down

0 comments on commit f402176

Please sign in to comment.