diff --git a/.github/workflows/test-prod.yml b/.github/workflows/test-prod.yml index da045a33..a7f40b6b 100644 --- a/.github/workflows/test-prod.yml +++ b/.github/workflows/test-prod.yml @@ -86,6 +86,7 @@ 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" @@ -93,6 +94,7 @@ jobs: 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" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aaf05b7b..666ec766 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -88,6 +88,7 @@ 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" @@ -95,6 +96,7 @@ jobs: 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" diff --git a/docs/data-sources/gitlab_integration.md b/docs/data-sources/gitlab_integration.md index f172458e..740aec5b 100644 --- a/docs/data-sources/gitlab_integration.md +++ b/docs/data-sources/gitlab_integration.md @@ -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 diff --git a/docs/resources/gitlab_integration.md b/docs/resources/gitlab_integration.md index d6bd6063..2eca420d 100644 --- a/docs/resources/gitlab_integration.md +++ b/docs/resources/gitlab_integration.md @@ -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 diff --git a/spacelift/config_test.go b/spacelift/config_test.go index a1f49e3d..8b01c22a 100644 --- a/spacelift/config_test.go +++ b/spacelift/config_test.go @@ -112,6 +112,7 @@ var testConfig struct { APIHost string WebhookSecret string WebhookURL string + VCSChecks string } SpaceLevel struct { Name string @@ -121,6 +122,7 @@ var testConfig struct { Token string WebhookSecret string WebhookURL string + VCSChecks string } Repository struct { Name string diff --git a/spacelift/data_gitlab_integration.go b/spacelift/data_gitlab_integration.go index 0a99dcec..8e585656 100644 --- a/spacelift/data_gitlab_integration.go +++ b/spacelift/data_gitlab_integration.go @@ -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, + }, }, } } @@ -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)"` } @@ -117,6 +123,7 @@ func dataGitlabIntegrationRead(ctx context.Context, d *schema.ResourceData, meta } d.Set(gitLabLabels, labels) + d.Set(gitLabVCSChecks, gitLabIntegration.VCSChecks) return nil } diff --git a/spacelift/data_gitlab_integration_test.go b/spacelift/data_gitlab_integration_test.go index 6fe2e979..2d40a983 100644 --- a/spacelift/data_gitlab_integration_test.go +++ b/spacelift/data_gitlab_integration_test.go @@ -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)), ), }}) }) @@ -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)), ), }}) }) diff --git a/spacelift/gitlab_integration.go b/spacelift/gitlab_integration.go index cfcd5637..935afd08 100644 --- a/spacelift/gitlab_integration.go +++ b/spacelift/gitlab_integration.go @@ -13,4 +13,5 @@ const ( gitLabToken = "private_token" gitLabWebhookURL = "webhook_url" gitLabWebhookSecret = "webhook_secret" + gitLabVCSChecks = "vcs_checks" ) diff --git a/spacelift/internal/structs/gitlab_integration.go b/spacelift/internal/structs/gitlab_integration.go index f74f72e1..fb124b9e 100644 --- a/spacelift/internal/structs/gitlab_integration.go +++ b/spacelift/internal/structs/gitlab_integration.go @@ -15,4 +15,5 @@ type GitLabIntegration struct { UserFacingHost string `graphql:"userFacingHost"` WebhookSecret string `graphql:"webhookSecret"` WebhookURL string `graphql:"webhookUrl"` + VCSChecks string `graphql:"vcsChecks"` } diff --git a/spacelift/internal/structs/vcs/input.go b/spacelift/internal/structs/vcs/input.go index 55dc52dc..b5b64989 100644 --- a/spacelift/internal/structs/vcs/input.go +++ b/spacelift/internal/structs/vcs/input.go @@ -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"` } diff --git a/spacelift/internal/structs/vcs/update.go b/spacelift/internal/structs/vcs/update.go index fb7ecf03..608d7897 100644 --- a/spacelift/internal/structs/vcs/update.go +++ b/spacelift/internal/structs/vcs/update.go @@ -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"` } diff --git a/spacelift/resource_gitlab_integration.go b/spacelift/resource_gitlab_integration.go index 6339b46a..46b81461 100644 --- a/spacelift/resource_gitlab_integration.go +++ b/spacelift/resource_gitlab_integration.go @@ -108,6 +108,11 @@ 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, + }, }, } } @@ -124,6 +129,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)), @@ -172,6 +178,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)), }, } @@ -214,6 +221,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 { diff --git a/spacelift/resource_gitlab_integration_test.go b/spacelift/resource_gitlab_integration_test.go index eb09a37f..447bc711 100644 --- a/spacelift/resource_gitlab_integration_test.go +++ b/spacelift/resource_gitlab_integration_test.go @@ -16,14 +16,15 @@ func TestGitLabIntegrationResource(t *testing.T) { random := func() string { return acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) } var ( - name = "my-test-gitlab-integration-" + random() - host = "https://gitlab.com/" + random() - token = "access-" + random() - descr = "description " + random() - labels = `["label1", "label2"]` + name = "my-test-gitlab-integration-" + random() + host = "https://gitlab.com/" + random() + token = "access-" + random() + descr = "description " + random() + labels = `["label1", "label2"]` + vcsChecksDefault = "INDIVIDUAL" ) - 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 + `" @@ -32,6 +33,7 @@ func TestGitLabIntegrationResource(t *testing.T) { private_token = "` + token + `" description = "` + descr + `" labels = ` + labels + ` + vcs_checks = "` + vcsChecks + `" } ` } @@ -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)), @@ -83,6 +85,7 @@ func TestGitLabIntegrationResource(t *testing.T) { Attribute(gitLabIsDefault, Equals("false")), Attribute(gitLabDescription, Equals(descr)), AttributeNotPresent(gitLabLabels), + Attribute(gitLabVCSChecks, Equals(vcsChecksDefault)), ), }, { @@ -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)), @@ -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(vcsChecksDefault)), ), }, { - 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)), @@ -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(vcsChecksDefault)), ), }, { - 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, "AGGREGATED"), + Check: Resource( + resourceName, + Attribute(gitLabVCSChecks, Equals("AGGREGATED")), + ), + }, + { + Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, "ALL"), + Check: Resource( + resourceName, + Attribute(gitLabVCSChecks, Equals("ALL")), + ), + }, + { + Config: configGitLab(spaceLevel.APIHost, spaceLevel.Token, descr, labels, vcsChecksDefault), + Check: Resource( + resourceName, + Attribute(gitLabVCSChecks, Equals(vcsChecksDefault)), + ), + }, }) }) }