forked from hashicorp/terraform-provider-azurerm
/
devtest.go
144 lines (123 loc) · 3.22 KB
/
devtest.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
package azure
import (
"github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func SchemaDevTestVirtualMachineInboundNatRule() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Optional: true,
// since these aren't returned from the API
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"protocol": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(dtl.TCP),
string(dtl.UDP),
}, false),
},
"backend_port": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validate.PortNumber,
},
"frontend_port": {
Type: schema.TypeInt,
Computed: true,
},
},
},
}
}
func ExpandDevTestLabVirtualMachineNatRules(input *schema.Set) []dtl.InboundNatRule {
rules := make([]dtl.InboundNatRule, 0)
if input == nil {
return rules
}
for _, val := range input.List() {
v := val.(map[string]interface{})
backendPort := v["backend_port"].(int)
protocol := v["protocol"].(string)
rule := dtl.InboundNatRule{
TransportProtocol: dtl.TransportProtocol(protocol),
BackendPort: utils.Int32(int32(backendPort)),
}
rules = append(rules, rule)
}
return rules
}
func ExpandDevTestLabVirtualMachineGalleryImageReference(input []interface{}, osType string) *dtl.GalleryImageReference {
if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})
offer := v["offer"].(string)
publisher := v["publisher"].(string)
sku := v["sku"].(string)
version := v["version"].(string)
return &dtl.GalleryImageReference{
Offer: utils.String(offer),
OsType: utils.String(osType),
Publisher: utils.String(publisher),
Sku: utils.String(sku),
Version: utils.String(version),
}
}
func SchemaDevTestVirtualMachineGalleryImageReference() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"offer": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"publisher": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"sku": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"version": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
}
}
func FlattenDevTestVirtualMachineGalleryImage(input *dtl.GalleryImageReference) []interface{} {
results := make([]interface{}, 0)
if input != nil {
output := make(map[string]interface{})
if input.Offer != nil {
output["offer"] = *input.Offer
}
if input.Publisher != nil {
output["publisher"] = *input.Publisher
}
if input.Sku != nil {
output["sku"] = *input.Sku
}
if input.Version != nil {
output["version"] = *input.Version
}
results = append(results, output)
}
return results
}