@@ -657,40 +657,52 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
657657 // NOTE(cjschaef): If one or more ServiceEndpoint's are supplied, attempt to build the Terraform endpoint_file_path
658658 // https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints#file-structure-for-endpoints-file
659659 var endpointsJSONFile string
660+ // Set Terraform visibility mode if necessary
661+ terraformPrivateVisibility := false
660662 if len (installConfig .Config .Platform .IBMCloud .ServiceEndpoints ) > 0 {
663+ // Determine if any endpoints require 'private' Terraform visibility mode (any contain 'private' or 'direct' for COS)
664+ // This is a requirement for the IBM Cloud Terraform provider, forcing 'public' or 'private' visibility mode.
665+ for _ , endpoint := range installConfig .Config .Platform .IBMCloud .ServiceEndpoints {
666+ if strings .Contains (endpoint .URL , "private" ) || strings .Contains (endpoint .URL , "direct" ) {
667+ // If at least one endpoint is private (or direct) we expect to use Private visibility mode
668+ terraformPrivateVisibility = true
669+ break
670+ }
671+ }
672+
661673 endpointData , err := ibmcloudtfvars .CreateEndpointJSON (installConfig .Config .Platform .IBMCloud .ServiceEndpoints , installConfig .Config .Platform .IBMCloud .Region )
662674 if err != nil {
663675 return err
664676 }
665- // While we should have already confirmed there are ServiceEndpoints, we can verify data did get created, requiring the JSON file gets created and passed along
666- if endpointData == nil {
667- return fmt .Errorf ("failed to generate endpoint JSON with provided IBM Cloud ServiceEndpoints" )
677+ // While service endpoints may not be empty, they may not be required for Terraform.
678+ // So, if we have not endpoint data, we don't need to generate the JSON override file.
679+ if endpointData != nil {
680+ // Add endpoint JSON data to list of generated files for Terraform
681+ t .FileList = append (t .FileList , & asset.File {
682+ Filename : ibmcloudtfvars .IBMCloudEndpointJSONFileName ,
683+ Data : endpointData ,
684+ })
685+ endpointsJSONFile = ibmcloudtfvars .IBMCloudEndpointJSONFileName
668686 }
669-
670- // Add endpoint JSON data to list of generated files for Terraform
671- t .FileList = append (t .FileList , & asset.File {
672- Filename : ibmcloudtfvars .IBMCloudEndpointJSONFileName ,
673- Data : endpointData ,
674- })
675- endpointsJSONFile = ibmcloudtfvars .IBMCloudEndpointJSONFileName
676687 }
677688
678689 data , err = ibmcloudtfvars .TFVars (
679690 ibmcloudtfvars.TFVarsSources {
680- Auth : auth ,
681- CISInstanceCRN : cisCRN ,
682- DNSInstanceID : dnsID ,
683- EndpointsJSONFile : endpointsJSONFile ,
684- ImageURL : string (* rhcosImage ),
685- MasterConfigs : masterConfigs ,
686- MasterDedicatedHosts : masterDedicatedHosts ,
687- NetworkResourceGroupName : installConfig .Config .Platform .IBMCloud .NetworkResourceGroupName ,
688- PreexistingVPC : preexistingVPC ,
689- PublishStrategy : installConfig .Config .Publish ,
690- ResourceGroupName : installConfig .Config .Platform .IBMCloud .ResourceGroupName ,
691- VPCPermitted : vpcPermitted ,
692- WorkerConfigs : workerConfigs ,
693- WorkerDedicatedHosts : workerDedicatedHosts ,
691+ Auth : auth ,
692+ CISInstanceCRN : cisCRN ,
693+ DNSInstanceID : dnsID ,
694+ EndpointsJSONFile : endpointsJSONFile ,
695+ ImageURL : string (* rhcosImage ),
696+ MasterConfigs : masterConfigs ,
697+ MasterDedicatedHosts : masterDedicatedHosts ,
698+ NetworkResourceGroupName : installConfig .Config .Platform .IBMCloud .NetworkResourceGroupName ,
699+ PreexistingVPC : preexistingVPC ,
700+ PublishStrategy : installConfig .Config .Publish ,
701+ ResourceGroupName : installConfig .Config .Platform .IBMCloud .ResourceGroupName ,
702+ TerraformPrivateVisibility : terraformPrivateVisibility ,
703+ VPCPermitted : vpcPermitted ,
704+ WorkerConfigs : workerConfigs ,
705+ WorkerDedicatedHosts : workerDedicatedHosts ,
694706 },
695707 )
696708 if err != nil {
0 commit comments