Skip to content

Commit

Permalink
ENG-7853: Modifying repository_binding resource is not removing old r…
Browse files Browse the repository at this point in the history
…esource
  • Loading branch information
VictorGFM authored Feb 10, 2022
1 parent 980780f commit 2fd6c6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cyral/resource_cyral_repository_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ func resourceRepositoryBinding() *schema.Resource {
"sidecar_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"repository_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"listener_port": {
Type: schema.TypeInt,
Expand Down
51 changes: 39 additions & 12 deletions cyral/resource_cyral_repository_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var initialRepositoryBindingConfig RepoBindingData = RepoBindingData{
RepositoryID: "1",
Enabled: false,
Listener: Listener{
Host: "local-repo-binding.local",
Host: "host.com",
Port: 3333,
},
}
Expand All @@ -22,7 +22,7 @@ var updatedRepositoryBindingConfig RepoBindingData = RepoBindingData{
RepositoryID: "2",
Enabled: true,
Listener: Listener{
Host: "local-repo-binding-update.local",
Host: "host-updated.com",
Port: 3334,
},
}
Expand All @@ -49,31 +49,58 @@ func TestAccRepositoryBindingResource(t *testing.T) {
func setupRepositoryBindingTest(integrationData RepoBindingData) (string, resource.TestCheckFunc) {
configuration := formatRepoBindingDataIntoConfig(integrationData)

sidecarResource := fmt.Sprintf("cyral_sidecar.test_repo_binding_sidecar_%s",
integrationData.SidecarID)
repositoryResource := fmt.Sprintf("cyral_repository.test_repo_binding_repository_%s",
integrationData.RepositoryID)

testFunction := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("cyral_repository_binding.repo_binding", "enabled", fmt.Sprintf("%t", integrationData.Enabled)),
resource.TestCheckResourceAttr("cyral_repository_binding.repo_binding", "enabled",
fmt.Sprintf("%t", integrationData.Enabled)),
resource.TestCheckResourceAttrPair("cyral_repository_binding.repo_binding", "repository_id",
repositoryResource, "id"),
resource.TestCheckResourceAttrPair("cyral_repository_binding.repo_binding", "sidecar_id",
sidecarResource, "id"),
resource.TestCheckResourceAttr("cyral_repository_binding.repo_binding", "listener_host",
integrationData.Listener.Host),
resource.TestCheckResourceAttr("cyral_repository_binding.repo_binding", "listener_port",
fmt.Sprintf("%d", integrationData.Listener.Port)),
)

return configuration, testFunction
}

func formatRepoBindingDataIntoConfig(data RepoBindingData) string {
return fmt.Sprintf(`
resource "cyral_repository" "test_repo_binding_repository" {
resource "cyral_sidecar" "test_repo_binding_sidecar_1" {
name = "tf-provider-repo-binding-sidecar-1"
deployment_method = "cloudFormation"
}
resource "cyral_repository" "test_repo_binding_repository_1" {
name = "tf-provider-repo-binding-repo-1"
type = "mongodb"
host = "mongodb.cyral.com"
port = 27017
name = "tf-provider-repo-binding-repo"
}
resource "cyral_sidecar" "test_repo_binding_sidecar" {
name = "tf-provider-repo-binding-sidecar"
resource "cyral_sidecar" "test_repo_binding_sidecar_2" {
name = "tf-provider-repo-binding-sidecar-2"
deployment_method = "cloudFormation"
}
resource "cyral_repository" "test_repo_binding_repository_2" {
name = "tf-provider-repo-binding-repo-2"
type = "mongodb"
host = "mongodb.cyral.com"
port = 27017
}
resource "cyral_repository_binding" "repo_binding" {
enabled = %t
repository_id = cyral_repository.test_repo_binding_repository.id
listener_port = cyral_repository.test_repo_binding_repository.port
sidecar_id = cyral_sidecar.test_repo_binding_sidecar.id
}`, data.Enabled)
sidecar_id = cyral_sidecar.test_repo_binding_sidecar_%s.id
repository_id = cyral_repository.test_repo_binding_repository_%s.id
listener_host = "%s"
listener_port = %d
}`, data.Enabled, data.SidecarID, data.RepositoryID, data.Listener.Host, data.Listener.Port)
}

0 comments on commit 2fd6c6e

Please sign in to comment.