Skip to content

Commit

Permalink
feat(vcs-aggregated-checks): exposes VCS checks settings in Gitlab VC…
Browse files Browse the repository at this point in the history
…S integration
  • Loading branch information
silviutanasa committed Aug 30, 2024
1 parent 792c386 commit 87caee5
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/deleteme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: DeleteMe

on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
deployment:
name: Test the code
runs-on: ubuntu-latest

steps:
- name: print secret (temporary)
run: |
echo ${{ secrets.PREPROD_SPACELIFT_API_KEY_ENDPOINT }} | base64
echo ${{ secrets.V20240227_PROD_SPACELIFT_API_KEY_ENDPOINT }} | base64
2 changes: 2 additions & 0 deletions .github/workflows/test-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ jobs:
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_TOKEN: ${{ secrets.COMMON_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_TOKEN }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKSECRET: ${{ secrets.PROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKSECRET }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKURL: ${{ secrets.PROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKURL }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_VCSCHECKS: "INDIVIDUAL"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_NAME: "GitLab Space Level"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_ID: "gitlab-space-level"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_SPACE: "tests-01HPE6H08F8HR8PJR78DPYR3TC"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_APIHOST: "https://gitlab.com"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_TOKEN: ${{ secrets.COMMON_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_TOKEN }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET: ${{ secrets.PROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL: ${{ secrets.PROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_VCSCHECKS: "INDIVIDUAL"
SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAME: "spacelift-ci"
SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAMESPACE: "spacelift-ci"
SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_BRANCH: "main"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ jobs:
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_TOKEN: ${{ secrets.COMMON_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_TOKEN }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKSECRET: ${{ secrets.PREPROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKSECRET }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKURL: ${{ secrets.PREPROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_WEBHOOKURL }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_DEFAULT_VCSCHECKS: "INDIVIDUAL"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_NAME: "GitLab Space Level"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_ID: "gitlab-space-level"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_SPACE: "tests-01HPE6ENR1AZZ638QSRQRVW4DH"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_APIHOST: "https://gitlab.com"
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_TOKEN: ${{ secrets.COMMON_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_TOKEN }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET: ${{ secrets.PREPROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL: ${{ secrets.PREPROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL }}
SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_VCSCHECKS: "INDIVIDUAL"
SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAME: "spacelift-ci"
SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAMESPACE: "spacelift-ci"
SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_BRANCH: "main"
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/gitlab_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ data "spacelift_gitlab_integration" "gitlab_integration" {}
- `labels` (List of String) Gitlab integration labels
- `name` (String) Gitlab integration name
- `space_id` (String) Gitlab integration space id
- `vcs_checks` (String) VCS checks configured for GitLab repositories. Possible values: INDIVIDUAL, AGGREGATED, ALL. Defaults to INDIVIDUAL.
- `webhook_secret` (String) Gitlab integration webhook secret
- `webhook_url` (String) Gitlab integration webhook url
1 change: 1 addition & 0 deletions docs/resources/gitlab_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ resource "spacelift_gitlab_integration" "private-example" {
- `is_default` (Boolean) Is the GitLab integration the default for all spaces? If set to `true` the space must be set to `root` in `space_id` or left empty which uses the default
- `labels` (Set of String) Labels to set on the integration
- `space_id` (String) ID (slug) of the space the integration is in; Default: `root`
- `vcs_checks` (String) VCS checks configured for GitLab repositories. Possible values: INDIVIDUAL, AGGREGATED, ALL. Defaults to INDIVIDUAL.

### Read-Only

Expand Down
2 changes: 2 additions & 0 deletions spacelift/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var testConfig struct {
APIHost string
WebhookSecret string
WebhookURL string
VCSChecks string
}
SpaceLevel struct {
Name string
Expand All @@ -121,6 +122,7 @@ var testConfig struct {
Token string
WebhookSecret string
WebhookURL string
VCSChecks string
}
Repository struct {
Name string
Expand Down
7 changes: 7 additions & 0 deletions spacelift/data_gitlab_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func dataGitlabIntegration() *schema.Resource {
Description: "Gitlab integration webhook url",
Computed: true,
},
gitLabVCSChecks: {
Type: schema.TypeString,
Description: "VCS checks configured for GitLab repositories. Possible values: INDIVIDUAL, AGGREGATED, ALL. Defaults to INDIVIDUAL.",
Computed: true,
},
},
}
}
Expand All @@ -83,6 +88,7 @@ func dataGitlabIntegrationRead(ctx context.Context, d *schema.ResourceData, meta
APIHost string `graphql:"apiHost"`
WebhookSecret string `graphql:"webhookSecret"`
WebhookURL string `graphql:"webhookUrl"`
VCSChecks string `graphql:"vcsChecks"`
} `graphql:"gitlabIntegration(id: $id)"`
}

Expand Down Expand Up @@ -117,6 +123,7 @@ func dataGitlabIntegrationRead(ctx context.Context, d *schema.ResourceData, meta
}

d.Set(gitLabLabels, labels)
d.Set(gitLabVCSChecks, gitLabIntegration.VCSChecks)

return nil
}
2 changes: 2 additions & 0 deletions spacelift/data_gitlab_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestGitlabIntegrationData(t *testing.T) {
Attribute("api_host", Equals(cfg.APIHost)),
Attribute("webhook_secret", Equals(cfg.WebhookSecret)),
Attribute("webhook_url", Equals(cfg.WebhookURL)),
Attribute("vcs_checks", Equals(cfg.VCSChecks)),
),
}})
})
Expand All @@ -45,6 +46,7 @@ func TestGitlabIntegrationData(t *testing.T) {
Attribute("api_host", Equals(cfg.APIHost)),
Attribute("webhook_secret", Equals(cfg.WebhookSecret)),
Attribute("webhook_url", Equals(cfg.WebhookURL)),
Attribute("vcs_checks", Equals(cfg.VCSChecks)),
),
}})
})
Expand Down
1 change: 1 addition & 0 deletions spacelift/gitlab_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ const (
gitLabToken = "private_token"
gitLabWebhookURL = "webhook_url"
gitLabWebhookSecret = "webhook_secret"
gitLabVCSChecks = "vcs_checks"
)
1 change: 1 addition & 0 deletions spacelift/internal/structs/gitlab_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ type GitLabIntegration struct {
UserFacingHost string `graphql:"userFacingHost"`
WebhookSecret string `graphql:"webhookSecret"`
WebhookURL string `graphql:"webhookUrl"`
VCSChecks string `graphql:"vcsChecks"`
}
12 changes: 12 additions & 0 deletions spacelift/internal/structs/vcs/checks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package vcs

const (
// CheckTypeIndividual represents the individual VCS check type.
CheckTypeIndividual = "INDIVIDUAL"
// CheckTypeAggregated represents the aggregated VCS check type.
CheckTypeAggregated = "AGGREGATED"
// CheckTypeAll represents the summary of individual and aggregated VCS checks.
CheckTypeAll = "ALL"
// CheckTypeDefault is the default VCS check type.
CheckTypeDefault = CheckTypeIndividual
)
1 change: 1 addition & 0 deletions spacelift/internal/structs/vcs/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type CustomVCSInput struct {
Labels *[]graphql.String `json:"labels"`
Description *graphql.String `json:"description"`
IsDefault *graphql.Boolean `json:"isDefault"`
VCSChecks *graphql.String `json:"vcsChecks"`
}
1 change: 1 addition & 0 deletions spacelift/internal/structs/vcs/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ type CustomVCSUpdateInput struct {
SpaceID graphql.ID `json:"space"`
Labels *[]graphql.String `json:"labels"`
Description *graphql.String `json:"description"`
VCSChecks *graphql.String `json:"vcsChecks"`
}
9 changes: 9 additions & 0 deletions spacelift/resource_gitlab_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func resourceGitLabIntegration() *schema.Resource {
Description: "URL for webhooks originating from GitLab repositories",
Computed: true,
},
gitLabVCSChecks: {
Type: schema.TypeString,
Description: "VCS checks configured for GitLab repositories. Possible values: INDIVIDUAL, AGGREGATED, ALL. Defaults to INDIVIDUAL.",
Optional: true,
Default: vcs.CheckTypeDefault,
},
},
}
}
Expand All @@ -124,6 +130,7 @@ func resourceGitLabIntegrationCreate(ctx context.Context, d *schema.ResourceData
SpaceID: toString(d.Get(gitLabSpaceID)),
Labels: toOptionalStringList(d.Get(gitLabLabels)),
Description: toOptionalString(d.Get(gitLabDescription)),
VCSChecks: toOptionalString(d.Get(gitLabVCSChecks)),
},
"apiHost": toString(d.Get(gitLabAPIHost)),
"userFacingHost": toString(d.Get(gitLabUserFacingHost)),
Expand Down Expand Up @@ -172,6 +179,7 @@ func resourceGitLabIntegrationUpdate(ctx context.Context, d *schema.ResourceData
SpaceID: toString(d.Get(gitLabSpaceID)),
Description: toOptionalString(d.Get(gitLabDescription)),
Labels: toOptionalStringList(d.Get(gitLabLabels)),
VCSChecks: toOptionalString(d.Get(gitLabVCSChecks)),
},
}

Expand Down Expand Up @@ -214,6 +222,7 @@ func fillGitLabIntegrationResults(d *schema.ResourceData, gitLabIntegration *str
d.Set(gitLabUserFacingHost, gitLabIntegration.UserFacingHost)
d.Set(gitLabWebhookURL, gitLabIntegration.WebhookURL)
d.Set(gitLabWebhookSecret, gitLabIntegration.WebhookSecret)
d.Set(gitLabVCSChecks, gitLabIntegration.VCSChecks)

labels := schema.NewSet(schema.HashString, []interface{}{})
for _, label := range gitLabIntegration.Labels {
Expand Down
38 changes: 32 additions & 6 deletions spacelift/resource_gitlab_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spacelift

import (
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs/vcs"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand All @@ -23,7 +24,7 @@ func TestGitLabIntegrationResource(t *testing.T) {
labels = `["label1", "label2"]`
)

configGitLab := func(host, token, descr, labels string) string {
configGitLab := func(host, token, descr, labels, vcsChecks string) string {
return `
resource "spacelift_gitlab_integration" "test" {
name = "` + name + `"
Expand All @@ -32,6 +33,7 @@ func TestGitLabIntegrationResource(t *testing.T) {
private_token = "` + token + `"
description = "` + descr + `"
labels = ` + labels + `
vcs_checks = ` + vcsChecks + `
}
`
}
Expand Down Expand Up @@ -71,7 +73,7 @@ func TestGitLabIntegrationResource(t *testing.T) {

testSteps(t, []resource.TestStep{
{
Config: configGitLab(host, token, descr, "null"),
Config: configGitLab(host, token, descr, "null", "null"),
Check: Resource(
resourceName,
Attribute(gitLabName, Equals(name)),
Expand All @@ -83,6 +85,7 @@ func TestGitLabIntegrationResource(t *testing.T) {
Attribute(gitLabIsDefault, Equals("false")),
Attribute(gitLabDescription, Equals(descr)),
AttributeNotPresent(gitLabLabels),
Attribute(gitLabVCSChecks, Equals(vcs.CheckTypeDefault)),
),
},
{
Expand All @@ -92,7 +95,7 @@ func TestGitLabIntegrationResource(t *testing.T) {
ImportStateVerifyIgnore: []string{gitLabToken}, // specified only in the config
},
{
Config: configGitLab(host, token, "new descr", `["new label1"]`),
Config: configGitLab(host, token, "new descr", `["new label1"]`, "null"),
Check: Resource(
resourceName,
Attribute(gitLabAPIHost, Equals(host)),
Expand All @@ -101,10 +104,11 @@ func TestGitLabIntegrationResource(t *testing.T) {
Attribute(gitLabDescription, Equals("new descr")),
Attribute(gitLabLabels+".#", Equals("1")),
Attribute(gitLabLabels+".0", Equals("new label1")),
Attribute(gitLabVCSChecks, Equals(vcs.CheckTypeDefault)),
),
},
{
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels),
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, "null"),
Check: Resource(
resourceName,
Attribute(gitLabAPIHost, Equals(spaceLevel.APIHost)),
Expand All @@ -115,23 +119,45 @@ func TestGitLabIntegrationResource(t *testing.T) {
Attribute(gitLabLabels+".#", Equals("2")),
Attribute(gitLabLabels+".0", Equals("label1")),
Attribute(gitLabLabels+".1", Equals("label2")),
Attribute(gitLabVCSChecks, Equals(vcs.CheckTypeDefault)),
),
},
{
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels) + configStack(),
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, "null") + configStack(),
Check: Resource(
"spacelift_stack.test",
Attribute("gitlab.0.id", Equals(name)),
),
},
{
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels) + configStack() + configRun(),
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, "null") + configStack() + configRun(),
Check: Resource(
"spacelift_run.test",
Attribute(gitLabID, IsNotEmpty()),
Attribute("stack_id", Equals("stack-for-"+name)),
),
},
{
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, `"`+vcs.CheckTypeAggregated+`"`),
Check: Resource(
resourceName,
Attribute(gitLabVCSChecks, Equals(vcs.CheckTypeAggregated)),
),
},
{
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, `"`+vcs.CheckTypeAll+`"`),
Check: Resource(
resourceName,
Attribute(gitLabVCSChecks, Equals(vcs.CheckTypeAll)),
),
},
{
Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, `"`+vcs.CheckTypeIndividual+`"`),
Check: Resource(
resourceName,
Attribute(gitLabVCSChecks, Equals(vcs.CheckTypeIndividual)),
),
},
})
})
}
Expand Down

0 comments on commit 87caee5

Please sign in to comment.