Skip to content

Commit

Permalink
Check is_default when calculating diff for stacks and modules VCS set…
Browse files Browse the repository at this point in the history
…ting (#511)

* Check is_default when calculating id diff for stack vcs setting

* remaining vendors

* update docs

* Add test for gitlab

* Implement modules
  • Loading branch information
TheMacies authored Feb 6, 2024
1 parent fa45049 commit 1115e59
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 12 deletions.
20 changes: 20 additions & 0 deletions docs/resources/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Optional:

- `id` (String) ID of the Azure Devops integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default Azure DevOps integration


<a id="nestedblock--bitbucket_cloud"></a>
### Nested Schema for `bitbucket_cloud`
Expand All @@ -89,6 +93,10 @@ Optional:

- `id` (String) The ID of the Bitbucket Cloud integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default Bitbucket Cloud integration


<a id="nestedblock--bitbucket_datacenter"></a>
### Nested Schema for `bitbucket_datacenter`
Expand All @@ -101,6 +109,10 @@ Optional:

- `id` (String) The ID of the Bitbucket Datacenter integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default Bitbucket Datacenter integration


<a id="nestedblock--github_enterprise"></a>
### Nested Schema for `github_enterprise`
Expand All @@ -113,6 +125,10 @@ Optional:

- `id` (String) The ID of the GitHub Enterprise integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default GitHub Enterprise integration


<a id="nestedblock--gitlab"></a>
### Nested Schema for `gitlab`
Expand All @@ -125,6 +141,10 @@ Optional:

- `id` (String) ID of the Gitlab integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default GitLab integration

## Import

Import is supported using the following syntax:
Expand Down
20 changes: 20 additions & 0 deletions docs/resources/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ Optional:

- `id` (String) The ID of the Azure Devops integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default Azure DevOps integration


<a id="nestedblock--bitbucket_cloud"></a>
### Nested Schema for `bitbucket_cloud`
Expand All @@ -274,6 +278,10 @@ Optional:

- `id` (String) The ID of the Bitbucket Cloud integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default Bitbucket Cloud integration


<a id="nestedblock--bitbucket_datacenter"></a>
### Nested Schema for `bitbucket_datacenter`
Expand All @@ -286,6 +294,10 @@ Optional:

- `id` (String) The ID of the Bitbucket Datacenter integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default Bitbucket Datacenter integration


<a id="nestedblock--cloudformation"></a>
### Nested Schema for `cloudformation`
Expand All @@ -309,6 +321,10 @@ Optional:

- `id` (String) The ID of the GitHub Enterprise integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default GitHub Enterprise integration


<a id="nestedblock--gitlab"></a>
### Nested Schema for `gitlab`
Expand All @@ -321,6 +337,10 @@ Optional:

- `id` (String) The ID of the Gitlab integration. If not specified, the default integration will be used.

Read-Only:

- `is_default` (Boolean) Indicates whether this is the default GitLab integration


<a id="nestedblock--kubernetes"></a>
### Nested Schema for `kubernetes`
Expand Down
8 changes: 7 additions & 1 deletion spacelift/internal/structs/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type Module struct {
Space string `graphql:"space"`
TerraformProvider string `graphql:"terraformProvider"`
VCSIntegration *struct {
ID string `graphql:"id"`
ID string `graphql:"id"`
IsDefault bool `graphql:"isDefault"`
} `graphql:"vcsIntegration"`
WorkerPool *struct {
ID string `graphql:"id"`
Expand All @@ -41,22 +42,27 @@ func (m *Module) ExportVCSSettings(d *schema.ResourceData) error {
case VCSProviderAzureDevOps:
vcsSettings["id"] = m.VCSIntegration.ID
vcsSettings["project"] = m.Namespace
vcsSettings["is_default"] = m.VCSIntegration.IsDefault
fieldName = "azure_devops"
case VCSProviderBitbucketCloud:
vcsSettings["id"] = m.VCSIntegration.ID
vcsSettings["namespace"] = m.Namespace
vcsSettings["is_default"] = m.VCSIntegration.IsDefault
fieldName = "bitbucket_cloud"
case VCSProviderBitbucketDatacenter:
vcsSettings["id"] = m.VCSIntegration.ID
vcsSettings["namespace"] = m.Namespace
vcsSettings["is_default"] = m.VCSIntegration.IsDefault
fieldName = "bitbucket_datacenter"
case VCSProviderGitHubEnterprise:
vcsSettings["id"] = m.VCSIntegration.ID
vcsSettings["namespace"] = m.Namespace
vcsSettings["is_default"] = m.VCSIntegration.IsDefault
fieldName = "github_enterprise"
case VCSProviderGitlab:
vcsSettings["id"] = m.VCSIntegration.ID
vcsSettings["namespace"] = m.Namespace
vcsSettings["is_default"] = m.VCSIntegration.IsDefault
fieldName = "gitlab"
}

Expand Down
28 changes: 17 additions & 11 deletions spacelift/internal/structs/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type Stack struct {
Space string `graphql:"space"`
TerraformVersion *string `graphql:"terraformVersion"`
VCSIntegration *struct {
ID string `graphql:"id"`
ID string `graphql:"id"`
IsDefault bool `graphql:"isDefault"`
} `graphql:"vcsIntegration"`
VendorConfig struct {
Typename string `graphql:"__typename"`
Expand Down Expand Up @@ -135,28 +136,33 @@ func (s *Stack) VCSSettings() (string, map[string]interface{}) {
switch s.Provider {
case VCSProviderAzureDevOps:
return "azure_devops", map[string]interface{}{
"id": s.VCSIntegration.ID,
"project": s.Namespace,
"id": s.VCSIntegration.ID,
"project": s.Namespace,
"is_default": s.VCSIntegration.IsDefault,
}
case VCSProviderBitbucketCloud:
return "bitbucket_cloud", map[string]interface{}{
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"is_default": s.VCSIntegration.IsDefault,
}
case VCSProviderBitbucketDatacenter:
return "bitbucket_datacenter", map[string]interface{}{
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"is_default": s.VCSIntegration.IsDefault,
}
case VCSProviderGitHubEnterprise:
return "github_enterprise", map[string]interface{}{
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"is_default": s.VCSIntegration.IsDefault,
}
case VCSProviderGitlab:
return "gitlab", map[string]interface{}{
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"id": s.VCSIntegration.ID,
"namespace": s.Namespace,
"is_default": s.VCSIntegration.IsDefault,
}
case VCSProviderRawGit:
return "raw_git", map[string]interface{}{
Expand Down
50 changes: 50 additions & 0 deletions spacelift/resource_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ func resourceModule() *schema.Resource {
Type: schema.TypeString,
Description: "ID of the Azure Devops integration. If not specified, the default integration will be used.",
Optional: true,
DiffSuppressFunc: func(_, _, new string, res *schema.ResourceData) bool {
isDefault := res.Get("azure_devops.0.is_default").(bool)

return isDefault && new == ""
},
},
"project": {
Type: schema.TypeString,
Required: true,
Description: "The name of the Azure DevOps project",
ValidateDiagFunc: validations.DisallowEmptyString,
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this is the default Azure DevOps integration",
},
},
},
},
Expand All @@ -75,13 +85,23 @@ func resourceModule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the Bitbucket Cloud integration. If not specified, the default integration will be used.",
DiffSuppressFunc: func(_, _, new string, res *schema.ResourceData) bool {
isDefault := res.Get("bitbucket_cloud.0.is_default").(bool)

return isDefault && new == ""
},
},
"namespace": {
Type: schema.TypeString,
Required: true,
Description: "The Bitbucket project containing the repository",
ValidateDiagFunc: validations.DisallowEmptyString,
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this is the default Bitbucket Cloud integration",
},
},
},
},
Expand All @@ -97,13 +117,23 @@ func resourceModule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the Bitbucket Datacenter integration. If not specified, the default integration will be used.",
DiffSuppressFunc: func(_, _, new string, res *schema.ResourceData) bool {
isDefault := res.Get("bitbucket_datacenter.0.is_default").(bool)

return isDefault && new == ""
},
},
"namespace": {
Type: schema.TypeString,
Required: true,
Description: "The Bitbucket project containing the repository",
ValidateDiagFunc: validations.DisallowEmptyString,
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this is the default Bitbucket Datacenter integration",
},
},
},
},
Expand Down Expand Up @@ -141,6 +171,16 @@ func resourceModule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the GitHub Enterprise integration. If not specified, the default integration will be used.",
DiffSuppressFunc: func(_, _, new string, res *schema.ResourceData) bool {
isDefault := res.Get("github_enterprise.0.is_default").(bool)

return isDefault && new == ""
},
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this is the default GitHub Enterprise integration",
},
},
},
Expand All @@ -157,13 +197,23 @@ func resourceModule() *schema.Resource {
Type: schema.TypeString,
Description: "ID of the Gitlab integration. If not specified, the default integration will be used.",
Optional: true,
DiffSuppressFunc: func(_, _, new string, res *schema.ResourceData) bool {
isDefault := res.Get("gitlab.0.is_default").(bool)

return isDefault && new == ""
},
},
"namespace": {
Type: schema.TypeString,
Required: true,
Description: "The GitLab namespace containing the repository",
ValidateDiagFunc: validations.DisallowEmptyString,
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this is the default GitLab integration",
},
},
},
},
Expand Down
20 changes: 20 additions & 0 deletions spacelift/resource_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ func TestModuleResource(t *testing.T) {
})
})

t.Run("vcs integration id", func(t *testing.T) {
testSteps(t, []resource.TestStep{
{
Config: `resource "spacelift_module" "test" {
name = "integration-id-check-test"
repository = "multimodule"
branch = "main"
administrative = false
gitlab {
namespace = "spacelift-ci"
}
}`,
Check: Resource(
"spacelift_module.test",
Attribute("gitlab.0.id", Equals("gitlab-default-integration")),
),
},
})
})

t.Run("project root and custom name", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

Expand Down
Loading

0 comments on commit 1115e59

Please sign in to comment.