-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_version_control_settings.go
78 lines (70 loc) · 2.93 KB
/
schema_version_control_settings.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
package octopusdeploy
import (
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func expandVersionControlSettings(flattenedVersionControlSettings interface{}) *octopusdeploy.VersionControlSettings {
versionControlSettingsList := flattenedVersionControlSettings.(*schema.Set).List()
versionControlSettingsMap := versionControlSettingsList[0].(map[string]interface{})
versionControlSettings := &octopusdeploy.VersionControlSettings{
BasePath: versionControlSettingsMap["base_path"].(string),
DefaultBranch: versionControlSettingsMap["default_branch"].(string),
HasValue: versionControlSettingsMap["has_value"].(bool),
URL: versionControlSettingsMap["url"].(string),
Username: versionControlSettingsMap["username"].(string),
}
if password := versionControlSettingsMap["password"].(string); len(password) > 0 {
versionControlSettings.Password = octopusdeploy.NewSensitiveValue(password)
}
return versionControlSettings
}
func flattenVersionControlSettings(versionControlSettings *octopusdeploy.VersionControlSettings) []interface{} {
if versionControlSettings == nil {
return nil
}
flattenedVersionControlSettings := make(map[string]interface{})
flattenedVersionControlSettings["base_path"] = versionControlSettings.BasePath
flattenedVersionControlSettings["default_branch"] = versionControlSettings.DefaultBranch
flattenedVersionControlSettings["has_value"] = versionControlSettings.HasValue
flattenedVersionControlSettings["url"] = versionControlSettings.URL
flattenedVersionControlSettings["username"] = versionControlSettings.Username
return []interface{}{flattenedVersionControlSettings}
}
func getVersionControlSettingsSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"base_path": {
Description: "The base path associated with these version control settings.",
Type: schema.TypeString,
Optional: true,
},
"default_branch": {
Description: "The default branch associated with these version control settings.",
Type: schema.TypeString,
Optional: true,
},
"has_value": {
Type: schema.TypeBool,
Optional: true,
},
"password": {
Description: "The password associated with these version control settings.",
Sensitive: true,
Optional: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotEmpty),
},
"url": {
Description: "The URL associated with these version control settings.",
Type: schema.TypeString,
Optional: true,
},
"username": {
Description: "The username associated with these version control settings.",
Optional: true,
Sensitive: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotEmpty),
},
}
}