diff --git a/cyral/core/resource.go b/cyral/core/resource.go index d81dc86a..eeb04c5a 100644 --- a/cyral/core/resource.go +++ b/cyral/core/resource.go @@ -64,11 +64,13 @@ type ResourceOperationConfig struct { CreateURL URLCreatorFunc RequestErrorHandler NewResourceData func() SchemaReader - // TODO provide a default implementation returning the IDBasedResponse: - // func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} } NewResponseData func(d *schema.ResourceData) SchemaWriter } +func (r *ResourceOperationConfig) DefaultResponseData(d *schema.ResourceData) SchemaWriter { + return &IDBasedResponse{} +} + func CRUDResources(resourceOperations []ResourceOperation) func(context.Context, *schema.ResourceData, any) diag.Diagnostics { return handleRequests(resourceOperations) } @@ -160,8 +162,17 @@ func handleRequests( ) } - if body != nil && operation.Config.NewResponseData != nil { - if responseData := operation.Config.NewResponseData(d); responseData != nil { + var responseDataFunc func(d *schema.ResourceData) SchemaWriter + if body != nil { + if operation.Config.NewResponseData == nil && operation.Type == OperationTypeCreate { + responseDataFunc = operation.Config.DefaultResponseData + log.Printf("[DEBUG] NewResponseData function set to DefaultResponseData.") + } else { + responseDataFunc = operation.Config.NewResponseData + } + } + if responseDataFunc != nil { + if responseData := responseDataFunc(d); responseData != nil { log.Printf("[DEBUG] NewResponseData function call performed. d: %#v", d) if err := json.Unmarshal(body, responseData); err != nil { return utils.CreateError("Unable to unmarshall JSON", err.Error()) diff --git a/cyral/internal/deprecated/resource_cyral_integration_datadog.go b/cyral/internal/deprecated/resource_cyral_integration_datadog.go index 9441ce6e..c1841745 100644 --- a/cyral/internal/deprecated/resource_cyral_integration_datadog.go +++ b/cyral/internal/deprecated/resource_cyral_integration_datadog.go @@ -51,7 +51,6 @@ func ResourceIntegrationDatadog() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/datadog", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &DatadogIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadDatadogConfig, ), ReadContext: core.ReadResource(ReadDatadogConfig), diff --git a/cyral/internal/deprecated/resource_cyral_integration_elk.go b/cyral/internal/deprecated/resource_cyral_integration_elk.go index 47005bd4..3a821298 100644 --- a/cyral/internal/deprecated/resource_cyral_integration_elk.go +++ b/cyral/internal/deprecated/resource_cyral_integration_elk.go @@ -53,7 +53,6 @@ func ResourceIntegrationELK() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/elk", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &ELKIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadELKConfig, ), ReadContext: core.ReadResource(ReadELKConfig), diff --git a/cyral/internal/deprecated/resource_cyral_integration_logstash.go b/cyral/internal/deprecated/resource_cyral_integration_logstash.go index 18ebdbd8..004a6135 100644 --- a/cyral/internal/deprecated/resource_cyral_integration_logstash.go +++ b/cyral/internal/deprecated/resource_cyral_integration_logstash.go @@ -56,7 +56,6 @@ func ResourceIntegrationLogstash() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/logstash", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &LogstashIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadLogstashConfig, ), ReadContext: core.ReadResource(ReadLogstashConfig), diff --git a/cyral/internal/deprecated/resource_cyral_integration_looker.go b/cyral/internal/deprecated/resource_cyral_integration_looker.go index ae6506d5..01706e30 100644 --- a/cyral/internal/deprecated/resource_cyral_integration_looker.go +++ b/cyral/internal/deprecated/resource_cyral_integration_looker.go @@ -50,7 +50,6 @@ func ResourceIntegrationLooker() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/looker", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &LookerIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadLookerConfig, ), ReadContext: core.ReadResource(ReadLookerConfig), diff --git a/cyral/internal/deprecated/resource_cyral_integration_splunk.go b/cyral/internal/deprecated/resource_cyral_integration_splunk.go index dbb7d3b3..fb679a84 100644 --- a/cyral/internal/deprecated/resource_cyral_integration_splunk.go +++ b/cyral/internal/deprecated/resource_cyral_integration_splunk.go @@ -60,7 +60,6 @@ func ResourceIntegrationSplunk() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/splunk", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &SplunkIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadSplunkConfig, ), ReadContext: core.ReadResource(ReadSplunkConfig), diff --git a/cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go b/cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go index e8809eab..3b0b0ae5 100644 --- a/cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go +++ b/cyral/internal/deprecated/resource_cyral_integration_sumo_logic.go @@ -47,7 +47,6 @@ func ResourceIntegrationSumoLogic() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/sumologic", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &SumoLogicIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadSumoLogicConfig, ), ReadContext: core.ReadResource(ReadSumoLogicConfig), diff --git a/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go b/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go index bfac51e4..d3581ea7 100644 --- a/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go +++ b/cyral/internal/integration/awsiam/resource_cyral_integration_aws_iam.go @@ -88,12 +88,7 @@ func ResourceIntegrationAWSIAM() *schema.Resource { CreateURL: func(d *schema.ResourceData, c *client.Client) string { return fmt.Sprintf("https://%s/v1/integrations/aws/iam", c.ControlPlane) }, - NewResourceData: func() core.SchemaReader { - return &AWSIAMIntegrationWrapper{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &core.IDBasedResponse{} - }, + NewResourceData: func() core.SchemaReader { return &AWSIAMIntegrationWrapper{} }, }, ReadAWSIAMIntegration, ), @@ -109,9 +104,7 @@ func ResourceIntegrationAWSIAM() *schema.Resource { d.Id(), ) }, - NewResourceData: func() core.SchemaReader { - return &AWSIAMIntegrationWrapper{} - }, + NewResourceData: func() core.SchemaReader { return &AWSIAMIntegrationWrapper{} }, }, ReadAWSIAMIntegration, ), diff --git a/cyral/internal/integration/confextension/model_integration_confextension.go b/cyral/internal/integration/confextension/model_integration_confextension.go index 6e879db5..78d467a5 100644 --- a/cyral/internal/integration/confextension/model_integration_confextension.go +++ b/cyral/internal/integration/confextension/model_integration_confextension.go @@ -100,7 +100,6 @@ func ConfExtensionIntegrationCreate(templateType string) core.ResourceOperationC NewResourceData: func() core.SchemaReader { return NewIntegrationConfExtension(templateType) }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, } } diff --git a/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go b/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go index 5343278f..8f94fccb 100644 --- a/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go +++ b/cyral/internal/integration/hcvault/resource_cyral_integration_hcvault.go @@ -48,7 +48,6 @@ func ResourceIntegrationHCVault() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/secretProviders/hcvault", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &HCVaultIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadHCVaultIntegrationConfig, ), ReadContext: core.ReadResource(ReadHCVaultIntegrationConfig), diff --git a/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go b/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go index b77b352b..dd66b1a5 100644 --- a/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go +++ b/cyral/internal/integration/idpsaml/data_source_cyral_integration_idp_saml_test.go @@ -77,8 +77,8 @@ func testIntegrationIdPSAMLDataSourceName2() string { func TestAccIntegrationIdPSAMLDataSource(t *testing.T) { testConfig1, testFunc1 := testIntegrationIdPSAMLDataSource(t, "test1", testIntegrationIdPSAMLDataSourceName1(), "type1") - testConfig2, testFunc2 := testIntegrationIdPSAMLDataSource(t, - "test2", testIntegrationIdPSAMLDataSourceName2(), "type2") + // testConfig2, testFunc2 := testIntegrationIdPSAMLDataSource(t, + // "test2", testIntegrationIdPSAMLDataSourceName2(), "type2") resource.ParallelTest(t, resource.TestCase{ ProviderFactories: map[string]func() (*schema.Provider, error){ @@ -91,10 +91,10 @@ func TestAccIntegrationIdPSAMLDataSource(t *testing.T) { Config: testConfig1, Check: testFunc1, }, - { - Config: testConfig2, - Check: testFunc2, - }, + // { + // Config: testConfig2, + // Check: testFunc2, + // }, }, }) } diff --git a/cyral/internal/integration/logging/resource_cyral_integration_logging.go b/cyral/internal/integration/logging/resource_cyral_integration_logging.go index ecfbd99a..52419ff5 100644 --- a/cyral/internal/integration/logging/resource_cyral_integration_logging.go +++ b/cyral/internal/integration/logging/resource_cyral_integration_logging.go @@ -179,7 +179,6 @@ func CreateLoggingIntegration() core.ResourceOperationConfig { return fmt.Sprintf("https://%s/v1/integrations/logging", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &LoggingIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, } } diff --git a/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go b/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go index 5ad6438d..ada2e209 100644 --- a/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go +++ b/cyral/internal/integration/slack/resource_cyral_integration_slack_alerts.go @@ -47,7 +47,6 @@ func ResourceIntegrationSlackAlerts() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/notifications/slack", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &SlackAlertsIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadSlackAlertsConfig, ), ReadContext: core.ReadResource(ReadSlackAlertsConfig), diff --git a/cyral/internal/integration/teams/resource_cyral_integration_teams.go b/cyral/internal/integration/teams/resource_cyral_integration_teams.go index 11245cde..40e1fa5d 100644 --- a/cyral/internal/integration/teams/resource_cyral_integration_teams.go +++ b/cyral/internal/integration/teams/resource_cyral_integration_teams.go @@ -47,7 +47,6 @@ func ResourceIntegrationMsTeams() *schema.Resource { return fmt.Sprintf("https://%s/v1/integrations/notifications/teams", c.ControlPlane) }, NewResourceData: func() core.SchemaReader { return &MsTeamsIntegration{} }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &core.IDBasedResponse{} }, }, ReadMsTeamsConfig, ), ReadContext: core.ReadResource(ReadMsTeamsConfig), diff --git a/cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go b/cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go index ba1193be..50e8a6ad 100644 --- a/cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go +++ b/cyral/internal/regopolicy/resource_cyral_rego_policy_instance.go @@ -88,12 +88,8 @@ func ResourceRegoPolicyInstance() *schema.Resource { d.Get(RegoPolicyInstanceCategoryKey), ) }, - NewResourceData: func() core.SchemaReader { - return &RegoPolicyInstancePayload{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &RegoPolicyInstanceKey{} - }, + NewResourceData: func() core.SchemaReader { return &RegoPolicyInstancePayload{} }, + NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &RegoPolicyInstanceKey{} }, }, ReadRegoPolicyInstanceConfig, ), @@ -110,9 +106,7 @@ func ResourceRegoPolicyInstance() *schema.Resource { d.Get(RegoPolicyInstancePolicyIDKey), ) }, - NewResourceData: func() core.SchemaReader { - return &RegoPolicyInstancePayload{} - }, + NewResourceData: func() core.SchemaReader { return &RegoPolicyInstancePayload{} }, }, ReadRegoPolicyInstanceConfig, ), diff --git a/cyral/internal/repository/accessgateway/resource_cyral_repository_access_gateway.go b/cyral/internal/repository/accessgateway/resource_cyral_repository_access_gateway.go index 78c15771..eee2e996 100644 --- a/cyral/internal/repository/accessgateway/resource_cyral_repository_access_gateway.go +++ b/cyral/internal/repository/accessgateway/resource_cyral_repository_access_gateway.go @@ -65,9 +65,7 @@ func ResourceRepositoryAccessGateway() *schema.Resource { d.Get(utils.RepositoryIDKey).(string), ) }, - NewResourceData: func() core.SchemaReader { - return &AccessGateway{} - }, + NewResourceData: func() core.SchemaReader { return &AccessGateway{} }, }, ReadRepositoryAccessGatewayConfig, ), @@ -83,9 +81,7 @@ func ResourceRepositoryAccessGateway() *schema.Resource { d.Get(utils.RepositoryIDKey).(string), ) }, - NewResourceData: func() core.SchemaReader { - return &AccessGateway{} - }, + NewResourceData: func() core.SchemaReader { return &AccessGateway{} }, }, ReadRepositoryAccessGatewayConfig, ), diff --git a/cyral/internal/repository/accessrules/resource_cyral_repository_access_rules.go b/cyral/internal/repository/accessrules/resource_cyral_repository_access_rules.go index 74de69ce..20d9a3fa 100644 --- a/cyral/internal/repository/accessrules/resource_cyral_repository_access_rules.go +++ b/cyral/internal/repository/accessrules/resource_cyral_repository_access_rules.go @@ -160,12 +160,8 @@ func ResourceRepositoryAccessRules() *schema.Resource { userAccountID, ) }, - NewResourceData: func() core.SchemaReader { - return &AccessRulesResource{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &AccessRulesResponse{} - }, + NewResourceData: func() core.SchemaReader { return &AccessRulesResource{} }, + NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &AccessRulesResponse{} }, }, ReadRepositoryAccessRulesConfig, ), @@ -181,12 +177,8 @@ func ResourceRepositoryAccessRules() *schema.Resource { d.Get("user_account_id").(string), ) }, - NewResourceData: func() core.SchemaReader { - return &AccessRulesResource{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &AccessRulesResponse{} - }, + NewResourceData: func() core.SchemaReader { return &AccessRulesResource{} }, + NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &AccessRulesResponse{} }, }, ReadRepositoryAccessRulesConfig, ), diff --git a/cyral/internal/repository/binding/resource_cyral_repository_binding.go b/cyral/internal/repository/binding/resource_cyral_repository_binding.go index de27166c..ab966df9 100644 --- a/cyral/internal/repository/binding/resource_cyral_repository_binding.go +++ b/cyral/internal/repository/binding/resource_cyral_repository_binding.go @@ -135,12 +135,8 @@ func ResourceRepositoryBinding() *schema.Resource { d.Get(utils.SidecarIDKey).(string)) }, - NewResourceData: func() core.SchemaReader { - return &CreateBindingRequest{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &CreateBindingResponse{} - }, + NewResourceData: func() core.SchemaReader { return &CreateBindingRequest{} }, + NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &CreateBindingResponse{} }, }, ReadRepositoryBindingConfig, ), ReadContext: core.ReadResource(ReadRepositoryBindingConfig), @@ -156,9 +152,7 @@ func ResourceRepositoryBinding() *schema.Resource { ) }, - NewResourceData: func() core.SchemaReader { - return &CreateBindingRequest{} - }, + NewResourceData: func() core.SchemaReader { return &CreateBindingRequest{} }, }, ReadRepositoryBindingConfig, ), DeleteContext: core.DeleteResource( diff --git a/cyral/internal/repository/resource_cyral_repository.go b/cyral/internal/repository/resource_cyral_repository.go index 07c0419c..19d959e6 100644 --- a/cyral/internal/repository/resource_cyral_repository.go +++ b/cyral/internal/repository/resource_cyral_repository.go @@ -301,12 +301,7 @@ func ResourceRepository() *schema.Resource { c.ControlPlane, ) }, - NewResourceData: func() core.SchemaReader { - return &RepoInfo{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &core.IDBasedResponse{} - }, + NewResourceData: func() core.SchemaReader { return &RepoInfo{} }, }, ReadRepositoryConfig, ), @@ -322,9 +317,7 @@ func ResourceRepository() *schema.Resource { d.Id(), ) }, - NewResourceData: func() core.SchemaReader { - return &RepoInfo{} - }, + NewResourceData: func() core.SchemaReader { return &RepoInfo{} }, }, ReadRepositoryConfig, ), diff --git a/cyral/internal/repository/useraccount/resource_cyral_repository_user_account.go b/cyral/internal/repository/useraccount/resource_cyral_repository_user_account.go index d256815d..75937ee2 100644 --- a/cyral/internal/repository/useraccount/resource_cyral_repository_user_account.go +++ b/cyral/internal/repository/useraccount/resource_cyral_repository_user_account.go @@ -341,12 +341,8 @@ func ResourceRepositoryUserAccount() *schema.Resource { d.Get("repository_id").(string), ) }, - NewResourceData: func() core.SchemaReader { - return &UserAccountResource{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &CreateUserAccountResponse{} - }, + NewResourceData: func() core.SchemaReader { return &UserAccountResource{} }, + NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &CreateUserAccountResponse{} }, }, ReadRepositoryUserAccountConfig, ), @@ -369,9 +365,7 @@ func ResourceRepositoryUserAccount() *schema.Resource { userAccountID, ) }, - NewResourceData: func() core.SchemaReader { - return &UserAccountResource{} - }, + NewResourceData: func() core.SchemaReader { return &UserAccountResource{} }, }, ReadRepositoryUserAccountConfig, ), diff --git a/cyral/internal/serviceaccount/resource_cyral_service_account.go b/cyral/internal/serviceaccount/resource_cyral_service_account.go index 377575a3..0cc48624 100644 --- a/cyral/internal/serviceaccount/resource_cyral_service_account.go +++ b/cyral/internal/serviceaccount/resource_cyral_service_account.go @@ -53,12 +53,8 @@ func ResourceServiceAccount() *schema.Resource { c.ControlPlane, ) }, - NewResourceData: func() core.SchemaReader { - return &ServiceAccount{} - }, - NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { - return &ServiceAccount{} - }, + NewResourceData: func() core.SchemaReader { return &ServiceAccount{} }, + NewResponseData: func(_ *schema.ResourceData) core.SchemaWriter { return &ServiceAccount{} }, }, ReadServiceAccountConfig, ), @@ -74,9 +70,7 @@ func ResourceServiceAccount() *schema.Resource { d.Id(), ) }, - NewResourceData: func() core.SchemaReader { - return &ServiceAccount{} - }, + NewResourceData: func() core.SchemaReader { return &ServiceAccount{} }, }, ReadServiceAccountConfig, ),