Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCALRCORE-21894 Scalr Provider > Error "Invalid Relationship" while switching between module and vcs provider #130

Merged
merged 10 commits into from
May 23, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Fixed
- `scalr_workspace`: vcs_repo and vcs_provider_id have to be passed simultaneously ([#130](https://github.com/Scalr/terraform-provider-scalr/pull/130))
- `scalr_policy_group`: remove environments and workspaces as includes ([#125](https://github.com/Scalr/terraform-provider-scalr/pull/125))

## [1.0.0-rc28] - 2022-04-01
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/scalr/go-scalr v0.0.0-20220510084130-4347446d3afe
github.com/scalr/go-scalr v0.0.0-20220512113143-ef0e8bccfde7
)

require (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ github.com/scalr/go-scalr v0.0.0-20220429130144-6ee1c7c3d93a h1:P4ANn4rx4tmVLUII
github.com/scalr/go-scalr v0.0.0-20220429130144-6ee1c7c3d93a/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220510084130-4347446d3afe h1:Gq6oYYwAe6b70HtxwG+3mfim87sHsZJVkE1DErQk2qY=
github.com/scalr/go-scalr v0.0.0-20220510084130-4347446d3afe/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220510133017-1bc7853bdbbd h1:PCzkYpwjwLHtKrxahMHbuwEkyZWp3bXGi8E62Neg1ug=
github.com/scalr/go-scalr v0.0.0-20220510133017-1bc7853bdbbd/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220512113143-ef0e8bccfde7 h1:RxhSr6OqSGdHryMgF6XcDixnFUNxyWIikIQdQrkUcAk=
github.com/scalr/go-scalr v0.0.0-20220512113143-ef0e8bccfde7/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
Expand Down
2 changes: 2 additions & 0 deletions scalr/resource_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func resourceScalrWorkspace() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"module_version_id"},
RequiredWith: []string{"vcs_repo"},
},
"module_version_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -138,6 +139,7 @@ func resourceScalrWorkspace() *schema.Resource {
MinItems: 1,
MaxItems: 1,
ConflictsWith: []string{"module_version_id"},
RequiredWith: []string{"vcs_provider_id"},
Copy link
Member

Choose a reason for hiding this comment

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

@RomanMytsko we need to cover new changes with tests

Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Expand Down
49 changes: 49 additions & 0 deletions scalr/resource_scalr_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -57,6 +58,25 @@ func TestAccScalrWorkspace_basic(t *testing.T) {
})
}

func TestAccScalrWorkspace_create_missed_vcs_attr(t *testing.T) {
rInt := GetRandomInteger()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccScalrWorkspaceMissedVcsProvider(rInt),
ExpectError: regexp.MustCompile("config is invalid: \"vcs_repo\": all of `vcs_provider_id,vcs_repo` must be specified"),
},
{
Config: testAccScalrWorkspaceMissedVcsRepo(rInt),
ExpectError: regexp.MustCompile("config is invalid: \"vcs_provider_id\": all of `vcs_provider_id,vcs_repo` must be specified"),
},
},
})
}

func TestAccScalrWorkspace_monorepo(t *testing.T) {
workspace := &scalr.Workspace{}
rInt := GetRandomInteger()
Expand Down Expand Up @@ -495,6 +515,35 @@ resource "scalr_workspace" "test" {
}`)
}

func testAccScalrWorkspaceMissedVcsProvider(rInt int) string {
return fmt.Sprintf(testAccScalrWorkspaceCommonConfig, rInt, defaultAccount, `
resource "scalr_workspace" "test" {
name = "workspace-updated"
environment_id = scalr_environment.test.id
auto_apply = false
operations = false
terraform_version = "0.12.19"
working_directory = "terraform/test"
vcs_repo {
identifier = "TestRepo/local"
branch = "main"
}
}`)
}

func testAccScalrWorkspaceMissedVcsRepo(rInt int) string {
return fmt.Sprintf(testAccScalrWorkspaceCommonConfig, rInt, defaultAccount, `
resource "scalr_workspace" "test" {
name = "workspace-updated"
environment_id = scalr_environment.test.id
auto_apply = false
operations = false
terraform_version = "0.12.19"
working_directory = "terraform/test"
vcs_provider_id = "test_provider_id"
}`)
}

func testAccScalrWorkspaceUpdateWithoutHooks(rInt int) string {
return fmt.Sprintf(testAccScalrWorkspaceCommonConfig, rInt, defaultAccount, `
resource "scalr_workspace" "test" {
Expand Down