-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_helm_feed.go
75 lines (61 loc) · 2.02 KB
/
schema_helm_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
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 expandHelmFeed(d *schema.ResourceData) *octopusdeploy.HelmFeed {
name := d.Get("name").(string)
var helmFeed = octopusdeploy.NewHelmFeed(name)
helmFeed.ID = d.Id()
if v, ok := d.GetOk("feed_uri"); ok {
helmFeed.FeedURI = v.(string)
}
if v, ok := d.GetOk("package_acquisition_location_options"); ok {
helmFeed.PackageAcquisitionLocationOptions = getSliceFromTerraformTypeList(v)
}
if v, ok := d.GetOk("password"); ok {
helmFeed.Password = octopusdeploy.NewSensitiveValue(v.(string))
}
if v, ok := d.GetOk("username"); ok {
helmFeed.Username = v.(string)
}
return helmFeed
}
func getHelmFeedSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"feed_uri": {
Required: true,
Type: schema.TypeString,
},
"id": getIDSchema(),
"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 setHelmFeed(ctx context.Context, d *schema.ResourceData, mavenFeed *octopusdeploy.HelmFeed) error {
d.Set("feed_uri", mavenFeed.FeedURI)
d.Set("name", mavenFeed.Name)
d.Set("space_id", mavenFeed.SpaceID)
d.Set("username", mavenFeed.Username)
if err := d.Set("package_acquisition_location_options", mavenFeed.PackageAcquisitionLocationOptions); err != nil {
return fmt.Errorf("error setting package_acquisition_location_options: %s", err)
}
d.SetId(mavenFeed.GetID())
return nil
}