-
Notifications
You must be signed in to change notification settings - Fork 133
/
data_cloud_project_capabilities_containerregistry_filter.go
131 lines (119 loc) · 3.19 KB
/
data_cloud_project_capabilities_containerregistry_filter.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
package ovh
import (
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceCloudProjectCapabilitiesContainerRegistryFilter() *schema.Resource {
return &schema.Resource{
Read: dataSourceCloudProjectCapabilitiesContainerRegistryFilterRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
},
"region": {
Type: schema.TypeString,
Description: "Region of the registry.",
Required: true,
},
"plan_name": {
Type: schema.TypeString,
Description: "Plan name of the registry.",
Required: true,
},
//Computed
"code": {
Type: schema.TypeString,
Description: "Plan code from catalog",
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Description: "Plan creation date",
Computed: true,
},
"features": {
Type: schema.TypeList,
Computed: true,
Description: "Features of the plan",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vulnerability": {
Type: schema.TypeBool,
Description: "Vulnerability scanning",
Computed: true,
},
},
},
},
"name": {
Type: schema.TypeString,
Description: "Plan name",
Computed: true,
},
"registry_limits": {
Type: schema.TypeList,
Computed: true,
Description: "Container registry limits",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"image_storage": {
Type: schema.TypeInt,
Description: "Docker image storage limits in bytes",
Computed: true,
},
"parallel_request": {
Type: schema.TypeInt,
Description: "Parallel requests on Docker image API (/v2 Docker registry API)",
Computed: true,
},
},
},
},
"updated_at": {
Type: schema.TypeString,
Description: "Plan last update date",
Computed: true,
},
},
}
}
func dataSourceCloudProjectCapabilitiesContainerRegistryFilterRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
log.Printf("[DEBUG] Will read cloud project capabilities container registry for project: %s", serviceName)
capregs := []CloudProjectCapabilitiesContainerRegistry{}
endpoint := fmt.Sprintf(
"/cloud/project/%s/capabilities/containerRegistry",
url.PathEscape(serviceName),
)
err := config.OVHClient.Get(endpoint, &capregs)
if err != nil {
return fmt.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
}
match := false
for _, capreg := range capregs {
if capreg.RegionName == d.Get("region").(string) {
for _, plan := range capreg.Plans {
if plan.Name == d.Get("plan_name").(string) {
for k, v := range plan.ToMap() {
match = true
if k == "id" {
d.SetId(v.(string))
} else {
d.Set(k, v)
}
}
}
}
}
}
if !match {
return fmt.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
}
return nil
}