@@ -29,10 +29,9 @@ import (
2929
3030// Ensure the implementation satisfies the expected interfaces.
3131var (
32- _ resource.Resource = & cloudSecurityGroupResource {}
33- _ resource.ResourceWithConfigure = & cloudSecurityGroupResource {}
34- _ resource.ResourceWithImportState = & cloudSecurityGroupResource {}
35- _ resource.ResourceWithValidateConfig = & cloudSecurityGroupResource {}
32+ _ resource.Resource = & cloudSecurityGroupResource {}
33+ _ resource.ResourceWithConfigure = & cloudSecurityGroupResource {}
34+ _ resource.ResourceWithImportState = & cloudSecurityGroupResource {}
3635)
3736
3837// cloudSecurityGroupScopes defines the required API scopes for Cloud Security Groups.
@@ -346,46 +345,6 @@ func (r *cloudSecurityGroupResource) Configure(
346345 r .client = client
347346}
348347
349- // ValidateConfig validates the resource configuration.
350- func (r * cloudSecurityGroupResource ) ValidateConfig (
351- ctx context.Context ,
352- req resource.ValidateConfigRequest ,
353- resp * resource.ValidateConfigResponse ,
354- ) {
355- var config cloudSecurityGroupResourceModel
356- resp .Diagnostics .Append (req .Config .Get (ctx , & config )... )
357- if resp .Diagnostics .HasError () {
358- return
359- }
360-
361- // Validate that GCP configuration does not use tags filter
362- if ! config .GCP .IsNull () && ! config .GCP .IsUnknown () {
363- var gcpConfig cloudProviderConfigModel
364- resp .Diagnostics .Append (config .GCP .As (ctx , & gcpConfig , basetypes.ObjectAsOptions {})... )
365- if resp .Diagnostics .HasError () {
366- return
367- }
368-
369- if ! gcpConfig .Filters .IsNull () && ! gcpConfig .Filters .IsUnknown () {
370- // Extract filters attributes to check for tags
371- filterValues := gcpConfig .Filters .Attributes ()
372-
373- // Check if tags field exists and has values
374- if tagsValue , ok := filterValues ["tags" ]; ok && ! tagsValue .IsNull () {
375- var tags []string
376- resp .Diagnostics .Append (tagsValue .(types.List ).ElementsAs (ctx , & tags , false )... )
377- if len (tags ) > 0 {
378- resp .Diagnostics .AddAttributeError (
379- path .Root ("gcp" ).AtName ("filters" ).AtName ("tags" ),
380- "Invalid Configuration" ,
381- "GCP cloud resources do not support tag filtering. Remove the tags filter from the GCP configuration." ,
382- )
383- }
384- }
385- }
386- }
387- }
388-
389348// Create creates the resource and sets the initial Terraform state.
390349func (r * cloudSecurityGroupResource ) Create (
391350 ctx context.Context ,
@@ -772,15 +731,31 @@ func (r *cloudSecurityGroupResource) convertSelectorsToAPI(
772731 // Extract region if present
773732 if regionValue , ok := filterValues ["region" ]; ok && ! regionValue .IsNull () {
774733 var regions []string
775- diags .Append (regionValue .(types.List ).ElementsAs (ctx , & regions , false )... )
734+ regionList , ok := regionValue .(types.List )
735+ if ! ok {
736+ diags .AddError (
737+ "Invalid Type" ,
738+ "Expected region to be a list type." ,
739+ )
740+ return nil , diags
741+ }
742+ diags .Append (regionList .ElementsAs (ctx , & regions , false )... )
776743 apiFilters .Region = regions
777744 }
778745
779746 // Extract tags if present and includeTags is true
780747 if includeTags {
781748 if tagsValue , ok := filterValues ["tags" ]; ok && ! tagsValue .IsNull () {
782749 var tags []string
783- diags .Append (tagsValue .(types.List ).ElementsAs (ctx , & tags , false )... )
750+ tagsList , ok := tagsValue .(types.List )
751+ if ! ok {
752+ diags .AddError (
753+ "Invalid Type" ,
754+ "Expected tags to be a list type." ,
755+ )
756+ return nil , diags
757+ }
758+ diags .Append (tagsList .ElementsAs (ctx , & tags , false )... )
784759 apiFilters .Tags = tags
785760 }
786761 }
0 commit comments