generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 40
/
infra_tanzu.go
74 lines (59 loc) · 1.8 KB
/
infra_tanzu.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
package environment
import (
"github.com/harness/harness-go-sdk/harness/cd/cac"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func infraDetailsTanzu() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"cloud_provider_name": {
Description: "The name of the cloud provider to connect with.",
Type: schema.TypeString,
Required: true,
},
"organization": {
Description: "The PCF organization to use.",
Type: schema.TypeString,
Required: true,
},
"space": {
Description: "The PCF space to deploy to.",
Type: schema.TypeString,
Required: true,
},
},
}
}
func expandTanzuConfiguration(d []interface{}, infraDef *cac.InfrastructureDefinition) {
if len(d) == 0 {
return
}
config := d[0].(map[string]interface{})
details := &cac.InfrastructureTanzu{}
if attr := config["cloud_provider_name"]; attr != "" {
details.CloudProviderName = attr.(string)
}
if attr := config["organization"]; attr != nil {
details.Organization = attr.(string)
}
if attr := config["space"]; attr != nil {
details.Space = attr.(string)
}
infraDef.InfrastructureDetail = details.ToInfrastructureDetail()
}
func flattenTanzuConfiguration(d *schema.ResourceData, infraDef *cac.InfrastructureDefinition) []interface{} {
results := []interface{}{}
if len(infraDef.InfrastructureDetail) == 0 {
return results
}
detail := infraDef.InfrastructureDetail[0]
if detail.Type != cac.InfrastructureTypes.Pcf {
return results
}
detailConfig := map[string]interface{}{}
infraDetail := detail.ToPcf()
detailConfig["cloud_provider_name"] = infraDetail.CloudProviderName
detailConfig["organization"] = infraDetail.Organization
detailConfig["space"] = infraDetail.Space
return append(results, detailConfig)
}