@@ -12,6 +12,7 @@ import (
12
12
"html/template"
13
13
"net/http"
14
14
"net/url"
15
+ "strings"
15
16
"time"
16
17
)
17
18
@@ -84,9 +85,9 @@ type DeploymentStatusResponse struct {
84
85
85
86
// CreateDeployment creates the deployment with the specified configuration.
86
87
func (c * Client ) CreateDeployment (ctx context.Context , req CreateDeploymentRequest ) (* CreateDeploymentResponse , error ) {
87
- tpl , err := template . New ( "create_deployment_request" ). Parse ( createDeploymentRequestTemplate )
88
+ tpl , err := deploymentTemplateFactory ( req )
88
89
if err != nil {
89
- return nil , fmt . Errorf ( "unable to parse deployment creation template: %w" , err )
90
+ return nil , err
90
91
}
91
92
92
93
var buf bytes.Buffer
@@ -307,8 +308,32 @@ func overallStatus(statuses ...DeploymentStatus) DeploymentStatus {
307
308
return overallStatus
308
309
}
309
310
310
- // TODO: make work for cloud other than GCP
311
- const createDeploymentRequestTemplate = `
311
+ func deploymentTemplateFactory (req CreateDeploymentRequest ) (* template.Template , error ) {
312
+ regionParts := strings .Split (req .Region , "-" )
313
+ if len (regionParts ) < 2 {
314
+ return nil , fmt .Errorf ("unable to parse CSP out of region [%s]" , req .Region )
315
+ }
316
+
317
+ csp := regionParts [0 ]
318
+ var tplStr string
319
+ switch csp {
320
+ case "gcp" :
321
+ tplStr = createDeploymentRequestTemplateGCP
322
+ case "azure" :
323
+ tplStr = createDeploymentRequestTemplateAzure
324
+ default :
325
+ return nil , fmt .Errorf ("unsupported CSP [%s]" , csp )
326
+ }
327
+
328
+ tpl , err := template .New ("create_deployment_request" ).Parse (tplStr )
329
+ if err != nil {
330
+ return nil , fmt .Errorf ("unable to parse deployment creation template: %w" , err )
331
+ }
332
+
333
+ return tpl , nil
334
+ }
335
+
336
+ const createDeploymentRequestTemplateGCP = `
312
337
{
313
338
"resources": {
314
339
"integrations_server": [
@@ -410,3 +435,106 @@ const createDeploymentRequestTemplate = `
410
435
"system_owned": false
411
436
}
412
437
}`
438
+
439
+ const createDeploymentRequestTemplateAzure = `
440
+ {
441
+ "resources": {
442
+ "integrations_server": [
443
+ {
444
+ "elasticsearch_cluster_ref_id": "main-elasticsearch",
445
+ "region": "{{ .Region }}",
446
+ "plan": {
447
+ "cluster_topology": [
448
+ {
449
+ "instance_configuration_id": "azure.integrationsserver.fsv2.2",
450
+ "zone_count": 1,
451
+ "size": {
452
+ "resource": "memory",
453
+ "value": 1024
454
+ }
455
+ }
456
+ ],
457
+ "integrations_server": {
458
+ "version": "{{ .Version }}"
459
+ }
460
+ },
461
+ "ref_id": "main-integrations_server"
462
+ }
463
+ ],
464
+ "elasticsearch": [
465
+ {
466
+ "region": "{{ .Region }}",
467
+ "settings": {
468
+ "dedicated_masters_threshold": 6
469
+ },
470
+ "plan": {
471
+ "cluster_topology": [
472
+ {
473
+ "zone_count": 1,
474
+ "elasticsearch": {
475
+ "node_attributes": {
476
+ "data": "hot"
477
+ }
478
+ },
479
+ "instance_configuration_id": "azure.es.datahot.edsv4",
480
+ "node_roles": [
481
+ "master",
482
+ "ingest",
483
+ "transform",
484
+ "data_hot",
485
+ "remote_cluster_client",
486
+ "data_content"
487
+ ],
488
+ "id": "hot_content",
489
+ "size": {
490
+ "resource": "memory",
491
+ "value": 8192
492
+ }
493
+ }
494
+ ],
495
+ "elasticsearch": {
496
+ "version": "{{ .Version }}",
497
+ "enabled_built_in_plugins": []
498
+ },
499
+ "deployment_template": {
500
+ "id": "azure-storage-optimized-v2"
501
+ }
502
+ },
503
+ "ref_id": "main-elasticsearch"
504
+ }
505
+ ],
506
+ "enterprise_search": [],
507
+ "kibana": [
508
+ {
509
+ "elasticsearch_cluster_ref_id": "main-elasticsearch",
510
+ "region": "{{ .Region }}",
511
+ "plan": {
512
+ "cluster_topology": [
513
+ {
514
+ "instance_configuration_id": "azure.kibana.fsv2",
515
+ "zone_count": 1,
516
+ "size": {
517
+ "resource": "memory",
518
+ "value": 1024
519
+ }
520
+ }
521
+ ],
522
+ "kibana": {
523
+ "version": "{{ .Version }}",
524
+ "user_settings_json": {
525
+ "xpack.fleet.enableExperimental": ["agentTamperProtectionEnabled"]
526
+ }
527
+ }
528
+ },
529
+ "ref_id": "main-kibana"
530
+ }
531
+ ]
532
+ },
533
+ "settings": {
534
+ "autoscaling_enabled": false
535
+ },
536
+ "name": "{{ .Name }}",
537
+ "metadata": {
538
+ "system_owned": false
539
+ }
540
+ }`
0 commit comments