Skip to content

Commit

Permalink
ENG-11522: Add sidecar log integration ID (#387)
Browse files Browse the repository at this point in the history
* Add log integration ID

* Update docs

---------

Co-authored-by: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com>
  • Loading branch information
ccampo133 and wcmjunior authored Apr 27, 2023
1 parent 6d6591d commit 39f030b
Show file tree
Hide file tree
Showing 12 changed files with 483 additions and 321 deletions.
46 changes: 26 additions & 20 deletions cyral/data_source_cyral_sidecar_bound_ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@ func dsourceSidecarBoundPortsSampleSidecarConfig() string {
return formatBasicSidecarIntoConfig(
basicSidecarResName,
accTestName(sidecarBoundPortsDataSourceName, "sidecar"),
"cloudFormation",
"cloudFormation", "",
)
}

func TestAccSidecarBoundPortsDataSource(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccSidecarBoundPortsConfig_EmptySidecarID(),
ExpectError: regexp.MustCompile(`The argument "sidecar_id" is required`),
},
{
Config: testAccSidecarBoundPortsConfig_NoBindings(),
Check: testAccSidecarBoundPortsCheck_NoBindings(),
},
{
Config: testAccSidecarBoundPortsConfig_MultipleBindings(),
Check: testAccSidecarBoundPortsCheck_MultipleBindings(),
resource.ParallelTest(
t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccSidecarBoundPortsConfig_EmptySidecarID(),
ExpectError: regexp.MustCompile(`The argument "sidecar_id" is required`),
},
{
Config: testAccSidecarBoundPortsConfig_NoBindings(),
Check: testAccSidecarBoundPortsCheck_NoBindings(),
},
{
Config: testAccSidecarBoundPortsConfig_MultipleBindings(),
Check: testAccSidecarBoundPortsCheck_MultipleBindings(),
},
},
},
})
)
}

func testAccSidecarBoundPortsConfig_EmptySidecarID() string {
Expand All @@ -50,10 +52,12 @@ func testAccSidecarBoundPortsConfig_EmptySidecarID() string {
func testAccSidecarBoundPortsConfig_NoBindings() string {
var config string
config += dsourceSidecarBoundPortsSampleSidecarConfig()
config += fmt.Sprintf(`
config += fmt.Sprintf(
`
data "cyral_sidecar_bound_ports" "sidecar_bound_ports_1" {
sidecar_id = %s
}`, basicSidecarID)
}`, basicSidecarID,
)
return config
}

Expand Down Expand Up @@ -150,7 +154,8 @@ func testAccSidecarBoundPortsConfig_MultipleBindings() string {
"cyral_repository.repo_4.id",
"cyral_sidecar_listener.listener_4.listener_id",
)
config += fmt.Sprintf(`
config += fmt.Sprintf(
`
data "cyral_sidecar_bound_ports" "sidecar_bound_ports_1" {
// depends_on is needed here so that we can retrieve the sidecar bound ports
// only after the bindings are created. Otherwise, the data source would
Expand All @@ -163,7 +168,8 @@ func testAccSidecarBoundPortsConfig_MultipleBindings() string {
cyral_repository_binding.binding_4
]
sidecar_id = %s
}`, basicSidecarID)
}`, basicSidecarID,
)

return config
}
Expand Down
46 changes: 27 additions & 19 deletions cyral/data_source_cyral_sidecar_cft_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,39 @@ const (
func TestAccSidecarCftTemplateDataSource(t *testing.T) {
cftConfig, cftFunc := setupSidecarCftTemplateTest()

resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: cftConfig,
Check: cftFunc,
resource.ParallelTest(
t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: cftConfig,
Check: cftFunc,
},
},
},
})
)
}

func setupSidecarCftTemplateTest() (string, resource.TestCheckFunc) {
var configuration string
configuration += formatBasicSidecarIntoConfig(
basicSidecarResName,
accTestName(sidecarCftTemplateDataSourceName, "sidecar"),
"cloudFormation",
"cloudFormation", "",
)
configuration += formatELKIntegrationDataIntoConfig(
ELKIntegration{
Name: accTestName(sidecarCftTemplateDataSourceName, "elk"),
KibanaURL: "kibana.local",
ESURL: "es.local",
},
)
configuration += formatDatadogIntegrationDataIntoConfig(
DatadogIntegration{
Name: accTestName(sidecarCftTemplateDataSourceName, "datadog"),
APIKey: "datadog-api-key",
},
)
configuration += formatELKIntegrationDataIntoConfig(ELKIntegration{
Name: accTestName(sidecarCftTemplateDataSourceName, "elk"),
KibanaURL: "kibana.local",
ESURL: "es.local",
})
configuration += formatDatadogIntegrationDataIntoConfig(DatadogIntegration{
Name: accTestName(sidecarCftTemplateDataSourceName, "datadog"),
APIKey: "datadog-api-key",
})
configuration += formatSidecarCftTemplateDataIntoConfig(
basicSidecarID,
"cyral_integration_elk.elk_integration.id",
Expand All @@ -62,7 +68,8 @@ func formatSidecarCftTemplateDataIntoConfig(
publiclyAccessible bool,
keyName string,
) string {
return fmt.Sprintf(`
return fmt.Sprintf(
`
data "cyral_sidecar_cft_template" "test_template" {
sidecar_id = %s
log_integration_id = %s
Expand All @@ -75,5 +82,6 @@ func formatSidecarCftTemplateDataIntoConfig(
output "output_template" {
value = data.cyral_sidecar_cft_template.test_template.template
}`, sidecarID, logIntegrationID, metricsIntegrationID, publiclyAccessible,
keyName)
keyName,
)
}
52 changes: 31 additions & 21 deletions cyral/data_source_cyral_sidecar_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@ const (
func TestAccSidecarIDDataSource(t *testing.T) {
nonExistentSidecarName := "some-non-existent-sidecar-name"

resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccSidecarIDConfig_EmptySidecarName(),
ExpectError: regexp.MustCompile(`The argument "sidecar_name" is required`),
},
{
Config: testAccSidecarIDConfig_NoSidecarFoundForGivenName(nonExistentSidecarName),
ExpectError: regexp.MustCompile(fmt.Sprintf("No sidecar found for name '%s'.",
nonExistentSidecarName)),
},
{
Config: testAccSidecarIDConfig_ExistentSidecar(),
Check: testAccSidecarIDCheck_ExistentSidecar(),
resource.ParallelTest(
t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccSidecarIDConfig_EmptySidecarName(),
ExpectError: regexp.MustCompile(`The argument "sidecar_name" is required`),
},
{
Config: testAccSidecarIDConfig_NoSidecarFoundForGivenName(nonExistentSidecarName),
ExpectError: regexp.MustCompile(
fmt.Sprintf(
"No sidecar found for name '%s'.",
nonExistentSidecarName,
),
),
},
{
Config: testAccSidecarIDConfig_ExistentSidecar(),
Check: testAccSidecarIDCheck_ExistentSidecar(),
},
},
},
})
)
}

func testAccSidecarIDConfig_EmptySidecarName() string {
Expand All @@ -43,24 +49,28 @@ func testAccSidecarIDConfig_EmptySidecarName() string {
}

func testAccSidecarIDConfig_NoSidecarFoundForGivenName(nonExistentSidecarName string) string {
return fmt.Sprintf(`
return fmt.Sprintf(
`
data "cyral_sidecar_id" "sidecar_id" {
sidecar_name = "%s"
}
`, nonExistentSidecarName)
`, nonExistentSidecarName,
)
}

func testAccSidecarIDConfig_ExistentSidecar() string {
var config string
config += formatBasicSidecarIntoConfig(
basicSidecarResName,
accTestName(sidecarIDDataSourceName, "sidecar"),
"cloudFormation",
"cloudFormation", "",
)
config += fmt.Sprintf(`
config += fmt.Sprintf(
`
data "cyral_sidecar_id" "sidecar_id" {
sidecar_name = cyral_sidecar.%s.name
}`, basicSidecarResName)
}`, basicSidecarResName,
)
return config
}

Expand Down
58 changes: 33 additions & 25 deletions cyral/data_source_cyral_sidecar_instance_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,32 @@ const (
func TestAccSidecarInstanceIDsDataSource(t *testing.T) {
nonExistentSidecarID := "some-non-existent-sidecar-id"

resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccSidecarInstanceIDsConfig_EmptySidecarID(),
ExpectError: regexp.MustCompile(`The argument "sidecar_id" is required`),
},
{
Config: testAccSidecarInstanceIDsConfig_NoSidecarFoundForGivenID(
nonExistentSidecarID,
),
ExpectError: regexp.MustCompile(fmt.Sprintf(
"Unable to retrieve sidecar details. SidecarID: %s",
nonExistentSidecarID,
)),
},
{
Config: testAccSidecarInstanceIDsConfig_NoSidecarInstances(),
Check: testAccSidecarInstanceIDsCheck_NoSidecarInstances(),
resource.ParallelTest(
t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccSidecarInstanceIDsConfig_EmptySidecarID(),
ExpectError: regexp.MustCompile(`The argument "sidecar_id" is required`),
},
{
Config: testAccSidecarInstanceIDsConfig_NoSidecarFoundForGivenID(
nonExistentSidecarID,
),
ExpectError: regexp.MustCompile(
fmt.Sprintf(
"Unable to retrieve sidecar details. SidecarID: %s",
nonExistentSidecarID,
),
),
},
{
Config: testAccSidecarInstanceIDsConfig_NoSidecarInstances(),
Check: testAccSidecarInstanceIDsCheck_NoSidecarInstances(),
},
},
},
})
)
}

func testAccSidecarInstanceIDsConfig_EmptySidecarID() string {
Expand All @@ -49,11 +53,13 @@ func testAccSidecarInstanceIDsConfig_EmptySidecarID() string {
func testAccSidecarInstanceIDsConfig_NoSidecarFoundForGivenID(
nonExistentSidecarID string,
) string {
return fmt.Sprintf(`
return fmt.Sprintf(
`
data "cyral_sidecar_instance_ids" "instance_ids" {
sidecar_id = "%s"
}
`, nonExistentSidecarID)
`, nonExistentSidecarID,
)
}

func testAccSidecarInstanceIDsConfig_NoSidecarInstances() string {
Expand All @@ -63,13 +69,15 @@ func testAccSidecarInstanceIDsConfig_NoSidecarInstances() string {
config += formatBasicSidecarIntoConfig(
basicSidecarResName,
accTestName(sidecarInstanceIDsDataSourceName, "sidecar"),
"cloudFormation",
"cloudFormation", "",
)

config += fmt.Sprintf(`
config += fmt.Sprintf(
`
data "cyral_sidecar_instance_ids" "instance_ids" {
sidecar_id = %s
}`, basicSidecarID)
}`, basicSidecarID,
)
return config
}

Expand Down
35 changes: 21 additions & 14 deletions cyral/resource_cyral_repository_access_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func accessGatewayConfig(ag accessGatewayTestConfig) string {
config += formatBasicSidecarIntoConfig(
ag.sidecarResName,
accTestName(repoAccessGatewayResourceName, ag.sidecarResName),
"docker",
"docker", "",
)

config += formatBasicSidecarListenerIntoConfig(
Expand Down Expand Up @@ -89,15 +89,17 @@ func TestAccRepositoryAccessGatewayResource(t *testing.T) {
ImportStateVerify: true,
ResourceName: resourceToImport,
}
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
intialTest,
updateSidecarTest,
updateBindingTest,
importTest,
resource.ParallelTest(
t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
intialTest,
updateSidecarTest,
updateBindingTest,
importTest,
},
},
})
)
}

func repositoryAccessGatewayTestStep(resName string, ag accessGatewayTestConfig) resource.TestStep {
Expand All @@ -113,22 +115,27 @@ func repoAccessGatewayCheck(resName, sidecarResName, bindingResName string) reso
checkFuncs := []resource.TestCheckFunc{
resource.TestCheckResourceAttrPair(
resFullName, SidecarIDKey,
fmt.Sprintf("cyral_sidecar.%s", sidecarResName), "id"),
fmt.Sprintf("cyral_sidecar.%s", sidecarResName), "id",
),
resource.TestCheckResourceAttrPair(
resFullName, RepositoryIDKey,
fmt.Sprintf("cyral_repository.%s", basicRepositoryResName), "id"),
fmt.Sprintf("cyral_repository.%s", basicRepositoryResName), "id",
),
resource.TestCheckResourceAttrPair(
resFullName, BindingIDKey,
fmt.Sprintf("cyral_repository_binding.%s", bindingResName), "binding_id"),
fmt.Sprintf("cyral_repository_binding.%s", bindingResName), "binding_id",
),
}
return resource.ComposeTestCheckFunc(checkFuncs...)
}

func repoAccessGatewayConfig(resName, sidecarID, bindingID string) string {
return fmt.Sprintf(`
return fmt.Sprintf(
`
resource "cyral_repository_access_gateway" "%s" {
repository_id = %s
sidecar_id = %s
binding_id = %s
}`, resName, basicRepositoryID, sidecarID, bindingID)
}`, resName, basicRepositoryID, sidecarID, bindingID,
)
}
Loading

0 comments on commit 39f030b

Please sign in to comment.