/
app_spec.go
846 lines (716 loc) · 22.4 KB
/
app_spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
package digitalocean
import (
"log"
"github.com/digitalocean/godo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)
func appSpecSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(2, 32),
Description: "The name of the app. Must be unique across all apps in the same account.",
},
"region": {
Type: schema.TypeString,
Optional: true,
Description: "The slug for the DigitalOcean data center region hosting the app",
},
"domains": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"service": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
Elem: appSpecServicesSchema(),
},
"static_site": {
Type: schema.TypeList,
Optional: true,
Elem: appSpecStaticSiteSchema(),
},
"worker": {
Type: schema.TypeList,
Optional: true,
Elem: appSpecWorkerSchema(),
},
"database": {
Type: schema.TypeList,
Optional: true,
Elem: appSpecDatabaseSchema(),
},
}
}
func appSpecGitSourceSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"repo_clone_url": {
Type: schema.TypeString,
Optional: true,
Description: "The clone URL of the repo.",
},
"branch": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the branch to use.",
},
}
}
func appSpecGitHubSourceSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"repo": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the repo in the format `owner/repo`.",
},
"branch": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the branch to use.",
},
"deploy_on_push": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to automatically deploy new commits made to the repo",
},
}
}
func appSpecEnvSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the environment variable.",
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: "The value of the environment variable.",
},
"scope": {
Type: schema.TypeString,
Optional: true,
Default: "RUN_AND_BUILD_TIME",
ValidateFunc: validation.StringInSlice([]string{
"UNSET",
"RUN_TIME",
"BUILD_TIME",
"RUN_AND_BUILD_TIME",
}, false),
Description: "The visibility scope of the environment variable.",
},
"type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"GENERAL",
"SECRET",
}, false),
Description: "The type of the environment variable.",
},
},
}
}
func appSpecRouteSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Optional: true,
Description: "Path specifies an route by HTTP path prefix. Paths must start with / and must be unique within the app.",
},
}
}
func appSpecHealthCheckSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"http_path": {
Type: schema.TypeString,
Optional: true,
Description: "The route path used for the HTTP health check ping.",
},
"initial_delay_seconds": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of seconds to wait before beginning health checks.",
},
"period_seconds": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of seconds to wait between health checks.",
},
"timeout_seconds": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of seconds after which the check times out.",
},
"success_threshold": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of successful health checks before considered healthy.",
},
"failure_threshold": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of failed health checks before considered unhealthy.",
},
}
}
func appSpecComponentBase() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the component",
},
"git": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: appSpecGitSourceSchema(),
},
},
"github": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: appSpecGitHubSourceSchema(),
},
},
"dockerfile_path": {
Type: schema.TypeString,
Optional: true,
Description: "The path to a Dockerfile relative to the root of the repo. If set, overrides usage of buildpacks.",
},
"build_command": {
Type: schema.TypeString,
Optional: true,
Description: "An optional build command to run while building this component from source.",
},
"env": {
Type: schema.TypeSet,
Optional: true,
Elem: appSpecEnvSchema(),
Set: schema.HashResource(appSpecEnvSchema()),
},
"routes": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: appSpecRouteSchema(),
},
},
"source_dir": {
Type: schema.TypeString,
Optional: true,
Description: "An optional path to the working directory to use for the build.",
},
"environment_slug": {
Type: schema.TypeString,
Optional: true,
Description: "An environment slug describing the type of this app.",
},
}
}
func appSpecServicesSchema() *schema.Resource {
serviceSchema := map[string]*schema.Schema{
"run_command": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "An optional run command to override the component's default.",
},
"http_port": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The internal port on which this service's run command will listen.",
},
"instance_size_slug": {
Type: schema.TypeString,
Optional: true,
Description: "The instance size to use for this component.",
},
"instance_count": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
Description: "The amount of instances that this component should be scaled to.",
},
"health_check": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: appSpecHealthCheckSchema(),
},
},
}
for k, v := range appSpecComponentBase() {
serviceSchema[k] = v
}
return &schema.Resource{
Schema: serviceSchema,
}
}
func appSpecStaticSiteSchema() *schema.Resource {
staticSiteSchema := map[string]*schema.Schema{
"output_dir": {
Type: schema.TypeString,
Optional: true,
Description: "An optional path to where the built assets will be located, relative to the build context. If not set, App Platform will automatically scan for these directory names: `_static`, `dist`, `public`.",
},
"index_document": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the index document to use when serving this static site.",
},
"error_document": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the error document to use when serving this static site.",
},
}
for k, v := range appSpecComponentBase() {
staticSiteSchema[k] = v
}
return &schema.Resource{
Schema: staticSiteSchema,
}
}
func appSpecWorkerSchema() *schema.Resource {
workerSchema := map[string]*schema.Schema{
"run_command": {
Type: schema.TypeString,
Optional: true,
Description: "An optional run command to override the component's default.",
},
"instance_size_slug": {
Type: schema.TypeString,
Optional: true,
Description: "The instance size to use for this component.",
},
"instance_count": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
Description: "The amount of instances that this component should be scaled to.",
},
}
for k, v := range appSpecComponentBase() {
workerSchema[k] = v
}
return &schema.Resource{
Schema: workerSchema,
}
}
func appSpecDatabaseSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the component",
},
"engine": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"UNSET",
"MYSQL",
"PG",
"REDIS",
}, false),
Description: "The database engine to use.",
},
"version": {
Type: schema.TypeString,
Optional: true,
Description: "The version of the database engine.",
},
"production": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether this is a production or dev database.",
},
"cluster_name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the underlying DigitalOcean DBaaS cluster. This is required for production databases. For dev databases, if cluster_name is not set, a new cluster will be provisioned.",
},
"db_name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the MySQL or PostgreSQL database to configure.",
},
"db_user": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the MySQL or PostgreSQL user to configure.",
},
},
}
}
func expandAppSpec(config []interface{}) *godo.AppSpec {
if len(config) == 0 || config[0] == nil {
return &godo.AppSpec{}
}
appSpecConfig := config[0].(map[string]interface{})
appSpec := &godo.AppSpec{
Name: appSpecConfig["name"].(string),
Region: appSpecConfig["region"].(string),
Domains: expandAppDomainSpec(appSpecConfig["domains"].(*schema.Set).List()),
Services: expandAppSpecServices(appSpecConfig["service"].([]interface{})),
StaticSites: expandAppSpecStaticSites(appSpecConfig["static_site"].([]interface{})),
Workers: expandAppSpecWorkers(appSpecConfig["worker"].([]interface{})),
Databases: expandAppSpecDatabases(appSpecConfig["database"].([]interface{})),
}
return appSpec
}
func flattenAppSpec(spec *godo.AppSpec) []map[string]interface{} {
result := make([]map[string]interface{}, 0, 1)
if spec != nil {
r := make(map[string]interface{})
r["name"] = (*spec).Name
r["region"] = (*spec).Region
r["domains"] = flattenAppDomainSpec((*spec).Domains)
if len((*spec).Services) > 0 {
r["service"] = flattenAppSpecServices((*spec).Services)
}
if len((*spec).StaticSites) > 0 {
r["static_site"] = flattenAppSpecStaticSites((*spec).StaticSites)
}
if len((*spec).Workers) > 0 {
r["worker"] = flattenAppSpecWorkers((*spec).Workers)
}
if len((*spec).Databases) > 0 {
r["database"] = flattenAppSpecDatabases((*spec).Databases)
}
result = append(result, r)
}
return result
}
func expandAppDomainSpec(config []interface{}) []*godo.AppDomainSpec {
appDomains := make([]*godo.AppDomainSpec, 0, len(config))
for _, rawDomain := range config {
domain := &godo.AppDomainSpec{
Domain: rawDomain.(string),
}
appDomains = append(appDomains, domain)
}
return appDomains
}
func flattenAppDomainSpec(spec []*godo.AppDomainSpec) *schema.Set {
result := schema.NewSet(schema.HashString, []interface{}{})
for _, domain := range spec {
result.Add(domain.Domain)
}
return result
}
func expandAppGitHubSourceSpec(config []interface{}) *godo.GitHubSourceSpec {
gitHubSourceConfig := config[0].(map[string]interface{})
gitHubSource := &godo.GitHubSourceSpec{
Repo: gitHubSourceConfig["repo"].(string),
Branch: gitHubSourceConfig["branch"].(string),
DeployOnPush: gitHubSourceConfig["deploy_on_push"].(bool),
}
return gitHubSource
}
func flattenAppGitHubSourceSpec(spec *godo.GitHubSourceSpec) []interface{} {
result := make([]interface{}, 0)
if spec != nil {
r := make(map[string]interface{})
r["repo"] = (*spec).Repo
r["branch"] = (*spec).Branch
r["deploy_on_push"] = (*spec).DeployOnPush
result = append(result, r)
}
return result
}
func expandAppGitSourceSpec(config []interface{}) *godo.GitSourceSpec {
gitSourceConfig := config[0].(map[string]interface{})
gitSource := &godo.GitSourceSpec{
Branch: gitSourceConfig["branch"].(string),
RepoCloneURL: gitSourceConfig["repo_clone_url"].(string),
}
return gitSource
}
func flattenAppGitSourceSpec(spec *godo.GitSourceSpec) []interface{} {
result := make([]interface{}, 0)
if spec != nil {
r := make(map[string]interface{})
r["branch"] = (*spec).Branch
r["repo_clone_url"] = (*spec).RepoCloneURL
result = append(result, r)
}
return result
}
func expandAppEnvs(config []interface{}) []*godo.AppVariableDefinition {
appEnvs := make([]*godo.AppVariableDefinition, 0, len(config))
for _, rawEnv := range config {
env := rawEnv.(map[string]interface{})
e := &godo.AppVariableDefinition{
Value: env["value"].(string),
Scope: godo.AppVariableScope(env["scope"].(string)),
Key: env["key"].(string),
Type: godo.AppVariableType(env["type"].(string)),
}
appEnvs = append(appEnvs, e)
}
return appEnvs
}
func flattenAppEnvs(appEnvs []*godo.AppVariableDefinition) *schema.Set {
result := schema.NewSet(schema.HashResource(appSpecEnvSchema()), []interface{}{})
for _, env := range appEnvs {
r := make(map[string]interface{})
r["value"] = env.Value
r["scope"] = string(env.Scope)
r["key"] = env.Key
r["type"] = string(env.Type)
result.Add(r)
setFunc := schema.HashResource(appSpecEnvSchema())
log.Printf("[DEBUG] App env hash for %s: %d", r["key"], setFunc(r))
}
return result
}
func expandAppHealthCheck(config []interface{}) *godo.AppServiceSpecHealthCheck {
healthCheckConfig := config[0].(map[string]interface{})
healthCheck := &godo.AppServiceSpecHealthCheck{
HTTPPath: healthCheckConfig["http_path"].(string),
InitialDelaySeconds: int32(healthCheckConfig["initial_delay_seconds"].(int)),
PeriodSeconds: int32(healthCheckConfig["period_seconds"].(int)),
TimeoutSeconds: int32(healthCheckConfig["timeout_seconds"].(int)),
SuccessThreshold: int32(healthCheckConfig["success_threshold"].(int)),
FailureThreshold: int32(healthCheckConfig["failure_threshold"].(int)),
}
return healthCheck
}
func flattenAppHealthCheck(check *godo.AppServiceSpecHealthCheck) []interface{} {
result := make([]interface{}, 0)
if check != nil {
r := make(map[string]interface{})
r["http_path"] = check.HTTPPath
r["initial_delay_seconds"] = check.InitialDelaySeconds
r["period_seconds"] = check.PeriodSeconds
r["timeout_seconds"] = check.TimeoutSeconds
r["success_threshold"] = check.SuccessThreshold
r["failure_threshold"] = check.FailureThreshold
result = append(result, r)
}
return result
}
func expandAppRoutes(config []interface{}) []*godo.AppRouteSpec {
appRoutes := make([]*godo.AppRouteSpec, 0, len(config))
for _, rawRoute := range config {
route := rawRoute.(map[string]interface{})
r := &godo.AppRouteSpec{
Path: route["path"].(string),
}
appRoutes = append(appRoutes, r)
}
return appRoutes
}
func flattenAppRoutes(routes []*godo.AppRouteSpec) []interface{} {
result := make([]interface{}, 0)
for _, route := range routes {
r := make(map[string]interface{})
r["path"] = route.Path
result = append(result, r)
}
return result
}
func expandAppSpecServices(config []interface{}) []*godo.AppServiceSpec {
appServices := make([]*godo.AppServiceSpec, 0, len(config))
for _, rawService := range config {
service := rawService.(map[string]interface{})
s := &godo.AppServiceSpec{
Name: service["name"].(string),
RunCommand: service["run_command"].(string),
BuildCommand: service["build_command"].(string),
HTTPPort: int64(service["http_port"].(int)),
DockerfilePath: service["dockerfile_path"].(string),
Envs: expandAppEnvs(service["env"].(*schema.Set).List()),
InstanceSizeSlug: service["instance_size_slug"].(string),
InstanceCount: int64(service["instance_count"].(int)),
SourceDir: service["source_dir"].(string),
EnvironmentSlug: service["environment_slug"].(string),
}
github := service["github"].([]interface{})
if len(github) > 0 {
s.GitHub = expandAppGitHubSourceSpec(github)
}
git := service["git"].([]interface{})
if len(git) > 0 {
s.Git = expandAppGitSourceSpec(git)
}
routes := service["routes"].([]interface{})
if len(routes) > 0 {
s.Routes = expandAppRoutes(routes)
}
checks := service["health_check"].([]interface{})
if len(checks) > 0 {
s.HealthCheck = expandAppHealthCheck(checks)
}
appServices = append(appServices, s)
}
return appServices
}
func flattenAppSpecServices(services []*godo.AppServiceSpec) []map[string]interface{} {
result := make([]map[string]interface{}, len(services))
for i, s := range services {
r := make(map[string]interface{})
r["name"] = s.Name
r["run_command"] = s.RunCommand
r["build_command"] = s.BuildCommand
r["github"] = flattenAppGitHubSourceSpec(s.GitHub)
r["git"] = flattenAppGitSourceSpec(s.Git)
r["http_port"] = int(s.HTTPPort)
r["routes"] = flattenAppRoutes(s.Routes)
r["dockerfile_path"] = s.DockerfilePath
r["env"] = flattenAppEnvs(s.Envs)
r["health_check"] = flattenAppHealthCheck(s.HealthCheck)
r["instance_size_slug"] = s.InstanceSizeSlug
r["instance_count"] = int(s.InstanceCount)
r["source_dir"] = s.SourceDir
r["environment_slug"] = s.EnvironmentSlug
result[i] = r
}
return result
}
func expandAppSpecStaticSites(config []interface{}) []*godo.AppStaticSiteSpec {
appSites := make([]*godo.AppStaticSiteSpec, 0, len(config))
for _, rawSite := range config {
site := rawSite.(map[string]interface{})
s := &godo.AppStaticSiteSpec{
Name: site["name"].(string),
BuildCommand: site["build_command"].(string),
DockerfilePath: site["dockerfile_path"].(string),
Envs: expandAppEnvs(site["env"].(*schema.Set).List()),
SourceDir: site["source_dir"].(string),
OutputDir: site["output_dir"].(string),
IndexDocument: site["index_document"].(string),
ErrorDocument: site["error_document"].(string),
EnvironmentSlug: site["environment_slug"].(string),
}
github := site["github"].([]interface{})
if len(github) > 0 {
s.GitHub = expandAppGitHubSourceSpec(github)
}
git := site["git"].([]interface{})
if len(git) > 0 {
s.Git = expandAppGitSourceSpec(git)
}
routes := site["routes"].([]interface{})
if len(routes) > 0 {
s.Routes = expandAppRoutes(routes)
}
appSites = append(appSites, s)
}
return appSites
}
func flattenAppSpecStaticSites(sites []*godo.AppStaticSiteSpec) []map[string]interface{} {
result := make([]map[string]interface{}, len(sites))
for i, s := range sites {
r := make(map[string]interface{})
r["name"] = s.Name
r["build_command"] = s.BuildCommand
r["github"] = flattenAppGitHubSourceSpec(s.GitHub)
r["git"] = flattenAppGitSourceSpec(s.Git)
r["routes"] = flattenAppRoutes(s.Routes)
r["dockerfile_path"] = s.DockerfilePath
r["env"] = flattenAppEnvs(s.Envs)
r["source_dir"] = s.SourceDir
r["output_dir"] = s.OutputDir
r["index_document"] = s.IndexDocument
r["error_document"] = s.ErrorDocument
r["environment_slug"] = s.EnvironmentSlug
result[i] = r
}
return result
}
func expandAppSpecWorkers(config []interface{}) []*godo.AppWorkerSpec {
appWorkers := make([]*godo.AppWorkerSpec, 0, len(config))
for _, rawWorker := range config {
worker := rawWorker.(map[string]interface{})
s := &godo.AppWorkerSpec{
Name: worker["name"].(string),
RunCommand: worker["run_command"].(string),
BuildCommand: worker["build_command"].(string),
DockerfilePath: worker["dockerfile_path"].(string),
Envs: expandAppEnvs(worker["env"].(*schema.Set).List()),
InstanceSizeSlug: worker["instance_size_slug"].(string),
InstanceCount: int64(worker["instance_count"].(int)),
SourceDir: worker["source_dir"].(string),
EnvironmentSlug: worker["environment_slug"].(string),
}
github := worker["github"].([]interface{})
if len(github) > 0 {
s.GitHub = expandAppGitHubSourceSpec(github)
}
git := worker["git"].([]interface{})
if len(git) > 0 {
s.Git = expandAppGitSourceSpec(git)
}
appWorkers = append(appWorkers, s)
}
return appWorkers
}
func flattenAppSpecWorkers(workers []*godo.AppWorkerSpec) []map[string]interface{} {
result := make([]map[string]interface{}, len(workers))
for i, w := range workers {
r := make(map[string]interface{})
r["name"] = w.Name
r["run_command"] = w.RunCommand
r["build_command"] = w.BuildCommand
r["github"] = flattenAppGitHubSourceSpec(w.GitHub)
r["git"] = flattenAppGitSourceSpec(w.Git)
r["dockerfile_path"] = w.DockerfilePath
r["env"] = flattenAppEnvs(w.Envs)
r["instance_size_slug"] = w.InstanceSizeSlug
r["instance_count"] = int(w.InstanceCount)
r["source_dir"] = w.SourceDir
r["environment_slug"] = w.EnvironmentSlug
result[i] = r
}
return result
}
func expandAppSpecDatabases(config []interface{}) []*godo.AppDatabaseSpec {
appDatabases := make([]*godo.AppDatabaseSpec, 0, len(config))
for _, rawDatabase := range config {
db := rawDatabase.(map[string]interface{})
s := &godo.AppDatabaseSpec{
Name: db["name"].(string),
Engine: godo.AppDatabaseSpecEngine(db["engine"].(string)),
Version: db["version"].(string),
Production: db["production"].(bool),
ClusterName: db["cluster_name"].(string),
DBName: db["db_name"].(string),
DBUser: db["db_user"].(string),
}
appDatabases = append(appDatabases, s)
}
return appDatabases
}
func flattenAppSpecDatabases(databases []*godo.AppDatabaseSpec) []map[string]interface{} {
result := make([]map[string]interface{}, len(databases))
for i, db := range databases {
r := make(map[string]interface{})
r["name"] = db.Name
r["engine"] = db.Engine
r["version"] = db.Version
r["production"] = db.Production
r["cluster_name"] = db.ClusterName
r["db_name"] = db.DBName
r["db_user"] = db.DBUser
result[i] = r
}
return result
}