-
Notifications
You must be signed in to change notification settings - Fork 67
/
schema_nuget_feed.go
105 lines (89 loc) · 3.23 KB
/
schema_nuget_feed.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
package octopusdeploy
import (
"context"
"fmt"
"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 expandNuGetFeed(d *schema.ResourceData) *octopusdeploy.NuGetFeed {
name := d.Get("name").(string)
feedURI := d.Get("feed_uri").(string)
nuGetFeed := octopusdeploy.NewNuGetFeed(name, feedURI)
nuGetFeed.ID = d.Id()
if v, ok := d.GetOk("download_attempts"); ok {
nuGetFeed.DownloadAttempts = v.(int)
}
if v, ok := d.GetOk("download_retry_backoff_seconds"); ok {
nuGetFeed.DownloadRetryBackoffSeconds = v.(int)
}
if v, ok := d.GetOk("is_enhanced_mode"); ok {
nuGetFeed.EnhancedMode = v.(bool)
}
if v, ok := d.GetOk("package_acquisition_location_options"); ok {
nuGetFeed.PackageAcquisitionLocationOptions = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("password"); ok {
nuGetFeed.Password = octopusdeploy.NewSensitiveValue(v.(string))
}
if v, ok := d.GetOk("username"); ok {
nuGetFeed.Username = v.(string)
}
return nuGetFeed
}
func getNuGetFeedSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"download_attempts": {
Default: 5,
Description: "The number of times a deployment should attempt to download a package from this feed before failing.",
Optional: true,
Type: schema.TypeInt,
},
"download_retry_backoff_seconds": {
Default: 10,
Description: "The number of seconds to apply as a linear back off between download attempts.",
Optional: true,
Type: schema.TypeInt,
},
"feed_uri": {
Description: "The feed URI can be a URL or a folder path.",
Required: true,
Type: schema.TypeString,
},
"id": getIDSchema(),
"is_enhanced_mode": {
Default: true,
Description: "This will improve performance of the NuGet feed but may not be supported by some older feeds. Disable if the operation, Create Release does not return the latest version for a package.",
Optional: true,
Type: schema.TypeBool,
},
"name": {
Description: "A short, memorable, unique name for this feed. Example: ACME Builds.",
Required: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotEmpty),
},
"package_acquisition_location_options": {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Type: schema.TypeList,
},
"password": getPasswordSchema(false),
"space_id": getSpaceIDSchema(),
"username": getUsernameSchema(false),
}
}
func setNuGetFeed(ctx context.Context, d *schema.ResourceData, nuGetFeed *octopusdeploy.NuGetFeed) error {
d.Set("download_attempts", nuGetFeed.DownloadAttempts)
d.Set("download_retry_backoff_seconds", nuGetFeed.DownloadRetryBackoffSeconds)
d.Set("feed_uri", nuGetFeed.FeedURI)
d.Set("is_enhanced_mode", nuGetFeed.EnhancedMode)
d.Set("name", nuGetFeed.Name)
d.Set("username", nuGetFeed.Username)
if err := d.Set("package_acquisition_location_options", nuGetFeed.PackageAcquisitionLocationOptions); err != nil {
return fmt.Errorf("error setting package_acquisition_location_options: %s", err)
}
d.SetId(nuGetFeed.GetID())
return nil
}