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
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ scalr_workspace_run_schedule
- `scalr_workspace`: added new attribute `var_files` ([#118](https://github.com/Scalr/terraform-provider-scalr/pull/118))

### 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))
- `scalr_variable`: updated the confusing error for multi-scope variables ([#119](https://github.com/Scalr/terraform-provider-scalr/pull/119))

Expand Down
1,047 changes: 1,047 additions & 0 deletions covprofile

Large diffs are not rendered by default.

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-20220517102326-518c471bd8cb
github.com/scalr/go-scalr v0.0.0-20220523083310-b14d71171237
)

require (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@ github.com/scalr/go-scalr v0.0.0-20220506112707-49f02107d87e h1:5ZiAqi2rN1/0qCc7
github.com/scalr/go-scalr v0.0.0-20220506112707-49f02107d87e/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-20220512113143-ef0e8bccfde7 h1:RxhSr6OqSGdHryMgF6XcDixnFUNxyWIikIQdQrkUcAk=
github.com/scalr/go-scalr v0.0.0-20220512113143-ef0e8bccfde7/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220517102326-518c471bd8cb h1:wT68qRSmY/xEY+ta2EbJxgMfII/U1g7cqcJH1yKIS+M=
github.com/scalr/go-scalr v0.0.0-20220517102326-518c471bd8cb/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220523083310-b14d71171237 h1:M9d2EOzFFBe/9fqkYpEKK0qKvh1RcZbA6dVWz4k3Rt8=
github.com/scalr/go-scalr v0.0.0-20220523083310-b14d71171237/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