@@ -28,15 +28,79 @@ func dataSourceSecureConnectBundleURL() *schema.Resource {
2828 },
2929 // Optional inputs
3030 "datacenter_id" : {
31- Description : "The ID of the Astra datacenter. If omitted, only the primary datacenter will be used ." ,
31+ Description : "The ID of the Astra datacenter. If omitted, all bundles will be fetched ." ,
3232 Type : schema .TypeString ,
3333 Optional : true ,
3434 },
3535 // Computed
36- "url " : {
37- Description : "The temporary download url to the secure connect bundle zip file. " ,
38- Type : schema .TypeString ,
36+ "secure_bundles " : {
37+ Description : "A list of Secure Connect Bundle info " ,
38+ Type : schema .TypeList ,
3939 Computed : true ,
40+ Elem : & schema.Resource {
41+ Schema : map [string ]* schema.Schema {
42+ "datacenter_id" : {
43+ Description : "The ID of the Astra datacenter." ,
44+ Type : schema .TypeString ,
45+ Computed : true ,
46+ },
47+ "url" : {
48+ Description : "The temporary download url to the secure connect bundle zip file." ,
49+ Type : schema .TypeString ,
50+ Computed : true ,
51+ },
52+ "internal_url" : {
53+ Description : "The temporary internal download url to the secure connect bundle zip file." ,
54+ Type : schema .TypeString ,
55+ Computed : true ,
56+ },
57+ "migration_proxy_url" : {
58+ Description : "The temporary migration proxy url." ,
59+ Type : schema .TypeString ,
60+ Computed : true ,
61+ },
62+ "internal_migration_proxy_url" : {
63+ Description : "The temporary internal migration proxy url." ,
64+ Type : schema .TypeString ,
65+ Computed : true ,
66+ },
67+ "custom_domain_bundles" : {
68+ Description : "Bundles for custom domain." ,
69+ Type : schema .TypeList ,
70+ Computed : true ,
71+ Optional : true ,
72+ Elem : & schema.Resource {
73+ Schema : map [string ]* schema.Schema {
74+ "domain" : {
75+ Description : "Custom Domain." ,
76+ Type : schema .TypeString ,
77+ Computed : true ,
78+ },
79+ "url" : {
80+ Description : "The temporary download url to the secure connect bundle zip file. This one is for the Custom Domain" ,
81+ Type : schema .TypeString ,
82+ Computed : true ,
83+ },
84+ "api_fqdn" : {
85+ Description : "The FQDN for API requests" ,
86+ Type : schema .TypeString ,
87+ Computed : true ,
88+ },
89+ "cql_fqdn" : {
90+ Description : "The FQDN for CQL requests" ,
91+ Type : schema .TypeString ,
92+ Computed : true ,
93+ },
94+ "dashboard_fqdn" : {
95+ Description : "The FQDN for the Dashboard" ,
96+ Type : schema .TypeString ,
97+ Computed : true ,
98+ },
99+ },
100+ },
101+ },
102+ },
103+ },
40104 },
41105 },
42106 }
@@ -48,47 +112,78 @@ func dataSourceSecureConnectBundleURLRead(ctx context.Context, d *schema.Resourc
48112
49113 databaseID := d .Get ("database_id" ).(string )
50114 datacenterID := d .Get ("datacenter_id" ).(string )
115+ if datacenterID != "" {
116+ tflog .Debug (ctx , fmt .Sprintf ("Datacenter ID %s was specified, will filter later\n " , datacenterID ))
117+ }
51118
52- credsURL , err := getSecureConnectBundleURL (ctx , client , databaseID , datacenterID )
119+ creds , err := getSecureConnectBundles (ctx , client , databaseID )
53120 if err != nil {
54121 return diag .FromErr (err )
55122 }
56-
57- d .SetId (fmt .Sprintf ("%s/secure-connect-bundle/%s" , databaseID , keyFromStrings ([]string {credsURL .DownloadURL })))
58- d .Set ("url" , credsURL .DownloadURL )
123+ setSecureConnectBundleData (ctx , d , databaseID , datacenterID , creds )
59124 return nil
60125}
61126
62- func getSecureConnectBundleURL (ctx context.Context , client astra.ClientWithResponsesInterface , databaseID , datacenterID string ) (* astra.CredsURL , error ) {
63- var credsURL * astra.CredsURL
64-
65- // fetch dataceneters for the specified DB ID
66- datacenterResp , err := client .ListDatacentersWithResponse (ctx , databaseID , & astra.ListDatacentersParams {})
127+ func getSecureConnectBundles (ctx context.Context , client astra.ClientWithResponsesInterface , databaseID string ) ([]astra.CredsURL , error ) {
128+ // fetch all the download bundles
129+ allBool := true
130+ secureBundleParams := & astra.GenerateSecureBundleURLParams {
131+ All : & allBool ,
132+ }
133+ secureBundlesResp , err := client .GenerateSecureBundleURLWithResponse (ctx , databaseID , secureBundleParams )
67134 if err != nil {
68135 return nil , err
69136 }
70- if datacenterResp .StatusCode () > http .StatusOK {
71- return nil , fmt .Errorf ("Failed to retrieve datacenters for Database with ID: %s. Response code: %d, msg = %s" , databaseID , datacenterResp .StatusCode (), string (datacenterResp .Body ))
72- }
73-
74- // if no datacenter ID specified, then use the primary datacenter ID, should be <dbid-1>
75- if datacenterID == "" {
76- datacenterID = databaseID + "-1"
137+ if secureBundlesResp .StatusCode () > http .StatusOK {
138+ return nil , fmt .Errorf ("Failed to generate Secure Connect Bundle for Database ID %s. Response code: %d, msg = %s" , databaseID , secureBundlesResp .StatusCode (), string (secureBundlesResp .Body ))
77139 }
140+ return * secureBundlesResp .JSON200 , nil
141+ }
78142
79- // find the URL for the datacenter ID
80- for _ , dc := range * datacenterResp .JSON200 {
81- if datacenterID == * dc .Id {
82- return & astra.CredsURL {
83- DownloadURL : * dc .SecureBundleUrl ,
84- DownloadURLInternal : dc .SecureBundleInternalUrl ,
85- DownloadURLMigrationProxy : dc .SecureBundleMigrationProxyUrl ,
86- DownloadURLMigrationProxyInternal : dc .SecureBundleMigrationProxyInternalUrl ,
87- }, nil
143+ func setSecureConnectBundleData (ctx context.Context , d * schema.ResourceData , databaseID , datacenterID string , bundleData []astra.CredsURL ) error {
144+ bundles := make ([]map [string ]interface {}, 0 , len (bundleData ))
145+ downloadURLs := make ([]string , len (bundleData ))
146+ for _ , bundle := range (bundleData ) {
147+ // DevOps APi has a misspelling that they might fix
148+ var bundleDatacenter string
149+ if bundle .DatacenterID != nil {
150+ bundleDatacenter = * bundle .DatacenterID
151+ } else if bundle .DatcenterID != nil {
152+ bundleDatacenter = * bundle .DatcenterID
88153 }
154+ if datacenterID != "" && bundleDatacenter != datacenterID {
155+ // skip adding this one because it doesn't match
156+ tflog .Debug (ctx , fmt .Sprintf ("Skipping SCB info for non-matching DC: %s\n " , bundleDatacenter ))
157+ continue
158+ }
159+ bundleMap := map [string ]interface {}{
160+ "datacenter_id" : bundleDatacenter ,
161+ "url" : bundle .DownloadURL ,
162+ "internal_url" : bundle .DownloadURLInternal ,
163+ "migration_proxy_url" : bundle .DownloadURLMigrationProxy ,
164+ "internal_migration_proxy_url" : bundle .DownloadURLMigrationProxyInternal ,
165+ }
166+ downloadURLs = append (downloadURLs , bundleMap ["url" ].(string ))
167+ // see if the bundle has custom domain info
168+ if bundle .CustomDomainBundles != nil {
169+ customDomainBundleArray := * bundle .CustomDomainBundles
170+ customDomains := make ([]map [string ]interface {}, 0 , len (customDomainBundleArray ))
171+ for _ , customDomain := range (customDomainBundleArray ) {
172+ customDomainMap := map [string ]interface {}{
173+ "domain" : customDomain .Domain ,
174+ "url" : customDomain .DownloadURL ,
175+ "api_fqdn" : customDomain .ApiFQDN ,
176+ "cql_fqdn" : customDomain .CqlFQDN ,
177+ "dashboard_fqdn" : customDomain .DashboardFQDN ,
178+ }
179+ customDomains = append (customDomains , customDomainMap )
180+ }
181+ bundleMap ["custom_domain_bundles" ] = customDomains
182+ }
183+ bundles = append (bundles , bundleMap )
89184 }
90-
91- tflog . Error ( ctx , fmt .Sprintf ("Could not find Datacenter with ID: %s " , databaseID ))
92- return credsURL , nil
93- }
94-
185+ // set the ID using the Database ID and the download URLs
186+ d . SetId ( fmt .Sprintf ("%s/secure-connect-bundle/%s " , databaseID , keyFromStrings ( downloadURLs ) ))
187+ d . Set ( "secure_bundles" , bundles )
188+ return nil
189+ }
0 commit comments