From 7edd5d892fcb07a95cbdf7d14ffdd529d88b1302 Mon Sep 17 00:00:00 2001 From: Wilson de Carvalho <796900+wcmjunior@users.noreply.github.com> Date: Thu, 2 Nov 2023 00:29:21 -0700 Subject: [PATCH] Stable version: all packages refactored --- .../data_source_cyral_integration_idp.go | 2 +- .../data_source_cyral_integration_idp_test.go | 2 +- .../data_source_cyral_sidecar_cft_template.go | 30 ++--- ..._source_cyral_sidecar_cft_template_test.go | 2 +- .../data_source_cyral_sidecar_instance_ids.go | 2 +- ..._source_cyral_sidecar_instance_ids_test.go | 2 +- .../{ => deprecated}/integrations_data.go | 2 +- .../integrations_data_test.go | 16 +-- .../{ => deprecated}/model_integration_idp.go | 2 +- .../resource_cyral_integration_datadog.go | 2 +- ...resource_cyral_integration_datadog_test.go | 10 +- .../resource_cyral_integration_elk.go | 2 +- .../resource_cyral_integration_elk_test.go | 10 +- .../resource_cyral_integration_idp.go | 23 +--- .../resource_cyral_integration_idp_test.go | 2 +- .../resource_cyral_integration_logstash.go | 2 +- ...esource_cyral_integration_logstash_test.go | 16 +-- .../resource_cyral_integration_looker.go | 2 +- .../resource_cyral_integration_looker_test.go | 12 +- .../resource_cyral_integration_splunk.go | 2 +- .../resource_cyral_integration_splunk_test.go | 12 +- .../resource_cyral_integration_sumo_logic.go | 2 +- ...ource_cyral_integration_sumo_logic_test.go | 12 +- .../resource_cyral_integration_aws_iam.go | 2 +- ...resource_cyral_integration_aws_iam_test.go | 2 +- .../resource_cyral_integration_mfa_duo.go | 15 +-- ...resource_cyral_integration_mfa_duo_test.go | 16 +-- .../model_integration_confextension.go | 2 +- .../resource_cyral_integration_pager_duty.go | 15 +-- ...ource_cyral_integration_pager_duty_test.go | 14 +-- .../model_cyral_integration_hcvault.go | 2 +- .../resource_cyral_integration_hcvault.go | 2 +- ...resource_cyral_integration_hcvault_test.go | 12 +- .../data_source_cyral_integration_idp_saml.go | 2 +- ..._source_cyral_integration_idp_saml_test.go | 32 +++--- .../model_integration_idp_generic_saml.go | 16 ++- .../resource_cyral_integration_idp_saml.go | 2 +- ...source_cyral_integration_idp_saml_draft.go | 2 +- ...e_cyral_integration_idp_saml_draft_test.go | 24 ++-- ...esource_cyral_integration_idp_saml_test.go | 2 +- .../data_source_cyral_integration_logging.go | 2 +- ...a_source_cyral_integration_logging_test.go | 16 +-- .../logging}/model_integration_logging.go | 2 +- .../resource_cyral_integration_logging.go | 2 +- ...resource_cyral_integration_logging_test.go | 98 ++++++++-------- ...resource_cyral_integration_slack_alerts.go | 2 +- ...rce_cyral_integration_slack_alerts_test.go | 12 +- .../resource_cyral_integration_teams.go | 2 +- .../resource_cyral_integration_teams_test.go | 12 +- .../data_source_cyral_permission.go | 2 +- .../data_source_cyral_permission_test.go | 12 +- cyral/internal/permission/model_permission.go | 39 +++++++ cyral/internal/{ => policy}/model_policy.go | 2 +- .../{ => policy}/resource_cyral_policy.go | 20 +--- .../resource_cyral_policy_test.go | 16 +-- .../rule}/resource_cyral_policy_rule.go | 4 +- .../rule}/resource_cyral_policy_rule_test.go | 16 +-- .../model_rego_policy_instance.go | 2 +- .../resource_cyral_rego_policy_instance.go | 2 +- ...esource_cyral_rego_policy_instance_test.go | 54 ++++----- .../resource_cyral_repository_binding.go | 2 +- .../resource_cyral_repository_binding_test.go | 4 +- ...resource_cyral_repository_conf_analysis.go | 2 +- ...rce_cyral_repository_conf_analysis_test.go | 6 +- .../resource_cyral_repository_conf_auth.go | 2 +- ...esource_cyral_repository_conf_auth_test.go | 4 +- cyral/internal/repository/datamap/model.go | 1 + cyral/internal/repository/datamap/resource.go | 4 +- .../{ => role}/data_source_cyral_role.go | 2 +- .../{ => role}/data_source_cyral_role_test.go | 2 +- .../model_role.go} | 41 +------ .../{ => role}/resource_cyral_role.go | 13 ++- .../resource_cyral_role_sso_groups.go | 2 +- .../resource_cyral_role_sso_groups_test.go | 6 +- .../{ => role}/resource_cyral_role_test.go | 2 +- .../data_source_cyral_saml_certificate.go | 2 +- ...data_source_cyral_saml_certificate_test.go | 2 +- .../data_source_cyral_saml_configuration.go | 11 +- ...ta_source_cyral_saml_configuration_test.go | 2 +- .../model_service_account.go | 2 +- .../resource_cyral_service_account.go | 2 +- .../resource_cyral_service_account_test.go | 33 +++--- cyral/internal/sweep/sweep_test.go | 10 +- .../data_source_cyral_system_info.go | 2 +- .../data_source_cyral_system_info_test.go | 8 +- cyral/provider/provider.go | 105 ++++++++++-------- cyral/utils/utils.go | 10 ++ 87 files changed, 479 insertions(+), 451 deletions(-) rename cyral/internal/{ => deprecated}/data_source_cyral_integration_idp.go (99%) rename cyral/internal/{ => deprecated}/data_source_cyral_integration_idp_test.go (64%) rename cyral/internal/{sidecar => deprecated}/data_source_cyral_sidecar_cft_template.go (90%) rename cyral/internal/{sidecar => deprecated}/data_source_cyral_sidecar_cft_template_test.go (98%) rename cyral/internal/{sidecar/instance => deprecated}/data_source_cyral_sidecar_instance_ids.go (99%) rename cyral/internal/{sidecar/instance => deprecated}/data_source_cyral_sidecar_instance_ids_test.go (99%) rename cyral/internal/{ => deprecated}/integrations_data.go (98%) rename cyral/internal/{ => deprecated}/integrations_data_test.go (72%) rename cyral/internal/{ => deprecated}/model_integration_idp.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_datadog.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_datadog_test.go (81%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_elk.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_elk_test.go (84%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_idp.go (98%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_idp_test.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_logstash.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_logstash_test.go (84%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_looker.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_looker_test.go (78%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_splunk.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_splunk_test.go (84%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_sumo_logic.go (99%) rename cyral/internal/{ => deprecated}/resource_cyral_integration_sumo_logic_test.go (78%) rename cyral/internal/{ => integration/awsiam}/resource_cyral_integration_aws_iam.go (99%) rename cyral/internal/{ => integration/awsiam}/resource_cyral_integration_aws_iam_test.go (99%) rename cyral/internal/{ => integration/confextension/mfaduo}/resource_cyral_integration_mfa_duo.go (74%) rename cyral/internal/{ => integration/confextension/mfaduo}/resource_cyral_integration_mfa_duo_test.go (82%) rename cyral/internal/{ => integration/confextension}/model_integration_confextension.go (99%) rename cyral/internal/{ => integration/confextension/pagerduty}/resource_cyral_integration_pager_duty.go (65%) rename cyral/internal/{ => integration/confextension/pagerduty}/resource_cyral_integration_pager_duty_test.go (78%) rename cyral/internal/{ => integration/hcvault}/model_cyral_integration_hcvault.go (96%) rename cyral/internal/{ => integration/hcvault}/resource_cyral_integration_hcvault.go (99%) rename cyral/internal/{ => integration/hcvault}/resource_cyral_integration_hcvault_test.go (83%) rename cyral/internal/{ => integration/idpsaml}/data_source_cyral_integration_idp_saml.go (99%) rename cyral/internal/{ => integration/idpsaml}/data_source_cyral_integration_idp_saml_test.go (87%) rename cyral/internal/{ => integration/idpsaml}/model_integration_idp_generic_saml.go (94%) rename cyral/internal/{ => integration/idpsaml}/resource_cyral_integration_idp_saml.go (99%) rename cyral/internal/{ => integration/idpsaml}/resource_cyral_integration_idp_saml_draft.go (99%) rename cyral/internal/{ => integration/idpsaml}/resource_cyral_integration_idp_saml_draft_test.go (88%) rename cyral/internal/{ => integration/idpsaml}/resource_cyral_integration_idp_saml_test.go (99%) rename cyral/internal/{ => integration/logging}/data_source_cyral_integration_logging.go (99%) rename cyral/internal/{ => integration/logging}/data_source_cyral_integration_logging_test.go (88%) rename cyral/internal/{ => integration/logging}/model_integration_logging.go (99%) rename cyral/internal/{ => integration/logging}/resource_cyral_integration_logging.go (99%) rename cyral/internal/{ => integration/logging}/resource_cyral_integration_logging_test.go (81%) rename cyral/internal/{ => integration/slack}/resource_cyral_integration_slack_alerts.go (99%) rename cyral/internal/{ => integration/slack}/resource_cyral_integration_slack_alerts_test.go (77%) rename cyral/internal/{ => integration/teams}/resource_cyral_integration_teams.go (99%) rename cyral/internal/{ => integration/teams}/resource_cyral_integration_teams_test.go (79%) rename cyral/internal/{ => permission}/data_source_cyral_permission.go (99%) rename cyral/internal/{ => permission}/data_source_cyral_permission_test.go (80%) create mode 100644 cyral/internal/permission/model_permission.go rename cyral/internal/{ => policy}/model_policy.go (97%) rename cyral/internal/{ => policy}/resource_cyral_policy.go (95%) rename cyral/internal/{ => policy}/resource_cyral_policy_test.go (87%) rename cyral/internal/{ => policy/rule}/resource_cyral_policy_rule.go (99%) rename cyral/internal/{ => policy/rule}/resource_cyral_policy_rule_test.go (95%) rename cyral/internal/{ => regopolicy}/model_rego_policy_instance.go (99%) rename cyral/internal/{ => regopolicy}/resource_cyral_rego_policy_instance.go (99%) rename cyral/internal/{ => regopolicy}/resource_cyral_rego_policy_instance_test.go (77%) rename cyral/internal/repository/{bind => binding}/resource_cyral_repository_binding.go (99%) rename cyral/internal/repository/{bind => binding}/resource_cyral_repository_binding_test.go (97%) rename cyral/internal/repository/{conf/analysis => confanalysis}/resource_cyral_repository_conf_analysis.go (99%) rename cyral/internal/repository/{conf/analysis => confanalysis}/resource_cyral_repository_conf_analysis_test.go (98%) rename cyral/internal/repository/{conf/auth => confauth}/resource_cyral_repository_conf_auth.go (99%) rename cyral/internal/repository/{conf/auth => confauth}/resource_cyral_repository_conf_auth_test.go (97%) rename cyral/internal/{ => role}/data_source_cyral_role.go (99%) rename cyral/internal/{ => role}/data_source_cyral_role_test.go (97%) rename cyral/internal/{model_permission.go => role/model_role.go} (78%) rename cyral/internal/{ => role}/resource_cyral_role.go (94%) rename cyral/internal/{ => role}/resource_cyral_role_sso_groups.go (99%) rename cyral/internal/{ => role}/resource_cyral_role_sso_groups_test.go (97%) rename cyral/internal/{ => role}/resource_cyral_role_test.go (99%) rename cyral/internal/{ => samlcertificate}/data_source_cyral_saml_certificate.go (98%) rename cyral/internal/{ => samlcertificate}/data_source_cyral_saml_certificate_test.go (96%) rename cyral/internal/{ => samlconfiguration}/data_source_cyral_saml_configuration.go (95%) rename cyral/internal/{ => samlconfiguration}/data_source_cyral_saml_configuration_test.go (99%) rename cyral/internal/{ => serviceaccount}/model_service_account.go (98%) rename cyral/internal/{ => serviceaccount}/resource_cyral_service_account.go (99%) rename cyral/internal/{ => serviceaccount}/resource_cyral_service_account_test.go (84%) rename cyral/internal/{ => systeminfo}/data_source_cyral_system_info.go (98%) rename cyral/internal/{ => systeminfo}/data_source_cyral_system_info_test.go (87%) diff --git a/cyral/internal/data_source_cyral_integration_idp.go b/cyral/internal/deprecated/data_source_cyral_integration_idp.go similarity index 99% rename from cyral/internal/data_source_cyral_integration_idp.go rename to cyral/internal/deprecated/data_source_cyral_integration_idp.go index 8013a817..e571301a 100644 --- a/cyral/internal/data_source_cyral_integration_idp.go +++ b/cyral/internal/deprecated/data_source_cyral_integration_idp.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "context" diff --git a/cyral/internal/data_source_cyral_integration_idp_test.go b/cyral/internal/deprecated/data_source_cyral_integration_idp_test.go similarity index 64% rename from cyral/internal/data_source_cyral_integration_idp_test.go rename to cyral/internal/deprecated/data_source_cyral_integration_idp_test.go index 9be0febd..ce18db03 100644 --- a/cyral/internal/data_source_cyral_integration_idp_test.go +++ b/cyral/internal/deprecated/data_source_cyral_integration_idp_test.go @@ -1,3 +1,3 @@ -package internal_test +package deprecated_test // TODO: ACC tests -aholmquist 2022-08-29 diff --git a/cyral/internal/sidecar/data_source_cyral_sidecar_cft_template.go b/cyral/internal/deprecated/data_source_cyral_sidecar_cft_template.go similarity index 90% rename from cyral/internal/sidecar/data_source_cyral_sidecar_cft_template.go rename to cyral/internal/deprecated/data_source_cyral_sidecar_cft_template.go index 9f0ff084..f1c94986 100644 --- a/cyral/internal/sidecar/data_source_cyral_sidecar_cft_template.go +++ b/cyral/internal/deprecated/data_source_cyral_sidecar_cft_template.go @@ -1,4 +1,4 @@ -package sidecar +package deprecated import ( "encoding/json" @@ -9,7 +9,7 @@ import ( "strings" "github.com/cyralinc/terraform-provider-cyral/cyral/client" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -115,23 +115,23 @@ func removePortFromURL(url string) string { return strings.Split(url, ":")[0] } -func getSidecarData(c *client.Client, d *schema.ResourceData) (SidecarData, error) { +func getSidecarData(c *client.Client, d *schema.ResourceData) (sidecar.SidecarData, error) { url := fmt.Sprintf("https://%s/v1/sidecars/%s", c.ControlPlane, d.Get("sidecar_id").(string)) body, err := c.DoRequest(url, http.MethodGet, nil) if err != nil { - return SidecarData{}, err + return sidecar.SidecarData{}, err } - response := SidecarData{} + response := sidecar.SidecarData{} if err := json.Unmarshal(body, &response); err != nil { - return SidecarData{}, err + return sidecar.SidecarData{}, err } return response, nil } -func getLogIntegrations(c *client.Client, d *schema.ResourceData) ([]internal.IntegrationsData, error) { +func getLogIntegrations(c *client.Client, d *schema.ResourceData) ([]IntegrationsData, error) { url := fmt.Sprintf("https://%s/integrations/logging/", removePortFromURL(c.ControlPlane)) body, err := c.DoRequest(url, http.MethodGet, nil) @@ -139,7 +139,7 @@ func getLogIntegrations(c *client.Client, d *schema.ResourceData) ([]internal.In return nil, err } - response := []internal.IntegrationsData{} + response := []IntegrationsData{} if err := json.Unmarshal(body, &response); err != nil { return nil, err } @@ -147,7 +147,7 @@ func getLogIntegrations(c *client.Client, d *schema.ResourceData) ([]internal.In return response, nil } -func getMetricsIntegrations(c *client.Client, d *schema.ResourceData) ([]internal.IntegrationsData, error) { +func getMetricsIntegrations(c *client.Client, d *schema.ResourceData) ([]IntegrationsData, error) { url := fmt.Sprintf("https://%s/integrations/metrics", removePortFromURL(c.ControlPlane)) body, err := c.DoRequest(url, http.MethodGet, nil) @@ -155,7 +155,7 @@ func getMetricsIntegrations(c *client.Client, d *schema.ResourceData) ([]interna return nil, err } - response := []internal.IntegrationsData{} + response := []IntegrationsData{} if err := json.Unmarshal(body, &response); err != nil { return nil, err } @@ -163,19 +163,19 @@ func getMetricsIntegrations(c *client.Client, d *schema.ResourceData) ([]interna return response, nil } -func filterIntegrationData(integrations []internal.IntegrationsData, id string) *internal.IntegrationsData { +func filterIntegrationData(integrations []IntegrationsData, id string) *IntegrationsData { for _, it := range integrations { if it.Id == id { return &it } } - return internal.NewDefaultIntegrationsData() + return NewDefaultIntegrationsData() } func getTemplateForSidecarProperties( - sidecarData SidecarData, - logging []internal.IntegrationsData, - metrics []internal.IntegrationsData, + sidecarData sidecar.SidecarData, + logging []IntegrationsData, + metrics []IntegrationsData, c *client.Client, d *schema.ResourceData, ) ([]byte, error) { diff --git a/cyral/internal/sidecar/data_source_cyral_sidecar_cft_template_test.go b/cyral/internal/deprecated/data_source_cyral_sidecar_cft_template_test.go similarity index 98% rename from cyral/internal/sidecar/data_source_cyral_sidecar_cft_template_test.go rename to cyral/internal/deprecated/data_source_cyral_sidecar_cft_template_test.go index 7731233b..16f1a441 100644 --- a/cyral/internal/sidecar/data_source_cyral_sidecar_cft_template_test.go +++ b/cyral/internal/deprecated/data_source_cyral_sidecar_cft_template_test.go @@ -1,4 +1,4 @@ -package sidecar_test +package deprecated_test import ( "fmt" diff --git a/cyral/internal/sidecar/instance/data_source_cyral_sidecar_instance_ids.go b/cyral/internal/deprecated/data_source_cyral_sidecar_instance_ids.go similarity index 99% rename from cyral/internal/sidecar/instance/data_source_cyral_sidecar_instance_ids.go rename to cyral/internal/deprecated/data_source_cyral_sidecar_instance_ids.go index 93a96462..50b7e581 100644 --- a/cyral/internal/sidecar/instance/data_source_cyral_sidecar_instance_ids.go +++ b/cyral/internal/deprecated/data_source_cyral_sidecar_instance_ids.go @@ -1,4 +1,4 @@ -package instance +package deprecated import ( "context" diff --git a/cyral/internal/sidecar/instance/data_source_cyral_sidecar_instance_ids_test.go b/cyral/internal/deprecated/data_source_cyral_sidecar_instance_ids_test.go similarity index 99% rename from cyral/internal/sidecar/instance/data_source_cyral_sidecar_instance_ids_test.go rename to cyral/internal/deprecated/data_source_cyral_sidecar_instance_ids_test.go index 94e874fb..681ef0f6 100644 --- a/cyral/internal/sidecar/instance/data_source_cyral_sidecar_instance_ids_test.go +++ b/cyral/internal/deprecated/data_source_cyral_sidecar_instance_ids_test.go @@ -1,4 +1,4 @@ -package instance_test +package deprecated_test import ( "fmt" diff --git a/cyral/internal/integrations_data.go b/cyral/internal/deprecated/integrations_data.go similarity index 98% rename from cyral/internal/integrations_data.go rename to cyral/internal/deprecated/integrations_data.go index a34b3b7d..14ef1a0b 100644 --- a/cyral/internal/integrations_data.go +++ b/cyral/internal/deprecated/integrations_data.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "encoding/json" diff --git a/cyral/internal/integrations_data_test.go b/cyral/internal/deprecated/integrations_data_test.go similarity index 72% rename from cyral/internal/integrations_data_test.go rename to cyral/internal/deprecated/integrations_data_test.go index 65a1233f..0a6a4b34 100644 --- a/cyral/internal/integrations_data_test.go +++ b/cyral/internal/deprecated/integrations_data_test.go @@ -1,20 +1,20 @@ -package internal_test +package deprecated_test import ( "encoding/json" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/stretchr/testify/require" ) -func sampleSplunkIntegrationsData() *internal.IntegrationsData { - return &internal.IntegrationsData{ +func sampleSplunkIntegrationsData() *deprecated.IntegrationsData { + return &deprecated.IntegrationsData{ Id: "id1", Type: "splunk", Name: "name1", Label: "label1", - Value: internal.SplunkIntegration{ + Value: deprecated.SplunkIntegration{ Name: "name1", AccessToken: "accessToken1", Port: 0, @@ -27,8 +27,8 @@ func sampleSplunkIntegrationsData() *internal.IntegrationsData { } func TestIntegrationsData_GetValue_Default(t *testing.T) { - integrationsData := internal.NewDefaultIntegrationsData() - expected := internal.NewDefaultIntegrationsData().Value.(string) + integrationsData := deprecated.NewDefaultIntegrationsData() + expected := deprecated.NewDefaultIntegrationsData().Value.(string) actual, err := integrationsData.GetValue() require.NoError(t, err) require.Equal(t, expected, actual) @@ -37,7 +37,7 @@ func TestIntegrationsData_GetValue_Default(t *testing.T) { func TestIntegrationsData_GetValue_Splunk(t *testing.T) { splunkIntegrationsData := sampleSplunkIntegrationsData() - expectedBytes, err := json.Marshal(internal.SplunkIntegration{ + expectedBytes, err := json.Marshal(deprecated.SplunkIntegration{ Name: "name1", AccessToken: "accessToken1", Port: 0, diff --git a/cyral/internal/model_integration_idp.go b/cyral/internal/deprecated/model_integration_idp.go similarity index 99% rename from cyral/internal/model_integration_idp.go rename to cyral/internal/deprecated/model_integration_idp.go index 50742b30..cd0f17d2 100644 --- a/cyral/internal/model_integration_idp.go +++ b/cyral/internal/deprecated/model_integration_idp.go @@ -1,4 +1,4 @@ -package internal +package deprecated type IdPIntegrations struct { Connections *Connections `json:"connections,omitempty"` diff --git a/cyral/internal/resource_cyral_integration_datadog.go b/cyral/internal/deprecated/resource_cyral_integration_datadog.go similarity index 99% rename from cyral/internal/resource_cyral_integration_datadog.go rename to cyral/internal/deprecated/resource_cyral_integration_datadog.go index 1495a6fe..c4229d44 100644 --- a/cyral/internal/resource_cyral_integration_datadog.go +++ b/cyral/internal/deprecated/resource_cyral_integration_datadog.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_datadog_test.go b/cyral/internal/deprecated/resource_cyral_integration_datadog_test.go similarity index 81% rename from cyral/internal/resource_cyral_integration_datadog_test.go rename to cyral/internal/deprecated/resource_cyral_integration_datadog_test.go index 92dbf966..83361419 100644 --- a/cyral/internal/resource_cyral_integration_datadog_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_datadog_test.go @@ -1,9 +1,9 @@ -package internal_test +package deprecated_test import ( "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,12 +14,12 @@ const ( integrationDatadogResourceName = "integration-datadog" ) -var initialDatadogConfig internal.DatadogIntegration = internal.DatadogIntegration{ +var initialDatadogConfig deprecated.DatadogIntegration = deprecated.DatadogIntegration{ Name: utils.AccTestName(integrationDatadogResourceName, "datadog"), APIKey: "some-api-key", } -var updatedDatadogConfig internal.DatadogIntegration = internal.DatadogIntegration{ +var updatedDatadogConfig deprecated.DatadogIntegration = deprecated.DatadogIntegration{ Name: utils.AccTestName(integrationDatadogResourceName, "datadog-updated"), APIKey: "some-api-key-updated", } @@ -52,7 +52,7 @@ func TestAccDatadogIntegrationResource(t *testing.T) { }) } -func setupDatadogTest(d internal.DatadogIntegration) (string, resource.TestCheckFunc) { +func setupDatadogTest(d deprecated.DatadogIntegration) (string, resource.TestCheckFunc) { configuration := utils.FormatDatadogIntegrationDataIntoConfig(d.Name, d.APIKey) testFunction := resource.ComposeTestCheckFunc( diff --git a/cyral/internal/resource_cyral_integration_elk.go b/cyral/internal/deprecated/resource_cyral_integration_elk.go similarity index 99% rename from cyral/internal/resource_cyral_integration_elk.go rename to cyral/internal/deprecated/resource_cyral_integration_elk.go index 7d7aa7f8..3ca9b897 100644 --- a/cyral/internal/resource_cyral_integration_elk.go +++ b/cyral/internal/deprecated/resource_cyral_integration_elk.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_elk_test.go b/cyral/internal/deprecated/resource_cyral_integration_elk_test.go similarity index 84% rename from cyral/internal/resource_cyral_integration_elk_test.go rename to cyral/internal/deprecated/resource_cyral_integration_elk_test.go index 0265bc40..c8c295a0 100644 --- a/cyral/internal/resource_cyral_integration_elk_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_elk_test.go @@ -1,9 +1,9 @@ -package internal_test +package deprecated_test import ( "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,13 +14,13 @@ const ( integrationELKResourceName = "integration-elk" ) -var initialELKConfig internal.ELKIntegration = internal.ELKIntegration{ +var initialELKConfig deprecated.ELKIntegration = deprecated.ELKIntegration{ Name: utils.AccTestName(integrationELKResourceName, "ELK"), KibanaURL: "kibana.local", ESURL: "es.local", } -var updatedELKConfig internal.ELKIntegration = internal.ELKIntegration{ +var updatedELKConfig deprecated.ELKIntegration = deprecated.ELKIntegration{ Name: utils.AccTestName(integrationELKResourceName, "ELK-updated"), KibanaURL: "kibana-update.local", ESURL: "es-update.local", @@ -54,7 +54,7 @@ func TestAccELKIntegrationResource(t *testing.T) { }) } -func setupELKTest(d internal.ELKIntegration) (string, resource.TestCheckFunc) { +func setupELKTest(d deprecated.ELKIntegration) (string, resource.TestCheckFunc) { configuration := utils.FormatELKIntegrationDataIntoConfig(d.Name, d.KibanaURL, d.ESURL) testFunction := resource.ComposeTestCheckFunc( diff --git a/cyral/internal/resource_cyral_integration_idp.go b/cyral/internal/deprecated/resource_cyral_integration_idp.go similarity index 98% rename from cyral/internal/resource_cyral_integration_idp.go rename to cyral/internal/deprecated/resource_cyral_integration_idp.go index c14945c7..d7631c31 100644 --- a/cyral/internal/resource_cyral_integration_idp.go +++ b/cyral/internal/deprecated/resource_cyral_integration_idp.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "context" @@ -8,6 +8,7 @@ import ( "github.com/cyralinc/terraform-provider-cyral/cyral/client" "github.com/cyralinc/terraform-provider-cyral/cyral/core" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/idpsaml" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -288,8 +289,8 @@ func resourceIntegrationIdPCreate(identityProvider string) schema.CreateContextF CreateURL: func(d *schema.ResourceData, c *client.Client) string { return fmt.Sprintf("https://%s/v1/conf/identityProviders/%s", c.ControlPlane, d.Id()) }, - NewResourceData: func() core.ResourceData { return &IdentityProviderData{} }, - NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &IdentityProviderData{} }, + NewResourceData: func() core.ResourceData { return &idpsaml.IdentityProviderData{} }, + NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &idpsaml.IdentityProviderData{} }, }, readIdentityProviderConfig, )(ctx, d, m) @@ -369,7 +370,7 @@ var readIdentityProviderConfig = core.ResourceOperationConfig{ CreateURL: func(d *schema.ResourceData, c *client.Client) string { return fmt.Sprintf("https://%s/v1/conf/identityProviders/%s", c.ControlPlane, d.Id()) }, - NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &IdentityProviderData{} }, + NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &idpsaml.IdentityProviderData{} }, } var deleteIntegrationIdPConfig = core.ResourceOperationConfig{ @@ -565,17 +566,3 @@ func (response AliasBasedResponse) WriteToSchema(d *schema.ResourceData) error { d.SetId(response.Alias) return nil } - -type KeycloakProvider struct{} - -type IdentityProviderData struct { - Keycloak KeycloakProvider `json:"keycloakProvider"` -} - -func (data IdentityProviderData) WriteToSchema(d *schema.ResourceData) error { - return nil -} - -func (data *IdentityProviderData) ReadFromSchema(d *schema.ResourceData) error { - return nil -} diff --git a/cyral/internal/resource_cyral_integration_idp_test.go b/cyral/internal/deprecated/resource_cyral_integration_idp_test.go similarity index 99% rename from cyral/internal/resource_cyral_integration_idp_test.go rename to cyral/internal/deprecated/resource_cyral_integration_idp_test.go index 45b30d39..6de0036c 100644 --- a/cyral/internal/resource_cyral_integration_idp_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_idp_test.go @@ -1,4 +1,4 @@ -package internal_test +package deprecated_test import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_logstash.go b/cyral/internal/deprecated/resource_cyral_integration_logstash.go similarity index 99% rename from cyral/internal/resource_cyral_integration_logstash.go rename to cyral/internal/deprecated/resource_cyral_integration_logstash.go index 4a571082..5331891d 100644 --- a/cyral/internal/resource_cyral_integration_logstash.go +++ b/cyral/internal/deprecated/resource_cyral_integration_logstash.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_logstash_test.go b/cyral/internal/deprecated/resource_cyral_integration_logstash_test.go similarity index 84% rename from cyral/internal/resource_cyral_integration_logstash_test.go rename to cyral/internal/deprecated/resource_cyral_integration_logstash_test.go index f06471af..041f09bd 100644 --- a/cyral/internal/resource_cyral_integration_logstash_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_logstash_test.go @@ -1,10 +1,10 @@ -package internal_test +package deprecated_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,7 +14,7 @@ const ( integrationLogstashResourceName = "integration-logstash" ) -var initialLogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{ +var initialLogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{ Endpoint: "logstash.local/", Name: utils.AccTestName(integrationLogstashResourceName, "logstash-test"), UseMutualAuthentication: false, @@ -22,7 +22,7 @@ var initialLogstashConfig internal.LogstashIntegration = internal.LogstashIntegr UseTLS: false, } -var updated1LogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{ +var updated1LogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{ Endpoint: "logstash-updated.local/", Name: utils.AccTestName(integrationLogstashResourceName, "logstash-update-test"), UseMutualAuthentication: true, @@ -30,7 +30,7 @@ var updated1LogstashConfig internal.LogstashIntegration = internal.LogstashInteg UseTLS: false, } -var updated2LogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{ +var updated2LogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{ Endpoint: "logstash-updated.local/", Name: utils.AccTestName(integrationLogstashResourceName, "logstash-update-test"), UseMutualAuthentication: false, @@ -38,7 +38,7 @@ var updated2LogstashConfig internal.LogstashIntegration = internal.LogstashInteg UseTLS: false, } -var updated3LogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{ +var updated3LogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{ Endpoint: "logstash-updated.local/", Name: utils.AccTestName(integrationLogstashResourceName, "logstash-update-test"), UseMutualAuthentication: false, @@ -80,7 +80,7 @@ func TestAccLogstashIntegrationResource(t *testing.T) { }) } -func setupLogstashTest(integrationData internal.LogstashIntegration) (string, resource.TestCheckFunc) { +func setupLogstashTest(integrationData deprecated.LogstashIntegration) (string, resource.TestCheckFunc) { configuration := formatLogstashIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -94,7 +94,7 @@ func setupLogstashTest(integrationData internal.LogstashIntegration) (string, re return configuration, testFunction } -func formatLogstashIntegrationDataIntoConfig(config internal.LogstashIntegration) string { +func formatLogstashIntegrationDataIntoConfig(config deprecated.LogstashIntegration) string { return fmt.Sprintf(` resource "cyral_integration_logstash" "logstash_integration" { name = "%s" diff --git a/cyral/internal/resource_cyral_integration_looker.go b/cyral/internal/deprecated/resource_cyral_integration_looker.go similarity index 99% rename from cyral/internal/resource_cyral_integration_looker.go rename to cyral/internal/deprecated/resource_cyral_integration_looker.go index e2fa74a1..db3c9c95 100644 --- a/cyral/internal/resource_cyral_integration_looker.go +++ b/cyral/internal/deprecated/resource_cyral_integration_looker.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_looker_test.go b/cyral/internal/deprecated/resource_cyral_integration_looker_test.go similarity index 78% rename from cyral/internal/resource_cyral_integration_looker_test.go rename to cyral/internal/deprecated/resource_cyral_integration_looker_test.go index 3a9d601c..a73ed9ef 100644 --- a/cyral/internal/resource_cyral_integration_looker_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_looker_test.go @@ -1,21 +1,21 @@ -package internal_test +package deprecated_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -var initialLookerConfig internal.LookerIntegration = internal.LookerIntegration{ +var initialLookerConfig deprecated.LookerIntegration = deprecated.LookerIntegration{ ClientId: "lookerClientID", ClientSecret: "lookerClientSecret", URL: "looker.local/", } -var updatedLookerConfig internal.LookerIntegration = internal.LookerIntegration{ +var updatedLookerConfig deprecated.LookerIntegration = deprecated.LookerIntegration{ ClientId: "lookerClientIDUpdated", ClientSecret: "lookerClientSecretUpdated", URL: "looker-updated.local/", @@ -45,7 +45,7 @@ func TestAccLookerIntegrationResource(t *testing.T) { }) } -func setupLookerTest(integrationData internal.LookerIntegration) (string, resource.TestCheckFunc) { +func setupLookerTest(integrationData deprecated.LookerIntegration) (string, resource.TestCheckFunc) { configuration := formatLookerIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -57,7 +57,7 @@ func setupLookerTest(integrationData internal.LookerIntegration) (string, resour return configuration, testFunction } -func formatLookerIntegrationDataIntoConfig(data internal.LookerIntegration) string { +func formatLookerIntegrationDataIntoConfig(data deprecated.LookerIntegration) string { return fmt.Sprintf(` resource "cyral_integration_looker" "looker_integration" { client_id = "%s" diff --git a/cyral/internal/resource_cyral_integration_splunk.go b/cyral/internal/deprecated/resource_cyral_integration_splunk.go similarity index 99% rename from cyral/internal/resource_cyral_integration_splunk.go rename to cyral/internal/deprecated/resource_cyral_integration_splunk.go index 6572749a..3f71b145 100644 --- a/cyral/internal/resource_cyral_integration_splunk.go +++ b/cyral/internal/deprecated/resource_cyral_integration_splunk.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_splunk_test.go b/cyral/internal/deprecated/resource_cyral_integration_splunk_test.go similarity index 84% rename from cyral/internal/resource_cyral_integration_splunk_test.go rename to cyral/internal/deprecated/resource_cyral_integration_splunk_test.go index 38edbe4a..58152b08 100644 --- a/cyral/internal/resource_cyral_integration_splunk_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_splunk_test.go @@ -1,10 +1,10 @@ -package internal_test +package deprecated_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,7 +14,7 @@ const ( integrationSplunkResourceName = "integration-splunk" ) -var initialSplunkConfig internal.SplunkIntegration = internal.SplunkIntegration{ +var initialSplunkConfig deprecated.SplunkIntegration = deprecated.SplunkIntegration{ Name: utils.AccTestName(integrationSplunkResourceName, "splunk-test"), AccessToken: "access-token", Port: 3333, @@ -23,7 +23,7 @@ var initialSplunkConfig internal.SplunkIntegration = internal.SplunkIntegration{ UseTLS: false, } -var updatedSplunkConfig internal.SplunkIntegration = internal.SplunkIntegration{ +var updatedSplunkConfig deprecated.SplunkIntegration = deprecated.SplunkIntegration{ Name: utils.AccTestName(integrationSplunkResourceName, "splunk-test-update"), AccessToken: "access-token-update", Port: 6666, @@ -56,7 +56,7 @@ func TestAccSplunkIntegrationResource(t *testing.T) { }) } -func setupSplunkTest(integrationData internal.SplunkIntegration) (string, resource.TestCheckFunc) { +func setupSplunkTest(integrationData deprecated.SplunkIntegration) (string, resource.TestCheckFunc) { configuration := formatSplunkIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -71,7 +71,7 @@ func setupSplunkTest(integrationData internal.SplunkIntegration) (string, resour return configuration, testFunction } -func formatSplunkIntegrationDataIntoConfig(data internal.SplunkIntegration) string { +func formatSplunkIntegrationDataIntoConfig(data deprecated.SplunkIntegration) string { return fmt.Sprintf(` resource "cyral_integration_splunk" "splunk_integration" { name = "%s" diff --git a/cyral/internal/resource_cyral_integration_sumo_logic.go b/cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go similarity index 99% rename from cyral/internal/resource_cyral_integration_sumo_logic.go rename to cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go index d07cc720..e177ea9b 100644 --- a/cyral/internal/resource_cyral_integration_sumo_logic.go +++ b/cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go @@ -1,4 +1,4 @@ -package internal +package deprecated import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_sumo_logic_test.go b/cyral/internal/deprecated/resource_cyral_integration_sumo_logic_test.go similarity index 78% rename from cyral/internal/resource_cyral_integration_sumo_logic_test.go rename to cyral/internal/deprecated/resource_cyral_integration_sumo_logic_test.go index 21a1d0e9..90e8fb0d 100644 --- a/cyral/internal/resource_cyral_integration_sumo_logic_test.go +++ b/cyral/internal/deprecated/resource_cyral_integration_sumo_logic_test.go @@ -1,10 +1,10 @@ -package internal_test +package deprecated_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,12 +14,12 @@ const ( integrationSumoLogicResourceName = "integration-sumo-logic" ) -var initialSumoLogicConfig internal.SumoLogicIntegration = internal.SumoLogicIntegration{ +var initialSumoLogicConfig deprecated.SumoLogicIntegration = deprecated.SumoLogicIntegration{ Name: utils.AccTestName(integrationSumoLogicResourceName, "sumo-logic"), Address: "https://sumologic.local/initial", } -var updatedSumoLogicConfig internal.SumoLogicIntegration = internal.SumoLogicIntegration{ +var updatedSumoLogicConfig deprecated.SumoLogicIntegration = deprecated.SumoLogicIntegration{ Name: utils.AccTestName(integrationSumoLogicResourceName, "sumo-logic-updated"), Address: "https://sumologic.local/updated", } @@ -48,7 +48,7 @@ func TestAccSumoLogicIntegrationResource(t *testing.T) { }) } -func setupSumoLogicTest(integrationData internal.SumoLogicIntegration) (string, resource.TestCheckFunc) { +func setupSumoLogicTest(integrationData deprecated.SumoLogicIntegration) (string, resource.TestCheckFunc) { configuration := formatSumoLogicIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -59,7 +59,7 @@ func setupSumoLogicTest(integrationData internal.SumoLogicIntegration) (string, return configuration, testFunction } -func formatSumoLogicIntegrationDataIntoConfig(data internal.SumoLogicIntegration) string { +func formatSumoLogicIntegrationDataIntoConfig(data deprecated.SumoLogicIntegration) string { return fmt.Sprintf(` resource "cyral_integration_sumo_logic" "sumo_logic_integration" { name = "%s" diff --git a/cyral/internal/resource_cyral_integration_aws_iam.go b/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go similarity index 99% rename from cyral/internal/resource_cyral_integration_aws_iam.go rename to cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go index 100bc5d5..33e9980f 100644 --- a/cyral/internal/resource_cyral_integration_aws_iam.go +++ b/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go @@ -1,4 +1,4 @@ -package internal +package awsiam import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_aws_iam_test.go b/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam_test.go similarity index 99% rename from cyral/internal/resource_cyral_integration_aws_iam_test.go rename to cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam_test.go index aee15ecf..c6f16d94 100644 --- a/cyral/internal/resource_cyral_integration_aws_iam_test.go +++ b/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam_test.go @@ -1,4 +1,4 @@ -package internal_test +package awsiam_test import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_mfa_duo.go b/cyral/internal/integration/confextension/mfaduo/resource_cyral_integration_mfa_duo.go similarity index 74% rename from cyral/internal/resource_cyral_integration_mfa_duo.go rename to cyral/internal/integration/confextension/mfaduo/resource_cyral_integration_mfa_duo.go index 5650f8b6..9d0fe918 100644 --- a/cyral/internal/resource_cyral_integration_mfa_duo.go +++ b/cyral/internal/integration/confextension/mfaduo/resource_cyral_integration_mfa_duo.go @@ -1,7 +1,8 @@ -package internal +package mfaduo import ( "github.com/cyralinc/terraform-provider-cyral/cyral/core" + ce "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/confextension" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) @@ -10,13 +11,13 @@ func ResourceIntegrationMFADuo() *schema.Resource { return &schema.Resource{ Description: "Manages [integration with Duo MFA](https://cyral.com/docs/mfa/duo).", CreateContext: core.CreateResource( - ConfExtensionIntegrationCreate(DuoMFATemplateType), - ConfExtensionIntegrationRead(DuoMFATemplateType)), - ReadContext: core.ReadResource(ConfExtensionIntegrationRead(DuoMFATemplateType)), + ce.ConfExtensionIntegrationCreate(ce.DuoMFATemplateType), + ce.ConfExtensionIntegrationRead(ce.DuoMFATemplateType)), + ReadContext: core.ReadResource(ce.ConfExtensionIntegrationRead(ce.DuoMFATemplateType)), UpdateContext: core.UpdateResource( - ConfExtensionIntegrationUpdate(DuoMFATemplateType), - ConfExtensionIntegrationRead(DuoMFATemplateType)), - DeleteContext: core.DeleteResource(ConfExtensionIntegrationDelete(DuoMFATemplateType)), + ce.ConfExtensionIntegrationUpdate(ce.DuoMFATemplateType), + ce.ConfExtensionIntegrationRead(ce.DuoMFATemplateType)), + DeleteContext: core.DeleteResource(ce.ConfExtensionIntegrationDelete(ce.DuoMFATemplateType)), Schema: map[string]*schema.Schema{ "id": { diff --git a/cyral/internal/resource_cyral_integration_mfa_duo_test.go b/cyral/internal/integration/confextension/mfaduo/resource_cyral_integration_mfa_duo_test.go similarity index 82% rename from cyral/internal/resource_cyral_integration_mfa_duo_test.go rename to cyral/internal/integration/confextension/mfaduo/resource_cyral_integration_mfa_duo_test.go index af4fa74d..950ada6a 100644 --- a/cyral/internal/resource_cyral_integration_mfa_duo_test.go +++ b/cyral/internal/integration/confextension/mfaduo/resource_cyral_integration_mfa_duo_test.go @@ -1,11 +1,11 @@ -package internal_test +package mfaduo_test import ( "encoding/json" "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/confextension" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -15,15 +15,15 @@ const ( integrationDuoMFAResourceName = "integration-duo-mfa" ) -func initialDuoMFAIntegrationConfig() *internal.IntegrationConfExtension { - integration := internal.NewIntegrationConfExtension(internal.DuoMFATemplateType) +func initialDuoMFAIntegrationConfig() *confextension.IntegrationConfExtension { + integration := confextension.NewIntegrationConfExtension(confextension.DuoMFATemplateType) integration.Name = utils.AccTestName(integrationDuoMFAResourceName, "integration") integration.Parameters = `{"integrationKey": "integration-key-1", "secretKey": "secret-key-1", "apiHostname": "api-hostname-1"}` return integration } -func updatedDuoMFAIntegrationConfig() *internal.IntegrationConfExtension { - integration := internal.NewIntegrationConfExtension(internal.DuoMFATemplateType) +func updatedDuoMFAIntegrationConfig() *confextension.IntegrationConfExtension { + integration := confextension.NewIntegrationConfExtension(confextension.DuoMFATemplateType) integration.Name = utils.AccTestName(integrationDuoMFAResourceName, "integration-updated") integration.Parameters = `{"integrationKey": "integration-key-2", "secretKey": "secret-key-2", "apiHostname": "api-hostname-2"}` return integration @@ -59,11 +59,11 @@ func TestAccDuoMFAIntegrationResource(t *testing.T) { func setupDuoMFAIntegrationTest( t *testing.T, - integrationData *internal.IntegrationConfExtension, + integrationData *confextension.IntegrationConfExtension, resourceName string, ) (string, resource.TestCheckFunc) { - var parameters internal.IntegrationConfExtensionParameters + var parameters confextension.IntegrationConfExtensionParameters err := json.Unmarshal([]byte(integrationData.Parameters), ¶meters) if err != nil { t.Fatalf("Error unmarshalling parameters: %v", err) diff --git a/cyral/internal/model_integration_confextension.go b/cyral/internal/integration/confextension/model_integration_confextension.go similarity index 99% rename from cyral/internal/model_integration_confextension.go rename to cyral/internal/integration/confextension/model_integration_confextension.go index fe96a7d5..9c0be0e9 100644 --- a/cyral/internal/model_integration_confextension.go +++ b/cyral/internal/integration/confextension/model_integration_confextension.go @@ -1,4 +1,4 @@ -package internal +package confextension import ( "encoding/json" diff --git a/cyral/internal/resource_cyral_integration_pager_duty.go b/cyral/internal/integration/confextension/pagerduty/resource_cyral_integration_pager_duty.go similarity index 65% rename from cyral/internal/resource_cyral_integration_pager_duty.go rename to cyral/internal/integration/confextension/pagerduty/resource_cyral_integration_pager_duty.go index ac695b62..ce4f48ef 100644 --- a/cyral/internal/resource_cyral_integration_pager_duty.go +++ b/cyral/internal/integration/confextension/pagerduty/resource_cyral_integration_pager_duty.go @@ -1,7 +1,8 @@ -package internal +package pagerduty import ( "github.com/cyralinc/terraform-provider-cyral/cyral/core" + ce "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/confextension" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -9,13 +10,13 @@ func ResourceIntegrationPagerDuty() *schema.Resource { return &schema.Resource{ Description: "Manages [integration with PagerDuty](https://cyral.com/docs/integrations/incident-response/pagerduty/#in-cyral).", CreateContext: core.CreateResource( - ConfExtensionIntegrationCreate(PagerDutyTemplateType), - ConfExtensionIntegrationRead(PagerDutyTemplateType)), - ReadContext: core.ReadResource(ConfExtensionIntegrationRead(PagerDutyTemplateType)), + ce.ConfExtensionIntegrationCreate(ce.PagerDutyTemplateType), + ce.ConfExtensionIntegrationRead(ce.PagerDutyTemplateType)), + ReadContext: core.ReadResource(ce.ConfExtensionIntegrationRead(ce.PagerDutyTemplateType)), UpdateContext: core.UpdateResource( - ConfExtensionIntegrationUpdate(PagerDutyTemplateType), - ConfExtensionIntegrationRead(PagerDutyTemplateType)), - DeleteContext: core.DeleteResource(ConfExtensionIntegrationDelete(PagerDutyTemplateType)), + ce.ConfExtensionIntegrationUpdate(ce.PagerDutyTemplateType), + ce.ConfExtensionIntegrationRead(ce.PagerDutyTemplateType)), + DeleteContext: core.DeleteResource(ce.ConfExtensionIntegrationDelete(ce.PagerDutyTemplateType)), Schema: map[string]*schema.Schema{ "id": { diff --git a/cyral/internal/resource_cyral_integration_pager_duty_test.go b/cyral/internal/integration/confextension/pagerduty/resource_cyral_integration_pager_duty_test.go similarity index 78% rename from cyral/internal/resource_cyral_integration_pager_duty_test.go rename to cyral/internal/integration/confextension/pagerduty/resource_cyral_integration_pager_duty_test.go index f6d7e5a3..6e2aa089 100644 --- a/cyral/internal/resource_cyral_integration_pager_duty_test.go +++ b/cyral/internal/integration/confextension/pagerduty/resource_cyral_integration_pager_duty_test.go @@ -1,10 +1,10 @@ -package internal_test +package pagerduty_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + ce "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/confextension" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,15 +14,15 @@ const ( integrationPagerDutyResourceName = "integration-pager-duty" ) -func initialPagerDutyIntegrationConfig() *internal.IntegrationConfExtension { - integration := internal.NewIntegrationConfExtension(internal.PagerDutyTemplateType) +func initialPagerDutyIntegrationConfig() *ce.IntegrationConfExtension { + integration := ce.NewIntegrationConfExtension(ce.PagerDutyTemplateType) integration.Name = utils.AccTestName(integrationPagerDutyResourceName, "pager-duty") integration.Parameters = "unitTest-parameters" return integration } -func updatedPagerDutyIntegrationConfig() *internal.IntegrationConfExtension { - integration := internal.NewIntegrationConfExtension(internal.PagerDutyTemplateType) +func updatedPagerDutyIntegrationConfig() *ce.IntegrationConfExtension { + integration := ce.NewIntegrationConfExtension(ce.PagerDutyTemplateType) integration.Name = utils.AccTestName(integrationPagerDutyResourceName, "pager-duty-updated") integration.Parameters = "unitTest-parameters-updated" return integration @@ -52,7 +52,7 @@ func TestAccPagerDutyIntegrationResource(t *testing.T) { }) } -func setupPagerDutyIntegrationTest(integrationData *internal.IntegrationConfExtension) (string, resource.TestCheckFunc) { +func setupPagerDutyIntegrationTest(integrationData *ce.IntegrationConfExtension) (string, resource.TestCheckFunc) { configuration := formatPagerDutyIntegrationIntoConfig( integrationData.Name, integrationData.Parameters) diff --git a/cyral/internal/model_cyral_integration_hcvault.go b/cyral/internal/integration/hcvault/model_cyral_integration_hcvault.go similarity index 96% rename from cyral/internal/model_cyral_integration_hcvault.go rename to cyral/internal/integration/hcvault/model_cyral_integration_hcvault.go index 4ce4ffd1..bf31a06b 100644 --- a/cyral/internal/model_cyral_integration_hcvault.go +++ b/cyral/internal/integration/hcvault/model_cyral_integration_hcvault.go @@ -1,4 +1,4 @@ -package internal +package hcvault // HCVaultIntegration defines the necessary data for Hashicorp Vault integration type HCVaultIntegration struct { diff --git a/cyral/internal/resource_cyral_integration_hcvault.go b/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go similarity index 99% rename from cyral/internal/resource_cyral_integration_hcvault.go rename to cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go index 570b934a..980c7b5d 100644 --- a/cyral/internal/resource_cyral_integration_hcvault.go +++ b/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go @@ -1,4 +1,4 @@ -package internal +package hcvault import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_hcvault_test.go b/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault_test.go similarity index 83% rename from cyral/internal/resource_cyral_integration_hcvault_test.go rename to cyral/internal/integration/hcvault/resource_cyral_integration_hcvault_test.go index d83987a9..77a68874 100644 --- a/cyral/internal/resource_cyral_integration_hcvault_test.go +++ b/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault_test.go @@ -1,10 +1,10 @@ -package internal_test +package hcvault_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/hcvault" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -15,7 +15,7 @@ const ( integrationHCVaultResourceName = "integration-hcvault" ) -var initialHCVaultIntegrationConfig internal.HCVaultIntegration = internal.HCVaultIntegration{ +var initialHCVaultIntegrationConfig hcvault.HCVaultIntegration = hcvault.HCVaultIntegration{ AuthMethod: "unitTest-auth_method", ID: "unitTest-id", AuthType: "unitTest-auth_type", @@ -23,7 +23,7 @@ var initialHCVaultIntegrationConfig internal.HCVaultIntegration = internal.HCVau Server: "unitTest-server", } -var updatedHCVaultIntegrationConfig internal.HCVaultIntegration = internal.HCVaultIntegration{ +var updatedHCVaultIntegrationConfig hcvault.HCVaultIntegration = hcvault.HCVaultIntegration{ AuthMethod: "unitTest-auth_method-updated", ID: "unitTest-id-updated", AuthType: "unitTest-auth_type-updated", @@ -59,7 +59,7 @@ func TestAccHCVaultIntegrationResource(t *testing.T) { }) } -func setupHCVaultIntegrationTest(integrationData internal.HCVaultIntegration) (string, resource.TestCheckFunc) { +func setupHCVaultIntegrationTest(integrationData hcvault.HCVaultIntegration) (string, resource.TestCheckFunc) { configuration := formatHCVaultIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -73,7 +73,7 @@ func setupHCVaultIntegrationTest(integrationData internal.HCVaultIntegration) (s return configuration, testFunction } -func formatHCVaultIntegrationDataIntoConfig(data internal.HCVaultIntegration) string { +func formatHCVaultIntegrationDataIntoConfig(data hcvault.HCVaultIntegration) string { return fmt.Sprintf(` resource "cyral_integration_hc_vault" "hc_vault_integration" { auth_method = "%s" diff --git a/cyral/internal/data_source_cyral_integration_idp_saml.go b/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml.go similarity index 99% rename from cyral/internal/data_source_cyral_integration_idp_saml.go rename to cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml.go index 33f98f19..b5e55227 100644 --- a/cyral/internal/data_source_cyral_integration_idp_saml.go +++ b/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml.go @@ -1,4 +1,4 @@ -package internal +package idpsaml import ( "fmt" diff --git a/cyral/internal/data_source_cyral_integration_idp_saml_test.go b/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go similarity index 87% rename from cyral/internal/data_source_cyral_integration_idp_saml_test.go rename to cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go index 1100aa81..b77b352b 100644 --- a/cyral/internal/data_source_cyral_integration_idp_saml_test.go +++ b/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go @@ -1,11 +1,11 @@ -package internal_test +package idpsaml_test import ( "fmt" "regexp" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/idpsaml" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -17,24 +17,24 @@ const ( integrationIdPSAMLDataSourceName = "data-integration-idp-saml" ) -func integrationIdPSAMLDataSourceTestIdps() []internal.GenericSAMLIntegration { - return []internal.GenericSAMLIntegration{ +func integrationIdPSAMLDataSourceTestIdps() []idpsaml.GenericSAMLIntegration { + return []idpsaml.GenericSAMLIntegration{ { ID: "id-1", DisplayName: utils.AccTestName( integrationIdPSAMLDataSourceName, "integration-1"), IdpType: "idp-type-1", Disabled: false, - IdpDescriptor: &internal.GenericSAMLIdpDescriptor{ + IdpDescriptor: &idpsaml.GenericSAMLIdpDescriptor{ SingleSignOnServiceURL: "sso-url-1", SigningCertificate: "signing-certificate-1", DisableForceAuthentication: false, SingleLogoutServiceURL: "slo-url-1", }, - SPMetadata: &internal.GenericSAMLSPMetadata{ + SPMetadata: &idpsaml.GenericSAMLSPMetadata{ XMLDocument: "xml-document-1", }, - Attributes: internal.NewRequiredUserAttributes( + Attributes: idpsaml.NewRequiredUserAttributes( "first-name-1", "last-name-1", "email-1", @@ -47,16 +47,16 @@ func integrationIdPSAMLDataSourceTestIdps() []internal.GenericSAMLIntegration { integrationIdPSAMLDataSourceName, "integration-2"), IdpType: "idp-type-2", Disabled: true, - IdpDescriptor: &internal.GenericSAMLIdpDescriptor{ + IdpDescriptor: &idpsaml.GenericSAMLIdpDescriptor{ SingleSignOnServiceURL: "sso-url-2", SigningCertificate: "signing-certificate-2", DisableForceAuthentication: true, SingleLogoutServiceURL: "slo-url-2", }, - SPMetadata: &internal.GenericSAMLSPMetadata{ + SPMetadata: &idpsaml.GenericSAMLSPMetadata{ XMLDocument: "xml-document-2", }, - Attributes: internal.NewRequiredUserAttributes( + Attributes: idpsaml.NewRequiredUserAttributes( "first-name-2", "last-name-2", "email-2", @@ -206,16 +206,16 @@ func testIntegrationIdPSAMLDataSourceChecks(t *testing.T, resName, nameFilter, t "idp_list.0.attributes.#", "1", ), resource.TestCheckResourceAttr(dataSourceFullName, - "idp_list.0.attributes.0.first_name", internal.DefaultUserAttributeFirstName, + "idp_list.0.attributes.0.first_name", idpsaml.DefaultUserAttributeFirstName, ), resource.TestCheckResourceAttr(dataSourceFullName, - "idp_list.0.attributes.0.last_name", internal.DefaultUserAttributeLastName, + "idp_list.0.attributes.0.last_name", idpsaml.DefaultUserAttributeLastName, ), resource.TestCheckResourceAttr(dataSourceFullName, - "idp_list.0.attributes.0.email", internal.DefaultUserAttributeEmail, + "idp_list.0.attributes.0.email", idpsaml.DefaultUserAttributeEmail, ), resource.TestCheckResourceAttr(dataSourceFullName, - "idp_list.0.attributes.0.groups", internal.DefaultUserAttributeGroups, + "idp_list.0.attributes.0.groups", idpsaml.DefaultUserAttributeGroups, ), } @@ -230,8 +230,8 @@ func testIntegrationIdPSAMLDataSourceChecks(t *testing.T, resName, nameFilter, t return resource.ComposeTestCheckFunc(testFunctions...) } -func filterSAMLIdps(idps []internal.GenericSAMLIntegration, nameFilter, typeFilter string) []internal.GenericSAMLIntegration { - var filteredIdps []internal.GenericSAMLIntegration +func filterSAMLIdps(idps []idpsaml.GenericSAMLIntegration, nameFilter, typeFilter string) []idpsaml.GenericSAMLIntegration { + var filteredIdps []idpsaml.GenericSAMLIntegration for _, idp := range idps { if (nameFilter == "" || idp.DisplayName == nameFilter) && (typeFilter == "" || idp.IdpType == typeFilter) { diff --git a/cyral/internal/model_integration_idp_generic_saml.go b/cyral/internal/integration/idpsaml/model_integration_idp_generic_saml.go similarity index 94% rename from cyral/internal/model_integration_idp_generic_saml.go rename to cyral/internal/integration/idpsaml/model_integration_idp_generic_saml.go index b6fa29b3..0695135b 100644 --- a/cyral/internal/model_integration_idp_generic_saml.go +++ b/cyral/internal/integration/idpsaml/model_integration_idp_generic_saml.go @@ -1,4 +1,4 @@ -package internal +package idpsaml import ( "fmt" @@ -163,3 +163,17 @@ type GenericSAMLIdpMetadata struct { URL string `json:"url,omitempty"` XML string `json:"xml,omitempty"` } + +type KeycloakProvider struct{} + +type IdentityProviderData struct { + Keycloak KeycloakProvider `json:"keycloakProvider"` +} + +func (data IdentityProviderData) WriteToSchema(d *schema.ResourceData) error { + return nil +} + +func (data *IdentityProviderData) ReadFromSchema(d *schema.ResourceData) error { + return nil +} diff --git a/cyral/internal/resource_cyral_integration_idp_saml.go b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml.go similarity index 99% rename from cyral/internal/resource_cyral_integration_idp_saml.go rename to cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml.go index 52835173..eafe58c4 100644 --- a/cyral/internal/resource_cyral_integration_idp_saml.go +++ b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml.go @@ -1,4 +1,4 @@ -package internal +package idpsaml import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_idp_saml_draft.go b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_draft.go similarity index 99% rename from cyral/internal/resource_cyral_integration_idp_saml_draft.go rename to cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_draft.go index 9fb5ab53..afcb19ff 100644 --- a/cyral/internal/resource_cyral_integration_idp_saml_draft.go +++ b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_draft.go @@ -1,4 +1,4 @@ -package internal +package idpsaml import ( "encoding/json" diff --git a/cyral/internal/resource_cyral_integration_idp_saml_draft_test.go b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_draft_test.go similarity index 88% rename from cyral/internal/resource_cyral_integration_idp_saml_draft_test.go rename to cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_draft_test.go index 8e5be006..002a0d45 100644 --- a/cyral/internal/resource_cyral_integration_idp_saml_draft_test.go +++ b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_draft_test.go @@ -1,4 +1,4 @@ -package internal_test +package idpsaml_test import ( "fmt" @@ -6,7 +6,7 @@ import ( "strconv" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/idpsaml" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -18,13 +18,13 @@ const ( integrationIdPSAMLDraftResourceName = "integration-idp-saml-draft" ) -func genericSAMLDraftConfigInitial() *internal.GenericSAMLDraft { - return &internal.GenericSAMLDraft{ +func genericSAMLDraftConfigInitial() *idpsaml.GenericSAMLDraft { + return &idpsaml.GenericSAMLDraft{ DisplayName: utils.AccTestName( integrationIdPSAMLDraftResourceName, "integration-1"), DisableIdPInitiatedLogin: false, IdpType: "some-idp-type-1", - Attributes: internal.NewRequiredUserAttributes( + Attributes: idpsaml.NewRequiredUserAttributes( "first-name-1", "last-name-1", "email-1", @@ -33,13 +33,13 @@ func genericSAMLDraftConfigInitial() *internal.GenericSAMLDraft { } } -func genericSAMLDraftConfigUpdated() *internal.GenericSAMLDraft { - return &internal.GenericSAMLDraft{ +func genericSAMLDraftConfigUpdated() *idpsaml.GenericSAMLDraft { + return &idpsaml.GenericSAMLDraft{ DisplayName: utils.AccTestName( integrationIdPSAMLDraftResourceName, "integration-2"), DisableIdPInitiatedLogin: true, IdpType: "some-idp-type-2", - Attributes: internal.NewRequiredUserAttributes( + Attributes: idpsaml.NewRequiredUserAttributes( "first-name-2", "last-name-2", "email-2", @@ -48,8 +48,8 @@ func genericSAMLDraftConfigUpdated() *internal.GenericSAMLDraft { } } -func genericSAMLDraftConfigNoAttributes() *internal.GenericSAMLDraft { - return &internal.GenericSAMLDraft{ +func genericSAMLDraftConfigNoAttributes() *idpsaml.GenericSAMLDraft { + return &idpsaml.GenericSAMLDraft{ DisplayName: utils.AccTestName( integrationIdPSAMLDraftResourceName, "integration-2"), DisableIdPInitiatedLogin: true, @@ -94,7 +94,7 @@ func TestAccIntegrationIdPSAMLDraftResource(t *testing.T) { }) } -func setupIntegrationIdPSAMLDraftTest(t *testing.T, draft *internal.GenericSAMLDraft, resName string) ( +func setupIntegrationIdPSAMLDraftTest(t *testing.T, draft *idpsaml.GenericSAMLDraft, resName string) ( string, resource.TestCheckFunc, ) { @@ -147,7 +147,7 @@ func setupIntegrationIdPSAMLDraftTest(t *testing.T, draft *internal.GenericSAMLD return config, resource.ComposeTestCheckFunc(checkFuncs...) } -func formatGenericSAMLDraftIntoConfig(draft *internal.GenericSAMLDraft, resName string) string { +func formatGenericSAMLDraftIntoConfig(draft *idpsaml.GenericSAMLDraft, resName string) string { var attributesStr string if draft.Attributes != nil { attributesStr += fmt.Sprintf(` diff --git a/cyral/internal/resource_cyral_integration_idp_saml_test.go b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_test.go similarity index 99% rename from cyral/internal/resource_cyral_integration_idp_saml_test.go rename to cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_test.go index 63677761..c47bfc54 100644 --- a/cyral/internal/resource_cyral_integration_idp_saml_test.go +++ b/cyral/internal/integration/idpsaml/resource_cyral_integration_idp_saml_test.go @@ -1,4 +1,4 @@ -package internal_test +package idpsaml_test import ( "encoding/base64" diff --git a/cyral/internal/data_source_cyral_integration_logging.go b/cyral/internal/integration/logging/data_source_cyral_integration_logging.go similarity index 99% rename from cyral/internal/data_source_cyral_integration_logging.go rename to cyral/internal/integration/logging/data_source_cyral_integration_logging.go index 77025907..e6246329 100644 --- a/cyral/internal/data_source_cyral_integration_logging.go +++ b/cyral/internal/integration/logging/data_source_cyral_integration_logging.go @@ -1,4 +1,4 @@ -package internal +package logging import ( "fmt" diff --git a/cyral/internal/data_source_cyral_integration_logging_test.go b/cyral/internal/integration/logging/data_source_cyral_integration_logging_test.go similarity index 88% rename from cyral/internal/data_source_cyral_integration_logging_test.go rename to cyral/internal/integration/logging/data_source_cyral_integration_logging_test.go index 2f22e231..1d9eb947 100644 --- a/cyral/internal/data_source_cyral_integration_logging_test.go +++ b/cyral/internal/integration/logging/data_source_cyral_integration_logging_test.go @@ -1,10 +1,10 @@ -package internal_test +package logging_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/logging" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -40,11 +40,11 @@ func testIntegrationLoggingDataSourceConfigDependencies(resName string) string { resName1 := resName + "_1" resName2 := resName + "_2" - resource1, _ := formatLogsIntegrationDataIntoConfig(internal.LoggingIntegration{ + resource1, _ := formatLogsIntegrationDataIntoConfig(logging.LoggingIntegration{ Name: resName1, ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - CloudWatch: &internal.CloudWatchConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + CloudWatch: &logging.CloudWatchConfig{ Region: "us-east-2", Group: "group2", Stream: "abcd", @@ -52,11 +52,11 @@ func testIntegrationLoggingDataSourceConfigDependencies(resName string) string { }, }, resName1) - resource2, _ := formatLogsIntegrationDataIntoConfig(internal.LoggingIntegration{ + resource2, _ := formatLogsIntegrationDataIntoConfig(logging.LoggingIntegration{ Name: resName2, ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Datadog: &internal.DataDogConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Datadog: &logging.DataDogConfig{ ApiKey: "API_KEY_A", }, }, diff --git a/cyral/internal/model_integration_logging.go b/cyral/internal/integration/logging/model_integration_logging.go similarity index 99% rename from cyral/internal/model_integration_logging.go rename to cyral/internal/integration/logging/model_integration_logging.go index 56bf2b58..4ac8f340 100644 --- a/cyral/internal/model_integration_logging.go +++ b/cyral/internal/integration/logging/model_integration_logging.go @@ -1,4 +1,4 @@ -package internal +package logging import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/cyral/internal/resource_cyral_integration_logging.go b/cyral/internal/integration/logging/resource_cyral_integration_logging.go similarity index 99% rename from cyral/internal/resource_cyral_integration_logging.go rename to cyral/internal/integration/logging/resource_cyral_integration_logging.go index ddb173a3..93532c30 100644 --- a/cyral/internal/resource_cyral_integration_logging.go +++ b/cyral/internal/integration/logging/resource_cyral_integration_logging.go @@ -1,4 +1,4 @@ -package internal +package logging import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_logging_test.go b/cyral/internal/integration/logging/resource_cyral_integration_logging_test.go similarity index 81% rename from cyral/internal/resource_cyral_integration_logging_test.go rename to cyral/internal/integration/logging/resource_cyral_integration_logging_test.go index 068ee38f..a5ee5486 100644 --- a/cyral/internal/resource_cyral_integration_logging_test.go +++ b/cyral/internal/integration/logging/resource_cyral_integration_logging_test.go @@ -1,4 +1,4 @@ -package internal_test +package logging_test import ( "fmt" @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/logging" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -24,11 +24,11 @@ var ProviderFactories = map[string]func() (*schema.Provider, error){ }, } -var initialLogsConfigCloudWatch internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigCloudWatch logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "LogsCloudWatchTest"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - CloudWatch: &internal.CloudWatchConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + CloudWatch: &logging.CloudWatchConfig{ Region: "us-east-2", Group: "group2", Stream: "abcd", @@ -36,23 +36,23 @@ var initialLogsConfigCloudWatch internal.LoggingIntegration = internal.LoggingIn }, } -var initialLogsConfigDataDog internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigDataDog logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Datadog"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Datadog: &internal.DataDogConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Datadog: &logging.DataDogConfig{ ApiKey: "TESTING_API", }, }, } -var initialLogsConfigElk internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigElk logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "LogsElkComplete"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Elk: &internal.ElkConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Elk: &logging.ElkConfig{ EsURL: "http://es.com", KibanaURL: "http://kibana.com", - EsCredentials: &internal.EsCredentials{ + EsCredentials: &logging.EsCredentials{ Username: "gabriel", Password: "123", }, @@ -60,21 +60,21 @@ var initialLogsConfigElk internal.LoggingIntegration = internal.LoggingIntegrati }, } -var initialLogsConfigElkEmptyEsCredentials internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigElkEmptyEsCredentials logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "LogsElkEmptyEsCredentials"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Elk: &internal.ElkConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Elk: &logging.ElkConfig{ EsURL: "http://es.com", }, }, } -var initialLogsConfigSplunk internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigSplunk logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Splunk"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Splunk: &internal.SplunkConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Splunk: &logging.SplunkConfig{ Hostname: "www.splunk.com", HecPort: "9529", AccessToken: "ACCESS", @@ -84,21 +84,21 @@ var initialLogsConfigSplunk internal.LoggingIntegration = internal.LoggingIntegr }, } -var initialLogsConfigSumologic internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigSumologic logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Sumologic"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - SumoLogic: &internal.SumoLogicConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + SumoLogic: &logging.SumoLogicConfig{ Address: "https://www.hostname.com.br/path", }, }, } -var initialLogsConfigFluentbit internal.LoggingIntegration = internal.LoggingIntegration{ +var initialLogsConfigFluentbit logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Fluentbit"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - FluentBit: &internal.FluentBitConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + FluentBit: &logging.FluentBitConfig{ Config: `[OUTPUT] Name stdout Match *`, @@ -106,11 +106,11 @@ Match *`, }, } -var updatedLogsConfigCloudWatch internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigCloudWatch logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "LogsCloudWatchTest"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - CloudWatch: &internal.CloudWatchConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + CloudWatch: &logging.CloudWatchConfig{ Region: "us-east-1", Group: "group1", Stream: "abcd", @@ -118,24 +118,24 @@ var updatedLogsConfigCloudWatch internal.LoggingIntegration = internal.LoggingIn }, } -var updatedLogsConfigDataDog internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigDataDog logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Datadog"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Datadog: &internal.DataDogConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Datadog: &logging.DataDogConfig{ ApiKey: "TESTING_API", }, }, } -var updatedLogsConfigElk internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigElk logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "LogsElkComplete"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Elk: &internal.ElkConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Elk: &logging.ElkConfig{ EsURL: "http://esupdate.com", KibanaURL: "http://kibanaupdate.com", - EsCredentials: &internal.EsCredentials{ + EsCredentials: &logging.EsCredentials{ Username: "gabriel-update", Password: "1234", }, @@ -143,21 +143,21 @@ var updatedLogsConfigElk internal.LoggingIntegration = internal.LoggingIntegrati }, } -var updatedLogsConfigElkEmptyEsCredentials internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigElkEmptyEsCredentials logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "LogsElkEmptyEsCredentials"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Elk: &internal.ElkConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Elk: &logging.ElkConfig{ EsURL: "http://esupdate1.com", }, }, } -var updatedLogsConfigSplunk internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigSplunk logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Splunk"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - Splunk: &internal.SplunkConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + Splunk: &logging.SplunkConfig{ Hostname: "www.splunk2.com", HecPort: "8090", AccessToken: "ACCESS", @@ -167,21 +167,21 @@ var updatedLogsConfigSplunk internal.LoggingIntegration = internal.LoggingIntegr }, } -var updatedLogsConfigSumologic internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigSumologic logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Sumologic"), ReceiveAuditLogs: true, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - SumoLogic: &internal.SumoLogicConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + SumoLogic: &logging.SumoLogicConfig{ Address: "https://www.hostnameupdated.com.br/path", }, }, } -var updatedLogsConfigFluentbit internal.LoggingIntegration = internal.LoggingIntegration{ +var updatedLogsConfigFluentbit logging.LoggingIntegration = logging.LoggingIntegration{ Name: utils.AccTestName(integrationLogsResourceName, "Fluentbit"), ReceiveAuditLogs: false, - LoggingIntegrationConfig: internal.LoggingIntegrationConfig{ - FluentBit: &internal.FluentBitConfig{ + LoggingIntegrationConfig: logging.LoggingIntegrationConfig{ + FluentBit: &logging.FluentBitConfig{ Config: `[OUTPUT] Name stdout Match *`, @@ -218,7 +218,7 @@ func TestAccLogsIntegrationResourceDataDog(t *testing.T) { testUpdateConfig, testUpdateFunc := setupLogsTest(updatedLogsConfigDataDog) resource.ParallelTest(t, resource.TestCase{ - ProviderFactories: provider.ProviderFactories(), + ProviderFactories: provider.ProviderFactories, Steps: []resource.TestStep{ { Config: testConfig, @@ -357,7 +357,7 @@ func TestAccLogsIntegrationResourceFluentbit(t *testing.T) { }) } -func setupLogsTest(integrationData internal.LoggingIntegration) (string, resource.TestCheckFunc) { +func setupLogsTest(integrationData logging.LoggingIntegration) (string, resource.TestCheckFunc) { configuration, err := formatLogsIntegrationDataIntoConfig(integrationData, "logs_integration_test") if err != nil { log.Fatalf("%v", err) @@ -442,7 +442,7 @@ func setupLogsTest(integrationData internal.LoggingIntegration) (string, resourc // this function formats LoggingIntegration into string. // this is also used in datasource tests -func formatLogsIntegrationDataIntoConfig(data internal.LoggingIntegration, resName string) (string, error) { +func formatLogsIntegrationDataIntoConfig(data logging.LoggingIntegration, resName string) (string, error) { var config string switch { case data.CloudWatch != nil: diff --git a/cyral/internal/resource_cyral_integration_slack_alerts.go b/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go similarity index 99% rename from cyral/internal/resource_cyral_integration_slack_alerts.go rename to cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go index dad26006..217c4000 100644 --- a/cyral/internal/resource_cyral_integration_slack_alerts.go +++ b/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go @@ -1,4 +1,4 @@ -package internal +package slack import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_slack_alerts_test.go b/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts_test.go similarity index 77% rename from cyral/internal/resource_cyral_integration_slack_alerts_test.go rename to cyral/internal/integration/slack/resource_cyral_integration_slack_alerts_test.go index 0a1396e4..30a3d332 100644 --- a/cyral/internal/resource_cyral_integration_slack_alerts_test.go +++ b/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts_test.go @@ -1,10 +1,10 @@ -package internal_test +package slack_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/slack" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,12 +14,12 @@ const ( integrationSlackAlertsResourceName = "integration-slack-alerts" ) -var initialSlackAlertsConfig internal.SlackAlertsIntegration = internal.SlackAlertsIntegration{ +var initialSlackAlertsConfig slack.SlackAlertsIntegration = slack.SlackAlertsIntegration{ Name: utils.AccTestName(integrationSlackAlertsResourceName, "slack-alerts"), URL: "https://slack.local", } -var updatedSlackAlertsConfig internal.SlackAlertsIntegration = internal.SlackAlertsIntegration{ +var updatedSlackAlertsConfig slack.SlackAlertsIntegration = slack.SlackAlertsIntegration{ Name: utils.AccTestName(integrationSlackAlertsResourceName, "slack-alerts-updated"), URL: "https://slack-updated.local", } @@ -48,7 +48,7 @@ func TestAccSlackAlertsIntegrationResource(t *testing.T) { }) } -func setupSlackAlertTest(integrationData internal.SlackAlertsIntegration) (string, resource.TestCheckFunc) { +func setupSlackAlertTest(integrationData slack.SlackAlertsIntegration) (string, resource.TestCheckFunc) { configuration := formatSlackAlertsIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -61,7 +61,7 @@ func setupSlackAlertTest(integrationData internal.SlackAlertsIntegration) (strin return configuration, testFunction } -func formatSlackAlertsIntegrationDataIntoConfig(data internal.SlackAlertsIntegration) string { +func formatSlackAlertsIntegrationDataIntoConfig(data slack.SlackAlertsIntegration) string { return fmt.Sprintf(` resource "cyral_integration_slack_alerts" "test_slack_alerts" { name = "%s" diff --git a/cyral/internal/resource_cyral_integration_teams.go b/cyral/internal/integration/teams/resource_cyral_integration_teams.go similarity index 99% rename from cyral/internal/resource_cyral_integration_teams.go rename to cyral/internal/integration/teams/resource_cyral_integration_teams.go index 8d11d560..1733e186 100644 --- a/cyral/internal/resource_cyral_integration_teams.go +++ b/cyral/internal/integration/teams/resource_cyral_integration_teams.go @@ -1,4 +1,4 @@ -package internal +package teams import ( "fmt" diff --git a/cyral/internal/resource_cyral_integration_teams_test.go b/cyral/internal/integration/teams/resource_cyral_integration_teams_test.go similarity index 79% rename from cyral/internal/resource_cyral_integration_teams_test.go rename to cyral/internal/integration/teams/resource_cyral_integration_teams_test.go index 8a5c3903..e53b575f 100644 --- a/cyral/internal/resource_cyral_integration_teams_test.go +++ b/cyral/internal/integration/teams/resource_cyral_integration_teams_test.go @@ -1,10 +1,10 @@ -package internal_test +package teams_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/teams" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -14,12 +14,12 @@ const ( integrationTeamsResourceName = "integrations-teams" ) -var initialTeamsConfig internal.MsTeamsIntegration = internal.MsTeamsIntegration{ +var initialTeamsConfig teams.MsTeamsIntegration = teams.MsTeamsIntegration{ Name: utils.AccTestName(integrationTeamsResourceName, "msteams-alerts"), URL: "https://msteams.local", } -var updatedTeamsConfig internal.MsTeamsIntegration = internal.MsTeamsIntegration{ +var updatedTeamsConfig teams.MsTeamsIntegration = teams.MsTeamsIntegration{ Name: utils.AccTestName(integrationTeamsResourceName, "msteams-alerts"), URL: "https://msteams-updated.local", } @@ -48,7 +48,7 @@ func TestAccMsTeamsIntegrationResource(t *testing.T) { }) } -func setupTeamsTest(integrationData internal.MsTeamsIntegration) (string, resource.TestCheckFunc) { +func setupTeamsTest(integrationData teams.MsTeamsIntegration) (string, resource.TestCheckFunc) { configuration := formatMsTeamsIntegrationDataIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -61,7 +61,7 @@ func setupTeamsTest(integrationData internal.MsTeamsIntegration) (string, resour return configuration, testFunction } -func formatMsTeamsIntegrationDataIntoConfig(data internal.MsTeamsIntegration) string { +func formatMsTeamsIntegrationDataIntoConfig(data teams.MsTeamsIntegration) string { return fmt.Sprintf(` resource "cyral_integration_microsoft_teams" "test_microsoft_teams" { name = "%s" diff --git a/cyral/internal/data_source_cyral_permission.go b/cyral/internal/permission/data_source_cyral_permission.go similarity index 99% rename from cyral/internal/data_source_cyral_permission.go rename to cyral/internal/permission/data_source_cyral_permission.go index 2b74bb45..60db95e0 100644 --- a/cyral/internal/data_source_cyral_permission.go +++ b/cyral/internal/permission/data_source_cyral_permission.go @@ -1,4 +1,4 @@ -package internal +package permission import ( "fmt" diff --git a/cyral/internal/data_source_cyral_permission_test.go b/cyral/internal/permission/data_source_cyral_permission_test.go similarity index 80% rename from cyral/internal/data_source_cyral_permission_test.go rename to cyral/internal/permission/data_source_cyral_permission_test.go index 87c570f3..3690a029 100644 --- a/cyral/internal/data_source_cyral_permission_test.go +++ b/cyral/internal/permission/data_source_cyral_permission_test.go @@ -1,10 +1,10 @@ -package internal_test +package permission_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/permission" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -33,26 +33,26 @@ func accTestStepPermissionDataSource_RetrieveAllPermissions(dataSourceName strin } `, dataSourceName) var checks []resource.TestCheckFunc - for index, expectedPermissionName := range internal.AllPermissionNames { + for index, expectedPermissionName := range permission.AllPermissionNames { checks = append(checks, []resource.TestCheckFunc{ resource.TestCheckResourceAttrSet( dataSourceFullName, fmt.Sprintf( "%s.%d.%s", - internal.PermissionDataSourcePermissionListKey, + permission.PermissionDataSourcePermissionListKey, index, utils.IDKey, ), ), resource.TestCheckTypeSetElemNestedAttrs( dataSourceFullName, - fmt.Sprintf("%s.*", internal.PermissionDataSourcePermissionListKey), + fmt.Sprintf("%s.*", permission.PermissionDataSourcePermissionListKey), map[string]string{utils.NameKey: expectedPermissionName}, ), resource.TestCheckTypeSetElemNestedAttrs( dataSourceFullName, - fmt.Sprintf("%s.*", internal.PermissionDataSourcePermissionListKey), + fmt.Sprintf("%s.*", permission.PermissionDataSourcePermissionListKey), map[string]string{utils.DescriptionKey: expectedPermissionName}, ), }..., diff --git a/cyral/internal/permission/model_permission.go b/cyral/internal/permission/model_permission.go new file mode 100644 index 00000000..2cc1c1eb --- /dev/null +++ b/cyral/internal/permission/model_permission.go @@ -0,0 +1,39 @@ +package permission + +import ( + "github.com/cyralinc/terraform-provider-cyral/cyral/utils" +) + +type Permission struct { + Id string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` +} + +func permissionsToInterfaceList(permissions []Permission) []any { + permissionsInterfaceList := make([]any, len(permissions)) + for index, permission := range permissions { + permissionsInterfaceList[index] = map[string]any{ + utils.IDKey: permission.Id, + utils.NameKey: permission.Name, + utils.DescriptionKey: permission.Description, + } + } + return permissionsInterfaceList +} + +var AllPermissionNames = []string{ + "Approval Management", + "Modify Policies", + "Modify Roles", + "Modify Sidecars and Repositories", + "Modify Users", + "Repo Crawler", + "View Audit Logs", + "View Datamaps", + "View Integrations", + "View Policies", + "View Roles", + "View Users", + "Modify Integrations", +} diff --git a/cyral/internal/model_policy.go b/cyral/internal/policy/model_policy.go similarity index 97% rename from cyral/internal/model_policy.go rename to cyral/internal/policy/model_policy.go index f94139cb..500dda8f 100644 --- a/cyral/internal/model_policy.go +++ b/cyral/internal/policy/model_policy.go @@ -1,4 +1,4 @@ -package internal +package policy import ( "time" diff --git a/cyral/internal/resource_cyral_policy.go b/cyral/internal/policy/resource_cyral_policy.go similarity index 95% rename from cyral/internal/resource_cyral_policy.go rename to cyral/internal/policy/resource_cyral_policy.go index 209606f2..46e75be9 100644 --- a/cyral/internal/resource_cyral_policy.go +++ b/cyral/internal/policy/resource_cyral_policy.go @@ -1,4 +1,4 @@ -package internal +package policy import ( "context" @@ -216,22 +216,12 @@ func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, m interfa return diag.Diagnostics{} } -func getStrListFromSchemaField(d *schema.ResourceData, field string) []string { - strList := []string{} - - for _, v := range d.Get(field).([]interface{}) { - strList = append(strList, v.(string)) - } - - return strList -} - func getPolicyInfoFromResource(d *schema.ResourceData) Policy { - data := getStrListFromSchemaField(d, "data") - dataTags := getStrListFromSchemaField(d, "data_label_tags") - metadataTags := getStrListFromSchemaField(d, "metadata_tags") + data := utils.GetStrListFromSchemaField(d, "data") + dataTags := utils.GetStrListFromSchemaField(d, "data_label_tags") + metadataTags := utils.GetStrListFromSchemaField(d, "metadata_tags") if len(metadataTags) == 0 { - metadataTags = getStrListFromSchemaField(d, "tags") + metadataTags = utils.GetStrListFromSchemaField(d, "tags") } policy := Policy{ diff --git a/cyral/internal/resource_cyral_policy_test.go b/cyral/internal/policy/resource_cyral_policy_test.go similarity index 87% rename from cyral/internal/resource_cyral_policy_test.go rename to cyral/internal/policy/resource_cyral_policy_test.go index 65bd3d92..b0f7bc11 100644 --- a/cyral/internal/resource_cyral_policy_test.go +++ b/cyral/internal/policy/resource_cyral_policy_test.go @@ -1,17 +1,17 @@ -package internal_test +package policy_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/policy" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -var initialPolicyConfig = internal.Policy{ - Meta: &internal.PolicyMetadata{ +var initialPolicyConfig = policy.Policy{ + Meta: &policy.PolicyMetadata{ Name: utils.AccTestName(utils.PolicyResourceName, "test"), Description: "description", Enabled: false, @@ -21,8 +21,8 @@ var initialPolicyConfig = internal.Policy{ Tags: []string{"DATA_TAG_TEST"}, } -var updatedPolicyConfig = internal.Policy{ - Meta: &internal.PolicyMetadata{ +var updatedPolicyConfig = policy.Policy{ + Meta: &policy.PolicyMetadata{ Name: utils.AccTestName(utils.PolicyResourceName, "test-updated"), Description: "desctiption-updated", Enabled: true, @@ -56,7 +56,7 @@ func TestAccPolicyResource(t *testing.T) { }) } -func setupPolicyTest(integrationData internal.Policy) (string, resource.TestCheckFunc) { +func setupPolicyTest(integrationData policy.Policy) (string, resource.TestCheckFunc) { configuration := formatPolicyTestConfigIntoConfig(integrationData) testFunction := resource.ComposeTestCheckFunc( @@ -101,7 +101,7 @@ func setupPolicyTest(integrationData internal.Policy) (string, resource.TestChec return configuration, testFunction } -func formatPolicyTestConfigIntoConfig(data internal.Policy) string { +func formatPolicyTestConfigIntoConfig(data policy.Policy) string { return fmt.Sprintf(` resource "cyral_policy" "policy_test" { name = "%s" diff --git a/cyral/internal/resource_cyral_policy_rule.go b/cyral/internal/policy/rule/resource_cyral_policy_rule.go similarity index 99% rename from cyral/internal/resource_cyral_policy_rule.go rename to cyral/internal/policy/rule/resource_cyral_policy_rule.go index 3f381b33..2fbf7249 100644 --- a/cyral/internal/resource_cyral_policy_rule.go +++ b/cyral/internal/policy/rule/resource_cyral_policy_rule.go @@ -1,4 +1,4 @@ -package internal +package rule import ( "context" @@ -485,7 +485,7 @@ func getRuleListFromResource(d *schema.ResourceData, name string) []Rule { func getPolicyRuleInfoFromResource(d *schema.ResourceData) PolicyRule { log.Printf("[DEBUG] Init getPolicyRuleInfoFromResource") - hosts := getStrListFromSchemaField(d, "hosts") + hosts := utils.GetStrListFromSchemaField(d, "hosts") identity := d.Get("identities").([]interface{}) diff --git a/cyral/internal/resource_cyral_policy_rule_test.go b/cyral/internal/policy/rule/resource_cyral_policy_rule_test.go similarity index 95% rename from cyral/internal/resource_cyral_policy_rule_test.go rename to cyral/internal/policy/rule/resource_cyral_policy_rule_test.go index dbc43631..37530ca0 100644 --- a/cyral/internal/resource_cyral_policy_rule_test.go +++ b/cyral/internal/policy/rule/resource_cyral_policy_rule_test.go @@ -1,11 +1,11 @@ -package internal_test +package rule_test import ( "context" "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/policy/rule" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -23,7 +23,7 @@ type PolicyRuleConfig struct { DeletedRateLimit int UpdatedRateLimit int ReadRateLimit int - Identities *internal.Identity + Identities *rule.Identity } var initialPolicyRuleConfig PolicyRuleConfig = PolicyRuleConfig{ @@ -33,7 +33,7 @@ var initialPolicyRuleConfig PolicyRuleConfig = PolicyRuleConfig{ DeletedRateLimit: 1, UpdatedRateLimit: 2, ReadRateLimit: 3, - Identities: &internal.Identity{ + Identities: &rule.Identity{ DBRoles: []string{ "db-role-1", }, @@ -47,7 +47,7 @@ var updatedGroupsPolicyRuleConfig PolicyRuleConfig = PolicyRuleConfig{ DeletedRateLimit: 2, UpdatedRateLimit: 3, ReadRateLimit: 4, - Identities: &internal.Identity{ + Identities: &rule.Identity{ Groups: []string{ "groups-1", }, @@ -61,7 +61,7 @@ var updatedServicesPolicyRuleConfig PolicyRuleConfig = PolicyRuleConfig{ DeletedRateLimit: 5, UpdatedRateLimit: 6, ReadRateLimit: 7, - Identities: &internal.Identity{ + Identities: &rule.Identity{ Services: []string{ "services-1", }, @@ -75,7 +75,7 @@ var updatedUsersPolicyRuleConfig PolicyRuleConfig = PolicyRuleConfig{ DeletedRateLimit: 5, UpdatedRateLimit: 6, ReadRateLimit: 7, - Identities: &internal.Identity{ + Identities: &rule.Identity{ Users: []string{ "users-1", }, @@ -137,7 +137,7 @@ func TestPolicyRuleResourceUpgradeV0(t *testing.T) { "id": "policy-rule-id", "policy_id": "policy-id", } - actualNewState, err := internal.UpgradePolicyRuleV0(context.Background(), + actualNewState, err := rule.UpgradePolicyRuleV0(context.Background(), previousState, nil) require.NoError(t, err) expectedNewState := map[string]interface{}{ diff --git a/cyral/internal/model_rego_policy_instance.go b/cyral/internal/regopolicy/model_rego_policy_instance.go similarity index 99% rename from cyral/internal/model_rego_policy_instance.go rename to cyral/internal/regopolicy/model_rego_policy_instance.go index 203ccd1e..080352e1 100644 --- a/cyral/internal/model_rego_policy_instance.go +++ b/cyral/internal/regopolicy/model_rego_policy_instance.go @@ -1,4 +1,4 @@ -package internal +package regopolicy import ( "github.com/cyralinc/terraform-provider-cyral/cyral/utils" diff --git a/cyral/internal/resource_cyral_rego_policy_instance.go b/cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go similarity index 99% rename from cyral/internal/resource_cyral_rego_policy_instance.go rename to cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go index c478b0e6..a56f5af9 100644 --- a/cyral/internal/resource_cyral_rego_policy_instance.go +++ b/cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go @@ -1,4 +1,4 @@ -package internal +package regopolicy import ( "context" diff --git a/cyral/internal/resource_cyral_rego_policy_instance_test.go b/cyral/internal/regopolicy/resource_cyral_rego_policy_instance_test.go similarity index 77% rename from cyral/internal/resource_cyral_rego_policy_instance_test.go rename to cyral/internal/regopolicy/resource_cyral_rego_policy_instance_test.go index 5113ce9f..f044c77b 100644 --- a/cyral/internal/resource_cyral_rego_policy_instance_test.go +++ b/cyral/internal/regopolicy/resource_cyral_rego_policy_instance_test.go @@ -1,11 +1,11 @@ -package internal_test +package regopolicy_test import ( "fmt" "regexp" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/regopolicy" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -43,9 +43,9 @@ func TestAccRegoPolicyInstanceResource(t *testing.T) { func getRequiredArgumentTestSteps() []resource.TestStep { requiredArgumentsTestSteps := []resource.TestStep{} requiredArguments := []string{ - internal.RegoPolicyInstanceNameKey, - internal.RegoPolicyInstanceCategoryKey, - internal.RegoPolicyInstanceTemplateIDKey, + regopolicy.RegoPolicyInstanceNameKey, + regopolicy.RegoPolicyInstanceCategoryKey, + regopolicy.RegoPolicyInstanceTemplateIDKey, } for _, argument := range requiredArguments { requiredArgumentsTestSteps = append(requiredArgumentsTestSteps, resource.TestStep{ @@ -59,15 +59,15 @@ func getRequiredArgumentTestSteps() []resource.TestStep { } type RegoPolicyInstanceTestParameters struct { - policy internal.RegoPolicyInstancePayload + policy regopolicy.RegoPolicyInstancePayload policyCategory string isUpdateOperation bool } var ( regoPolicyInstanceOnlyRequiredArguments = RegoPolicyInstanceTestParameters{ - policy: internal.RegoPolicyInstancePayload{ - RegoPolicyInstance: internal.RegoPolicyInstance{ + policy: regopolicy.RegoPolicyInstancePayload{ + RegoPolicyInstance: regopolicy.RegoPolicyInstance{ Name: "some-rate-limit-policy", TemplateID: "rate-limit", Parameters: "{\"rateLimit\":7,\"labels\":[\"EMAIL\"],\"alertSeverity\":\"high\",\"block\":false}", @@ -76,14 +76,14 @@ var ( policyCategory: "SECURITY", } regoPolicyInstanceAllArguments = RegoPolicyInstanceTestParameters{ - policy: internal.RegoPolicyInstancePayload{ - RegoPolicyInstance: internal.RegoPolicyInstance{ + policy: regopolicy.RegoPolicyInstancePayload{ + RegoPolicyInstance: regopolicy.RegoPolicyInstance{ Name: "some-rate-limit-policy", Description: "Some description.", TemplateID: "rate-limit", Parameters: "{\"rateLimit\":7,\"labels\":[\"EMAIL\"],\"alertSeverity\":\"high\",\"block\":false}", Enabled: true, - Scope: &internal.RegoPolicyInstanceScope{ + Scope: ®opolicy.RegoPolicyInstanceScope{ RepoIDs: []string{"2U4prk5o6yi1rTvvXyImz8lgbgG"}, }, Tags: []string{"tag1", "tag2"}, @@ -156,45 +156,45 @@ func testAccRegoPolicyInstanceCheck( ) resource.TestCheckFunc { testCheckFuncs := []resource.TestCheckFunc{ resource.TestCheckResourceAttrSet("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceResourceIDKey), + regopolicy.RegoPolicyInstanceResourceIDKey), resource.TestCheckResourceAttrSet("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstancePolicyIDKey), + regopolicy.RegoPolicyInstancePolicyIDKey), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceCategoryKey, parameters.policyCategory), + regopolicy.RegoPolicyInstanceCategoryKey, parameters.policyCategory), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceNameKey, parameters.policy.RegoPolicyInstance.Name), + regopolicy.RegoPolicyInstanceNameKey, parameters.policy.RegoPolicyInstance.Name), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceDescriptionKey, parameters.policy.RegoPolicyInstance.Description), + regopolicy.RegoPolicyInstanceDescriptionKey, parameters.policy.RegoPolicyInstance.Description), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceTemplateIDKey, parameters.policy.RegoPolicyInstance.TemplateID), + regopolicy.RegoPolicyInstanceTemplateIDKey, parameters.policy.RegoPolicyInstance.TemplateID), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceParametersKey, parameters.policy.RegoPolicyInstance.Parameters), + regopolicy.RegoPolicyInstanceParametersKey, parameters.policy.RegoPolicyInstance.Parameters), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceEnabledKey, fmt.Sprintf("%t", parameters.policy.RegoPolicyInstance.Enabled)), + regopolicy.RegoPolicyInstanceEnabledKey, fmt.Sprintf("%t", parameters.policy.RegoPolicyInstance.Enabled)), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - fmt.Sprintf("%s.#", internal.RegoPolicyInstanceTagsKey), + fmt.Sprintf("%s.#", regopolicy.RegoPolicyInstanceTagsKey), fmt.Sprintf("%d", len(parameters.policy.RegoPolicyInstance.Tags))), resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - fmt.Sprintf("%s.#", internal.RegoPolicyInstanceCreatedKey), "1"), + fmt.Sprintf("%s.#", regopolicy.RegoPolicyInstanceCreatedKey), "1"), } var durationTestCheckFunc resource.TestCheckFunc if parameters.policy.Duration != "" { durationTestCheckFunc = resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceDurationKey, parameters.policy.Duration) + regopolicy.RegoPolicyInstanceDurationKey, parameters.policy.Duration) } else { durationTestCheckFunc = resource.TestCheckNoResourceAttr("cyral_rego_policy_instance.policy_1", - internal.RegoPolicyInstanceDurationKey) + regopolicy.RegoPolicyInstanceDurationKey) } testCheckFuncs = append(testCheckFuncs, durationTestCheckFunc) var lastUpdatedTestCheckFunc resource.TestCheckFunc if parameters.isUpdateOperation { lastUpdatedTestCheckFunc = resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - fmt.Sprintf("%s.#", internal.RegoPolicyInstanceLastUpdatedKey), "1") + fmt.Sprintf("%s.#", regopolicy.RegoPolicyInstanceLastUpdatedKey), "1") } else { lastUpdatedTestCheckFunc = resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - fmt.Sprintf("%s.#", internal.RegoPolicyInstanceLastUpdatedKey), "0") + fmt.Sprintf("%s.#", regopolicy.RegoPolicyInstanceLastUpdatedKey), "0") } testCheckFuncs = append(testCheckFuncs, lastUpdatedTestCheckFunc) @@ -203,13 +203,13 @@ func testAccRegoPolicyInstanceCheck( repoIDs := parameters.policy.RegoPolicyInstance.Scope.RepoIDs scopeTestCheckFunc = resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - fmt.Sprintf("%s.0.%s.#", internal.RegoPolicyInstanceScopeKey, internal.RegoPolicyInstanceRepoIDsKey), + fmt.Sprintf("%s.0.%s.#", regopolicy.RegoPolicyInstanceScopeKey, regopolicy.RegoPolicyInstanceRepoIDsKey), fmt.Sprintf("%d", len(repoIDs)), ), ) } else { scopeTestCheckFunc = resource.TestCheckResourceAttr("cyral_rego_policy_instance.policy_1", - fmt.Sprintf("%s.#", internal.RegoPolicyInstanceScopeKey), "0") + fmt.Sprintf("%s.#", regopolicy.RegoPolicyInstanceScopeKey), "0") } testCheckFuncs = append(testCheckFuncs, scopeTestCheckFunc) diff --git a/cyral/internal/repository/bind/resource_cyral_repository_binding.go b/cyral/internal/repository/binding/resource_cyral_repository_binding.go similarity index 99% rename from cyral/internal/repository/bind/resource_cyral_repository_binding.go rename to cyral/internal/repository/binding/resource_cyral_repository_binding.go index e05922ef..c553cec5 100644 --- a/cyral/internal/repository/bind/resource_cyral_repository_binding.go +++ b/cyral/internal/repository/binding/resource_cyral_repository_binding.go @@ -1,4 +1,4 @@ -package bind +package binding import ( "context" diff --git a/cyral/internal/repository/bind/resource_cyral_repository_binding_test.go b/cyral/internal/repository/binding/resource_cyral_repository_binding_test.go similarity index 97% rename from cyral/internal/repository/bind/resource_cyral_repository_binding_test.go rename to cyral/internal/repository/binding/resource_cyral_repository_binding_test.go index 224db3b8..d76582f0 100644 --- a/cyral/internal/repository/bind/resource_cyral_repository_binding_test.go +++ b/cyral/internal/repository/binding/resource_cyral_repository_binding_test.go @@ -1,11 +1,11 @@ -package bind_test +package binding_test import ( "fmt" "strconv" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/bind" + bind "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/binding" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" diff --git a/cyral/internal/repository/conf/analysis/resource_cyral_repository_conf_analysis.go b/cyral/internal/repository/confanalysis/resource_cyral_repository_conf_analysis.go similarity index 99% rename from cyral/internal/repository/conf/analysis/resource_cyral_repository_conf_analysis.go rename to cyral/internal/repository/confanalysis/resource_cyral_repository_conf_analysis.go index 032e3819..fe10deb9 100644 --- a/cyral/internal/repository/conf/analysis/resource_cyral_repository_conf_analysis.go +++ b/cyral/internal/repository/confanalysis/resource_cyral_repository_conf_analysis.go @@ -1,4 +1,4 @@ -package analysis +package confanalysis import ( "context" diff --git a/cyral/internal/repository/conf/analysis/resource_cyral_repository_conf_analysis_test.go b/cyral/internal/repository/confanalysis/resource_cyral_repository_conf_analysis_test.go similarity index 98% rename from cyral/internal/repository/conf/analysis/resource_cyral_repository_conf_analysis_test.go rename to cyral/internal/repository/confanalysis/resource_cyral_repository_conf_analysis_test.go index 41ea960f..c1e4a668 100644 --- a/cyral/internal/repository/conf/analysis/resource_cyral_repository_conf_analysis_test.go +++ b/cyral/internal/repository/confanalysis/resource_cyral_repository_conf_analysis_test.go @@ -1,4 +1,4 @@ -package analysis_test +package confanalysis_test import ( "context" @@ -6,7 +6,7 @@ import ( "regexp" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/conf/analysis" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/confanalysis" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -65,7 +65,7 @@ func TestRepositoryConfAnalysisResourceUpgradeV0(t *testing.T) { "id": "repositoryID/ConfAnalysis", "repository_id": "repositoryID", } - actualNewState, err := analysis.UpgradeRepositoryConfAnalysisV0(context.Background(), + actualNewState, err := confanalysis.UpgradeRepositoryConfAnalysisV0(context.Background(), previousState, nil) require.NoError(t, err) expectedNewState := map[string]interface{}{ diff --git a/cyral/internal/repository/conf/auth/resource_cyral_repository_conf_auth.go b/cyral/internal/repository/confauth/resource_cyral_repository_conf_auth.go similarity index 99% rename from cyral/internal/repository/conf/auth/resource_cyral_repository_conf_auth.go rename to cyral/internal/repository/confauth/resource_cyral_repository_conf_auth.go index 5e1c21c9..fafad39d 100644 --- a/cyral/internal/repository/conf/auth/resource_cyral_repository_conf_auth.go +++ b/cyral/internal/repository/confauth/resource_cyral_repository_conf_auth.go @@ -1,4 +1,4 @@ -package auth +package confauth import ( "context" diff --git a/cyral/internal/repository/conf/auth/resource_cyral_repository_conf_auth_test.go b/cyral/internal/repository/confauth/resource_cyral_repository_conf_auth_test.go similarity index 97% rename from cyral/internal/repository/conf/auth/resource_cyral_repository_conf_auth_test.go rename to cyral/internal/repository/confauth/resource_cyral_repository_conf_auth_test.go index 812038c2..6ad02099 100644 --- a/cyral/internal/repository/conf/auth/resource_cyral_repository_conf_auth_test.go +++ b/cyral/internal/repository/confauth/resource_cyral_repository_conf_auth_test.go @@ -1,11 +1,11 @@ -package auth_test +package confauth_test import ( "context" "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/conf/auth" + auth "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/confauth" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" diff --git a/cyral/internal/repository/datamap/model.go b/cyral/internal/repository/datamap/model.go index 6fc387da..aff12615 100644 --- a/cyral/internal/repository/datamap/model.go +++ b/cyral/internal/repository/datamap/model.go @@ -35,6 +35,7 @@ func (dm *DataMap) WriteToSchema(d *schema.ResourceData) error { mappings = append(mappings, mappingContents) } + d.SetId(d.Get("repository_id").(string)) return d.Set("mapping", mappings) } diff --git a/cyral/internal/repository/datamap/resource.go b/cyral/internal/repository/datamap/resource.go index 1f8704cc..17cf6a43 100644 --- a/cyral/internal/repository/datamap/resource.go +++ b/cyral/internal/repository/datamap/resource.go @@ -23,7 +23,7 @@ func resourceSchema() *schema.Resource { c.ControlPlane, d.Get("repository_id").(string)) }, - NewResourceData: func() core.ResourceData { return &DataMap{} }, + NewResourceData: func() core.ResourceData { return &DataMapRequest{} }, NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &DataMap{} }, }, readDataMapConfig, ), @@ -38,7 +38,7 @@ func resourceSchema() *schema.Resource { c.ControlPlane, d.Get("repository_id").(string)) }, - NewResourceData: func() core.ResourceData { return &DataMap{} }, + NewResourceData: func() core.ResourceData { return &DataMapRequest{} }, }, readDataMapConfig, ), DeleteContext: core.DeleteResource( diff --git a/cyral/internal/data_source_cyral_role.go b/cyral/internal/role/data_source_cyral_role.go similarity index 99% rename from cyral/internal/data_source_cyral_role.go rename to cyral/internal/role/data_source_cyral_role.go index d938e518..5e38ff91 100644 --- a/cyral/internal/data_source_cyral_role.go +++ b/cyral/internal/role/data_source_cyral_role.go @@ -1,4 +1,4 @@ -package internal +package role import ( "encoding/json" diff --git a/cyral/internal/data_source_cyral_role_test.go b/cyral/internal/role/data_source_cyral_role_test.go similarity index 97% rename from cyral/internal/data_source_cyral_role_test.go rename to cyral/internal/role/data_source_cyral_role_test.go index ae4d89d1..5d6da4be 100644 --- a/cyral/internal/data_source_cyral_role_test.go +++ b/cyral/internal/role/data_source_cyral_role_test.go @@ -1,4 +1,4 @@ -package internal_test +package role_test import ( "fmt" diff --git a/cyral/internal/model_permission.go b/cyral/internal/role/model_role.go similarity index 78% rename from cyral/internal/model_permission.go rename to cyral/internal/role/model_role.go index cfc6ad1c..f7280bef 100644 --- a/cyral/internal/model_permission.go +++ b/cyral/internal/role/model_role.go @@ -1,43 +1,6 @@ -package internal +package role -import ( - "github.com/cyralinc/terraform-provider-cyral/cyral/utils" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -type Permission struct { - Id string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` -} - -func permissionsToInterfaceList(permissions []Permission) []any { - permissionsInterfaceList := make([]any, len(permissions)) - for index, permission := range permissions { - permissionsInterfaceList[index] = map[string]any{ - utils.IDKey: permission.Id, - utils.NameKey: permission.Name, - utils.DescriptionKey: permission.Description, - } - } - return permissionsInterfaceList -} - -var AllPermissionNames = []string{ - "Approval Management", - "Modify Policies", - "Modify Roles", - "Modify Sidecars and Repositories", - "Modify Users", - "Repo Crawler", - "View Audit Logs", - "View Datamaps", - "View Integrations", - "View Policies", - "View Roles", - "View Users", - "Modify Integrations", -} +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" const ( // Schema keys diff --git a/cyral/internal/resource_cyral_role.go b/cyral/internal/role/resource_cyral_role.go similarity index 94% rename from cyral/internal/resource_cyral_role.go rename to cyral/internal/role/resource_cyral_role.go index dc3ceb7e..dc0dc110 100644 --- a/cyral/internal/resource_cyral_role.go +++ b/cyral/internal/role/resource_cyral_role.go @@ -1,4 +1,4 @@ -package internal +package role import ( "context" @@ -9,6 +9,7 @@ import ( "strings" "github.com/cyralinc/terraform-provider-cyral/cyral/client" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/permission" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +27,7 @@ type RoleDataResponse struct { Id string `json:"id,omitempty"` Name string `json:"name,omitempty"` // Permissions correspond to Roles in API. - Permissions []*Permission `json:"roles,omitempty"` + Permissions []*permission.Permission `json:"roles,omitempty"` } func ResourceRole() *schema.Resource { @@ -192,7 +193,7 @@ func getRoleDataFromResource(c *client.Client, d *schema.ResourceData) (RoleData }, nil } -func flattenPermissions(permissions []*Permission) []interface{} { +func flattenPermissions(permissions []*permission.Permission) []interface{} { flatPermissions := make([]interface{}, 1) permissionsMap := make(map[string]interface{}) @@ -211,17 +212,17 @@ func formatPermissionName(permissionName string) string { return permissionName } -func getPermissionsFromAPI(c *client.Client) ([]*Permission, error) { +func getPermissionsFromAPI(c *client.Client) ([]*permission.Permission, error) { url := fmt.Sprintf("https://%s/v1/users/roles", c.ControlPlane) body, err := c.DoRequest(url, http.MethodGet, nil) if err != nil { - return []*Permission{}, err + return []*permission.Permission{}, err } response := RoleDataResponse{} if err := json.Unmarshal(body, &response); err != nil { - return []*Permission{}, err + return []*permission.Permission{}, err } return response.Permissions, nil diff --git a/cyral/internal/resource_cyral_role_sso_groups.go b/cyral/internal/role/resource_cyral_role_sso_groups.go similarity index 99% rename from cyral/internal/resource_cyral_role_sso_groups.go rename to cyral/internal/role/resource_cyral_role_sso_groups.go index d51e4f71..47c7b296 100644 --- a/cyral/internal/resource_cyral_role_sso_groups.go +++ b/cyral/internal/role/resource_cyral_role_sso_groups.go @@ -1,4 +1,4 @@ -package internal +package role import ( "context" diff --git a/cyral/internal/resource_cyral_role_sso_groups_test.go b/cyral/internal/role/resource_cyral_role_sso_groups_test.go similarity index 97% rename from cyral/internal/resource_cyral_role_sso_groups_test.go rename to cyral/internal/role/resource_cyral_role_sso_groups_test.go index bfe708d5..d71c214b 100644 --- a/cyral/internal/resource_cyral_role_sso_groups_test.go +++ b/cyral/internal/role/resource_cyral_role_sso_groups_test.go @@ -1,4 +1,4 @@ -package internal_test +package role_test import ( "context" @@ -6,7 +6,7 @@ import ( "regexp" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/role" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -92,7 +92,7 @@ func TestRoleSSOGroupsResourceUpgradeV0(t *testing.T) { "id": "roleID/SSOGroups", "role_id": "roleID", } - actualNewState, err := internal.UpgradeRoleSSOGroupsV0(context.Background(), + actualNewState, err := role.UpgradeRoleSSOGroupsV0(context.Background(), previousState, nil) require.NoError(t, err) expectedNewState := map[string]interface{}{ diff --git a/cyral/internal/resource_cyral_role_test.go b/cyral/internal/role/resource_cyral_role_test.go similarity index 99% rename from cyral/internal/resource_cyral_role_test.go rename to cyral/internal/role/resource_cyral_role_test.go index 3ec86596..f330c590 100644 --- a/cyral/internal/resource_cyral_role_test.go +++ b/cyral/internal/role/resource_cyral_role_test.go @@ -1,4 +1,4 @@ -package internal_test +package role_test import ( "fmt" diff --git a/cyral/internal/data_source_cyral_saml_certificate.go b/cyral/internal/samlcertificate/data_source_cyral_saml_certificate.go similarity index 98% rename from cyral/internal/data_source_cyral_saml_certificate.go rename to cyral/internal/samlcertificate/data_source_cyral_saml_certificate.go index 221a68f4..b7bab240 100644 --- a/cyral/internal/data_source_cyral_saml_certificate.go +++ b/cyral/internal/samlcertificate/data_source_cyral_saml_certificate.go @@ -1,4 +1,4 @@ -package internal +package samlcertificate import ( "fmt" diff --git a/cyral/internal/data_source_cyral_saml_certificate_test.go b/cyral/internal/samlcertificate/data_source_cyral_saml_certificate_test.go similarity index 96% rename from cyral/internal/data_source_cyral_saml_certificate_test.go rename to cyral/internal/samlcertificate/data_source_cyral_saml_certificate_test.go index 946d7920..0a22d28f 100644 --- a/cyral/internal/data_source_cyral_saml_certificate_test.go +++ b/cyral/internal/samlcertificate/data_source_cyral_saml_certificate_test.go @@ -1,4 +1,4 @@ -package internal_test +package samlcertificate_test import ( "testing" diff --git a/cyral/internal/data_source_cyral_saml_configuration.go b/cyral/internal/samlconfiguration/data_source_cyral_saml_configuration.go similarity index 95% rename from cyral/internal/data_source_cyral_saml_configuration.go rename to cyral/internal/samlconfiguration/data_source_cyral_saml_configuration.go index 2de81fee..bff3ae95 100644 --- a/cyral/internal/data_source_cyral_saml_configuration.go +++ b/cyral/internal/samlconfiguration/data_source_cyral_saml_configuration.go @@ -1,4 +1,4 @@ -package internal +package samlconfiguration import ( "context" @@ -8,6 +8,7 @@ import ( "net/http" "github.com/cyralinc/terraform-provider-cyral/cyral/client" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -181,7 +182,7 @@ func dataSourceSAMLConfigurationRead(ctx context.Context, d *schema.ResourceData return utils.CreateError("Unable to retrieve saml configuration", fmt.Sprintf("%v", err)) } - response := SAMLConfiguration{} + response := deprecated.SAMLConfiguration{} if err := json.Unmarshal(body, &response); err != nil { return utils.CreateError("Unable to unmarshall JSON", fmt.Sprintf("%v", err)) } @@ -196,14 +197,14 @@ func dataSourceSAMLConfigurationRead(ctx context.Context, d *schema.ResourceData return diag.Diagnostics{} } -func getSAMLMetadataRequestFromSchema(d *schema.ResourceData) ParseSAMLMetadataRequest { - return ParseSAMLMetadataRequest{ +func getSAMLMetadataRequestFromSchema(d *schema.ResourceData) deprecated.ParseSAMLMetadataRequest { + return deprecated.ParseSAMLMetadataRequest{ SamlMetadataURL: d.Get("saml_metadata_url").(string), Base64SamlMetadataDocument: d.Get("base_64_saml_metadata_document").(string), } } -func setSAMLConfigurationToSchema(d *schema.ResourceData, data SAMLConfiguration) { +func setSAMLConfigurationToSchema(d *schema.ResourceData, data deprecated.SAMLConfiguration) { if data.Config != nil { d.Set("disable_using_jwks_url", data.Config.DisableUsingJWKSUrl) d.Set("sync_mode", data.Config.SyncMode) diff --git a/cyral/internal/data_source_cyral_saml_configuration_test.go b/cyral/internal/samlconfiguration/data_source_cyral_saml_configuration_test.go similarity index 99% rename from cyral/internal/data_source_cyral_saml_configuration_test.go rename to cyral/internal/samlconfiguration/data_source_cyral_saml_configuration_test.go index 5e204fe2..1029d3ef 100644 --- a/cyral/internal/data_source_cyral_saml_configuration_test.go +++ b/cyral/internal/samlconfiguration/data_source_cyral_saml_configuration_test.go @@ -1,4 +1,4 @@ -package internal_test +package samlconfiguration_test import ( "fmt" diff --git a/cyral/internal/model_service_account.go b/cyral/internal/serviceaccount/model_service_account.go similarity index 98% rename from cyral/internal/model_service_account.go rename to cyral/internal/serviceaccount/model_service_account.go index 0aa1cdaa..d653f087 100644 --- a/cyral/internal/model_service_account.go +++ b/cyral/internal/serviceaccount/model_service_account.go @@ -1,4 +1,4 @@ -package internal +package serviceaccount import ( "fmt" diff --git a/cyral/internal/resource_cyral_service_account.go b/cyral/internal/serviceaccount/resource_cyral_service_account.go similarity index 99% rename from cyral/internal/resource_cyral_service_account.go rename to cyral/internal/serviceaccount/resource_cyral_service_account.go index 519fec6a..5cf79968 100644 --- a/cyral/internal/resource_cyral_service_account.go +++ b/cyral/internal/serviceaccount/resource_cyral_service_account.go @@ -1,4 +1,4 @@ -package internal +package serviceaccount import ( "fmt" diff --git a/cyral/internal/resource_cyral_service_account_test.go b/cyral/internal/serviceaccount/resource_cyral_service_account_test.go similarity index 84% rename from cyral/internal/resource_cyral_service_account_test.go rename to cyral/internal/serviceaccount/resource_cyral_service_account_test.go index 3e7d53ad..94a08a4b 100644 --- a/cyral/internal/resource_cyral_service_account_test.go +++ b/cyral/internal/serviceaccount/resource_cyral_service_account_test.go @@ -1,11 +1,12 @@ -package internal_test +package serviceaccount_test import ( "fmt" "regexp" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/permission" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/serviceaccount" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -43,7 +44,7 @@ func accTestStepServiceAccountResource_RequiredArgumentDisplayName(resourceName ExpectError: regexp.MustCompile( fmt.Sprintf( `The argument "%s" is required, but no definition was found.`, - internal.ServiceAccountResourceDisplayNameKey, + serviceaccount.ServiceAccountResourceDisplayNameKey, ), ), } @@ -61,7 +62,7 @@ func accTestStepServiceAccountResource_RequiredArgumentPermissions(resourceName ExpectError: regexp.MustCompile( fmt.Sprintf( `The argument "%s" is required, but no definition was found.`, - internal.ServiceAccountResourcePermissionIDsKey, + serviceaccount.ServiceAccountResourcePermissionIDsKey, ), ), } @@ -108,27 +109,27 @@ func accTestStepServiceAccountResource_DuplicatedPermission(resourceName string) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( resourceFullName, - internal.ServiceAccountResourceDisplayNameKey, + serviceaccount.ServiceAccountResourceDisplayNameKey, displayName, ), resource.TestCheckResourceAttr( resourceFullName, - fmt.Sprintf("%s.#", internal.ServiceAccountResourcePermissionIDsKey), + fmt.Sprintf("%s.#", serviceaccount.ServiceAccountResourcePermissionIDsKey), "1", ), resource.TestCheckResourceAttrPair( resourceFullName, utils.IDKey, resourceFullName, - internal.ServiceAccountResourceClientIDKey, + serviceaccount.ServiceAccountResourceClientIDKey, ), resource.TestCheckResourceAttrSet( resourceFullName, - internal.ServiceAccountResourceClientIDKey, + serviceaccount.ServiceAccountResourceClientIDKey, ), resource.TestCheckResourceAttrSet( resourceFullName, - internal.ServiceAccountResourceClientSecretKey, + serviceaccount.ServiceAccountResourceClientSecretKey, ), ) return resource.TestStep{ @@ -142,7 +143,7 @@ func accTestStepServiceAccountResource_AllPermissions(resourceName string) resou config, check := getAccTestStepForServiceAccountResourceFullConfig( resourceName, displayName, - internal.AllPermissionNames, + permission.AllPermissionNames, ) return resource.TestStep{ Config: config, @@ -192,33 +193,33 @@ func getAccTestStepForServiceAccountResourceFullConfig( if contains(local.serviceAccountPermissions, permission.name) ] } - `, resourceName, displayName, internal.PermissionDataSourcePermissionListKey, + `, resourceName, displayName, permission.PermissionDataSourcePermissionListKey, ) resourceFullName := fmt.Sprintf("cyral_service_account.%s", resourceName) checks := []resource.TestCheckFunc{ resource.TestCheckResourceAttr( resourceFullName, - internal.ServiceAccountResourceDisplayNameKey, + serviceaccount.ServiceAccountResourceDisplayNameKey, displayName, ), resource.TestCheckResourceAttr( resourceFullName, - fmt.Sprintf("%s.#", internal.ServiceAccountResourcePermissionIDsKey), + fmt.Sprintf("%s.#", serviceaccount.ServiceAccountResourcePermissionIDsKey), fmt.Sprintf("%d", len(permissionNames)), ), resource.TestCheckResourceAttrPair( resourceFullName, utils.IDKey, resourceFullName, - internal.ServiceAccountResourceClientIDKey, + serviceaccount.ServiceAccountResourceClientIDKey, ), resource.TestCheckResourceAttrSet( resourceFullName, - internal.ServiceAccountResourceClientIDKey, + serviceaccount.ServiceAccountResourceClientIDKey, ), resource.TestCheckResourceAttrSet( resourceFullName, - internal.ServiceAccountResourceClientSecretKey, + serviceaccount.ServiceAccountResourceClientSecretKey, ), } return config, resource.ComposeTestCheckFunc(checks...) diff --git a/cyral/internal/sweep/sweep_test.go b/cyral/internal/sweep/sweep_test.go index daa512d4..424a3d06 100644 --- a/cyral/internal/sweep/sweep_test.go +++ b/cyral/internal/sweep/sweep_test.go @@ -7,8 +7,10 @@ import ( "testing" "github.com/cyralinc/terraform-provider-cyral/cyral/client" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/policy" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/role" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -124,7 +126,7 @@ func sweepRole(_ string) error { if err != nil { return err } - resp, err := internal.ListRoles(c) + resp, err := role.ListRoles(c) if err != nil { return err } @@ -148,7 +150,7 @@ func sweepPolicy(_ string) error { if err != nil { return err } - policies, err := internal.ListPolicies(c) + policies, err := policy.ListPolicies(c) if err != nil { return err } @@ -171,7 +173,7 @@ func sweepIntegrationIdP(_ string) error { if err != nil { return err } - resp, err := internal.ListIdPIntegrations(c) + resp, err := deprecated.ListIdPIntegrations(c) if err != nil { return fmt.Errorf("failed to get IdP integrations: %w", err) } diff --git a/cyral/internal/data_source_cyral_system_info.go b/cyral/internal/systeminfo/data_source_cyral_system_info.go similarity index 98% rename from cyral/internal/data_source_cyral_system_info.go rename to cyral/internal/systeminfo/data_source_cyral_system_info.go index d10cd44b..296eac48 100644 --- a/cyral/internal/data_source_cyral_system_info.go +++ b/cyral/internal/systeminfo/data_source_cyral_system_info.go @@ -1,4 +1,4 @@ -package internal +package systeminfo import ( "fmt" diff --git a/cyral/internal/data_source_cyral_system_info_test.go b/cyral/internal/systeminfo/data_source_cyral_system_info_test.go similarity index 87% rename from cyral/internal/data_source_cyral_system_info_test.go rename to cyral/internal/systeminfo/data_source_cyral_system_info_test.go index ce33d0ba..e0c481c8 100644 --- a/cyral/internal/data_source_cyral_system_info_test.go +++ b/cyral/internal/systeminfo/data_source_cyral_system_info_test.go @@ -1,10 +1,10 @@ -package internal_test +package systeminfo_test import ( "fmt" "testing" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/systeminfo" "github.com/cyralinc/terraform-provider-cyral/cyral/provider" "github.com/cyralinc/terraform-provider-cyral/cyral/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -38,11 +38,11 @@ func accTestStepSystemInfoDataSource_ListAllSystemInfo(dataSourceName string) re ), resource.TestCheckResourceAttrSet( dataSourceFullName, - internal.ControlPlaneVersionKey, + systeminfo.ControlPlaneVersionKey, ), resource.TestCheckResourceAttrSet( dataSourceFullName, - internal.SidecarLatestVersionKey, + systeminfo.SidecarLatestVersionKey, ), ) return resource.TestStep{ diff --git a/cyral/provider/provider.go b/cyral/provider/provider.go index f77965d4..fc9cfc8e 100644 --- a/cyral/provider/provider.go +++ b/cyral/provider/provider.go @@ -11,20 +11,37 @@ import ( "github.com/cyralinc/terraform-provider-cyral/cyral/client" "github.com/cyralinc/terraform-provider-cyral/cyral/core" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/awsiam" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/confextension/mfaduo" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/confextension/pagerduty" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/hcvault" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/idpsaml" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/logging" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/slack" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/teams" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/permission" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/policy" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/policy/rule" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/regopolicy" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/accessgateway" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/accessrules" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/bind" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/conf/analysis" - "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/conf/auth" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/binding" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/confanalysis" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/confauth" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/network" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/repository/useraccount" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/role" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/samlcertificate" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/samlconfiguration" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/serviceaccount" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar/credentials" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar/health" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar/instance" "github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar/listener" + "github.com/cyralinc/terraform-provider-cyral/cyral/internal/systeminfo" ) func init() { @@ -95,23 +112,23 @@ func getDataSourceMap(ps []core.PackageSchema) map[string]*schema.Resource { } } - schemaMap["cyral_integration_idp"] = internal.DataSourceIntegrationIdP() - schemaMap["cyral_integration_idp_saml"] = internal.DataSourceIntegrationIdPSAML() - schemaMap["cyral_integration_logging"] = internal.DataSourceIntegrationLogging() - schemaMap["cyral_permission"] = internal.DataSourcePermission() + schemaMap["cyral_integration_idp"] = deprecated.DataSourceIntegrationIdP() + schemaMap["cyral_integration_idp_saml"] = idpsaml.DataSourceIntegrationIdPSAML() + schemaMap["cyral_integration_logging"] = logging.DataSourceIntegrationLogging() + schemaMap["cyral_permission"] = permission.DataSourcePermission() schemaMap["cyral_repository"] = repository.DataSourceRepository() - schemaMap["cyral_role"] = internal.DataSourceRole() - schemaMap["cyral_saml_certificate"] = internal.DataSourceSAMLCertificate() - schemaMap["cyral_saml_configuration"] = internal.DataSourceSAMLConfiguration() + schemaMap["cyral_role"] = role.DataSourceRole() + schemaMap["cyral_saml_certificate"] = samlcertificate.DataSourceSAMLCertificate() + schemaMap["cyral_saml_configuration"] = samlconfiguration.DataSourceSAMLConfiguration() schemaMap["cyral_sidecar_bound_ports"] = sidecar.DataSourceSidecarBoundPorts() - schemaMap["cyral_sidecar_cft_template"] = sidecar.DataSourceSidecarCftTemplate() + schemaMap["cyral_sidecar_cft_template"] = deprecated.DataSourceSidecarCftTemplate() schemaMap["cyral_sidecar_health"] = health.DataSourceSidecarHealth() schemaMap["cyral_sidecar_id"] = sidecar.DataSourceSidecarID() - schemaMap["cyral_sidecar_instance_ids"] = instance.DataSourceSidecarInstanceIDs() + schemaMap["cyral_sidecar_instance_ids"] = deprecated.DataSourceSidecarInstanceIDs() schemaMap["cyral_sidecar_instance_stats"] = instance.DataSourceSidecarInstanceStats() schemaMap["cyral_sidecar_instance"] = instance.DataSourceSidecarInstance() schemaMap["cyral_sidecar_listener"] = listener.DataSourceSidecarListener() - schemaMap["cyral_system_info"] = internal.DataSourceSystemInfo() + schemaMap["cyral_system_info"] = systeminfo.DataSourceSystemInfo() log.Printf("[DEBUG] end getDataSourceMap") @@ -134,41 +151,41 @@ func getResourceMap(ps []core.PackageSchema) map[string]*schema.Resource { // // TODO Once the resources are migrated to the new SchemaRegister // // abstraction, these calls from provider to resource will be removed. - schemaMap["cyral_integration_aws_iam"] = internal.ResourceIntegrationAWSIAM() - schemaMap["cyral_integration_datadog"] = internal.ResourceIntegrationDatadog() - schemaMap["cyral_integration_mfa_duo"] = internal.ResourceIntegrationMFADuo() - schemaMap["cyral_integration_elk"] = internal.ResourceIntegrationELK() - schemaMap["cyral_integration_hc_vault"] = internal.ResourceIntegrationHCVault() - schemaMap["cyral_integration_logstash"] = internal.ResourceIntegrationLogstash() - schemaMap["cyral_integration_looker"] = internal.ResourceIntegrationLooker() - schemaMap["cyral_integration_microsoft_teams"] = internal.ResourceIntegrationMsTeams() - schemaMap["cyral_integration_pager_duty"] = internal.ResourceIntegrationPagerDuty() - schemaMap["cyral_integration_slack_alerts"] = internal.ResourceIntegrationSlackAlerts() - schemaMap["cyral_integration_splunk"] = internal.ResourceIntegrationSplunk() - schemaMap["cyral_integration_idp_aad"] = internal.ResourceIntegrationIdP("aad", idpDeprecationMessage) - schemaMap["cyral_integration_idp_adfs"] = internal.ResourceIntegrationIdP("adfs-2016", idpDeprecationMessage) - schemaMap["cyral_integration_idp_forgerock"] = internal.ResourceIntegrationIdP("forgerock", "") - schemaMap["cyral_integration_idp_gsuite"] = internal.ResourceIntegrationIdP("gsuite", idpDeprecationMessage) - schemaMap["cyral_integration_idp_okta"] = internal.ResourceIntegrationIdP("okta", idpDeprecationMessage) - schemaMap["cyral_integration_idp_ping_one"] = internal.ResourceIntegrationIdP("pingone", idpDeprecationMessage) - schemaMap["cyral_integration_idp_saml"] = internal.ResourceIntegrationIdPSAML() - schemaMap["cyral_integration_idp_saml_draft"] = internal.ResourceIntegrationIdPSAMLDraft() - schemaMap["cyral_integration_sumo_logic"] = internal.ResourceIntegrationSumoLogic() - schemaMap["cyral_integration_logging"] = internal.ResourceIntegrationLogging() - schemaMap["cyral_policy"] = internal.ResourcePolicy() - schemaMap["cyral_policy_rule"] = internal.ResourcePolicyRule() - schemaMap["cyral_rego_policy_instance"] = internal.ResourceRegoPolicyInstance() + schemaMap["cyral_integration_aws_iam"] = awsiam.ResourceIntegrationAWSIAM() + schemaMap["cyral_integration_datadog"] = deprecated.ResourceIntegrationDatadog() + schemaMap["cyral_integration_mfa_duo"] = mfaduo.ResourceIntegrationMFADuo() + schemaMap["cyral_integration_elk"] = deprecated.ResourceIntegrationELK() + schemaMap["cyral_integration_hc_vault"] = hcvault.ResourceIntegrationHCVault() + schemaMap["cyral_integration_logstash"] = deprecated.ResourceIntegrationLogstash() + schemaMap["cyral_integration_looker"] = deprecated.ResourceIntegrationLooker() + schemaMap["cyral_integration_microsoft_teams"] = teams.ResourceIntegrationMsTeams() + schemaMap["cyral_integration_pager_duty"] = pagerduty.ResourceIntegrationPagerDuty() + schemaMap["cyral_integration_slack_alerts"] = slack.ResourceIntegrationSlackAlerts() + schemaMap["cyral_integration_splunk"] = deprecated.ResourceIntegrationSplunk() + schemaMap["cyral_integration_idp_aad"] = deprecated.ResourceIntegrationIdP("aad", idpDeprecationMessage) + schemaMap["cyral_integration_idp_adfs"] = deprecated.ResourceIntegrationIdP("adfs-2016", idpDeprecationMessage) + schemaMap["cyral_integration_idp_forgerock"] = deprecated.ResourceIntegrationIdP("forgerock", "") + schemaMap["cyral_integration_idp_gsuite"] = deprecated.ResourceIntegrationIdP("gsuite", idpDeprecationMessage) + schemaMap["cyral_integration_idp_okta"] = deprecated.ResourceIntegrationIdP("okta", idpDeprecationMessage) + schemaMap["cyral_integration_idp_ping_one"] = deprecated.ResourceIntegrationIdP("pingone", idpDeprecationMessage) + schemaMap["cyral_integration_idp_saml"] = idpsaml.ResourceIntegrationIdPSAML() + schemaMap["cyral_integration_idp_saml_draft"] = idpsaml.ResourceIntegrationIdPSAMLDraft() + schemaMap["cyral_integration_sumo_logic"] = deprecated.ResourceIntegrationSumoLogic() + schemaMap["cyral_integration_logging"] = logging.ResourceIntegrationLogging() + schemaMap["cyral_policy"] = policy.ResourcePolicy() + schemaMap["cyral_policy_rule"] = rule.ResourcePolicyRule() + schemaMap["cyral_rego_policy_instance"] = regopolicy.ResourceRegoPolicyInstance() schemaMap["cyral_repository"] = repository.ResourceRepository() schemaMap["cyral_repository_access_rules"] = accessrules.ResourceRepositoryAccessRules() schemaMap["cyral_repository_access_gateway"] = accessgateway.ResourceRepositoryAccessGateway() - schemaMap["cyral_repository_binding"] = bind.ResourceRepositoryBinding() - schemaMap["cyral_repository_conf_auth"] = auth.ResourceRepositoryConfAuth() - schemaMap["cyral_repository_conf_analysis"] = analysis.ResourceRepositoryConfAnalysis() + schemaMap["cyral_repository_binding"] = binding.ResourceRepositoryBinding() + schemaMap["cyral_repository_conf_auth"] = confauth.ResourceRepositoryConfAuth() + schemaMap["cyral_repository_conf_analysis"] = confanalysis.ResourceRepositoryConfAnalysis() schemaMap["cyral_repository_network_access_policy"] = network.ResourceRepositoryNetworkAccessPolicy() schemaMap["cyral_repository_user_account"] = useraccount.ResourceRepositoryUserAccount() - schemaMap["cyral_role"] = internal.ResourceRole() - schemaMap["cyral_role_sso_groups"] = internal.ResourceRoleSSOGroups() - schemaMap["cyral_service_account"] = internal.ResourceServiceAccount() + schemaMap["cyral_role"] = role.ResourceRole() + schemaMap["cyral_role_sso_groups"] = role.ResourceRoleSSOGroups() + schemaMap["cyral_service_account"] = serviceaccount.ResourceServiceAccount() schemaMap["cyral_sidecar"] = sidecar.ResourceSidecar() schemaMap["cyral_sidecar_credentials"] = credentials.ResourceSidecarCredentials() schemaMap["cyral_sidecar_listener"] = listener.ResourceSidecarListener() diff --git a/cyral/utils/utils.go b/cyral/utils/utils.go index f712d974..01243be3 100644 --- a/cyral/utils/utils.go +++ b/cyral/utils/utils.go @@ -210,3 +210,13 @@ func SetKeysAsNewComputedIfPlanHasChanges(resourceDiff *schema.ResourceDiff, key } } } + +func GetStrListFromSchemaField(d *schema.ResourceData, field string) []string { + strList := []string{} + + for _, v := range d.Get(field).([]interface{}) { + strList = append(strList, v.(string)) + } + + return strList +}