Skip to content

Commit 95679fd

Browse files
authored
fix: TP | Fix aquasec_registry (resource and datasource)
fix: TP | Fix aquasec_registry (resource and datasource)
2 parents 60c8b1e + d37e40e commit 95679fd

11 files changed

Lines changed: 702 additions & 173 deletions

File tree

aquasec/data_image_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ var imageData = client.Image{
1919
func TestDataSourceAquasecImage(t *testing.T) {
2020
t.Parallel()
2121
rootRef := imageDataRef("test")
22+
option := "status"
23+
value := "Connected"
2224
resource.Test(t, resource.TestCase{
2325
PreCheck: func() {
2426
testAccPreCheck(t)
2527
},
2628
Providers: testAccProviders,
2729
Steps: []resource.TestStep{
2830
{
29-
Config: getImageDataSource(&imageData),
31+
Config: getImageDataSource(&imageData, option, value),
3032
Check: resource.ComposeAggregateTestCheckFunc(
3133
resource.TestCheckResourceAttr(rootRef, "registry", imageData.Registry),
3234
resource.TestCheckResourceAttr(rootRef, "registry_type", "HUB"),
@@ -35,7 +37,6 @@ func TestDataSourceAquasecImage(t *testing.T) {
3537
resource.TestCheckResourceAttrSet(rootRef, "scan_status"),
3638
resource.TestCheckResourceAttrSet(rootRef, "disallowed"),
3739
resource.TestCheckResourceAttrSet(rootRef, "scan_date"),
38-
resource.TestCheckResourceAttr(rootRef, "scan_error", ""),
3940
resource.TestCheckResourceAttrSet(rootRef, "critical_vulnerabilities"),
4041
resource.TestCheckResourceAttrSet(rootRef, "high_vulnerabilities"),
4142
resource.TestCheckResourceAttrSet(rootRef, "medium_vulnerabilities"),
@@ -54,8 +55,8 @@ func imageDataRef(name string) string {
5455
return fmt.Sprintf("data.aquasec_image.%s", name)
5556
}
5657

57-
func getImageDataSource(image *client.Image) string {
58-
return getRegistry(image.Registry) + fmt.Sprintf(`
58+
func getImageDataSource(image *client.Image, option, value string) string {
59+
return getRegistry(image.Registry, option, value) + fmt.Sprintf(`
5960
resource "aquasec_image" "test" {
6061
registry = aquasec_integration_registry.demo.id
6162
repository = "%s"

aquasec/data_registry.go

Lines changed: 181 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package aquasec
22

33
import (
4+
"context"
45
"log"
56

67
"github.com/aquasecurity/terraform-provider-aquasec/client"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
810
)
911

1012
func dataSourceRegistry() *schema.Resource {
1113
return &schema.Resource{
12-
Read: dataRegistryRead,
14+
ReadContext: dataRegistryRead,
1315
Schema: map[string]*schema.Schema{
1416
"username": {
1517
Type: schema.TypeString,
@@ -193,11 +195,167 @@ func dataSourceRegistry() *schema.Resource {
193195
Type: schema.TypeString,
194196
},
195197
},
198+
"auto_scan_time": {
199+
Type: schema.TypeSet,
200+
Description: "When enabled, registry events are sent to the given Aqua webhook url",
201+
Optional: true,
202+
Computed: true,
203+
Elem: &schema.Resource{
204+
Schema: map[string]*schema.Schema{
205+
"auto_pull_day": {
206+
Type: schema.TypeInt,
207+
Description: "The day for auto pull",
208+
Optional: true,
209+
Computed: true,
210+
},
211+
"iteration": {
212+
Type: schema.TypeInt,
213+
Description: "Number of iterations",
214+
Optional: true,
215+
Computed: true,
216+
},
217+
"iteration_type": {
218+
Type: schema.TypeString,
219+
Description: "The type of iteration (day, week, month, year)",
220+
Optional: true,
221+
Computed: true,
222+
},
223+
"time": {
224+
Type: schema.TypeString,
225+
Description: "the time for auto pull",
226+
Optional: true,
227+
Computed: true,
228+
},
229+
"week_days": {
230+
Type: schema.TypeList,
231+
Description: "The days of week for auto pull",
232+
Optional: true,
233+
Elem: &schema.Schema{
234+
Type: schema.TypeString,
235+
},
236+
},
237+
},
238+
},
239+
},
240+
"detected_type": {
241+
Type: schema.TypeInt,
242+
Description: "The detected type of the registry",
243+
Computed: true,
244+
},
245+
"force_save": {
246+
Type: schema.TypeBool,
247+
Description: "Whether to force save the registry even if the test connection fails",
248+
Optional: true,
249+
Default: false,
250+
},
251+
"force_ootb": {
252+
Type: schema.TypeBool,
253+
Description: "To identify and ignore supersonic client calls initiated from OOTB",
254+
Optional: true,
255+
Default: false,
256+
},
257+
"image_s3_prefixes": {
258+
Type: schema.TypeList,
259+
Description: "The S3 prefixes for images",
260+
Optional: true,
261+
Elem: &schema.Schema{
262+
Type: schema.TypeString,
263+
},
264+
},
265+
"is_registry_connected": {
266+
Type: schema.TypeBool,
267+
Description: "Whether the registry is connected",
268+
Computed: true,
269+
},
270+
"permission": {
271+
Type: schema.TypeString,
272+
Description: "Permission action",
273+
Optional: true,
274+
},
275+
"pull_max_tags": {
276+
Type: schema.TypeInt,
277+
Description: "The maximum number of tags for auto pull",
278+
Optional: true,
279+
},
280+
"pull_tags_pattern": {
281+
Type: schema.TypeList,
282+
Description: "Patterns for tags to be pulled from auto pull",
283+
Optional: true,
284+
Elem: &schema.Schema{
285+
Type: schema.TypeString,
286+
},
287+
},
288+
"pull_repo_patterns": {
289+
Type: schema.TypeList,
290+
Description: "Patterns for repositories to be pulled from auto pull",
291+
Optional: true,
292+
Elem: &schema.Schema{
293+
Type: schema.TypeString,
294+
},
295+
},
296+
"registries_type": {
297+
Type: schema.TypeString,
298+
Description: "The type of registries",
299+
Computed: true,
300+
},
301+
"auto_pull_latest_xff_enabled": {
302+
Type: schema.TypeBool,
303+
Description: "Auto pull latest xff enabled",
304+
Optional: true,
305+
},
306+
"is_architecture_system_default": {
307+
Type: schema.TypeBool,
308+
Description: "Whether the architecture is the system default",
309+
Optional: true,
310+
},
311+
"client_cert": {
312+
Type: schema.TypeString,
313+
Description: "The client certificate for the registry",
314+
Optional: true,
315+
},
316+
"client_key": {
317+
Type: schema.TypeString,
318+
Description: "The client key for the registry",
319+
Optional: true,
320+
},
321+
"auto_pull_in_progress": {
322+
Type: schema.TypeBool,
323+
Description: "Whether auto pull is in progress",
324+
Computed: true,
325+
},
326+
"auto_pull_processed_page_number": {
327+
Type: schema.TypeInt,
328+
Description: "The page number processed for auto pull",
329+
Computed: true,
330+
},
331+
"architecture": {
332+
Type: schema.TypeString,
333+
Description: "The architecture of the registry",
334+
Optional: true,
335+
},
336+
"cloud_resources": {
337+
Type: schema.TypeList,
338+
Description: "The cloud resource of the registry",
339+
Optional: true,
340+
Elem: &schema.Schema{
341+
Type: schema.TypeString,
342+
},
343+
},
344+
"error_msg": {
345+
Type: schema.TypeString,
346+
Description: "The error message of the registry",
347+
Optional: true,
348+
},
349+
"nexus_mtts_ff_enabled": {
350+
Type: schema.TypeBool,
351+
Description: "Enable mutual TLS for Sonatype Nexus Repository",
352+
Optional: true,
353+
},
196354
},
197355
}
198356
}
199357

200-
func dataRegistryRead(d *schema.ResourceData, m interface{}) error {
358+
func dataRegistryRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
201359
log.Println("[DEBUG] inside dataRegistryRead")
202360
ac := m.(*client.Client)
203361
name := d.Get("name").(string)
@@ -231,10 +389,29 @@ func dataRegistryRead(d *schema.ResourceData, m interface{}) error {
231389
if scannerType == "specific" {
232390
d.Set("scanner_name", convertStringArr(scanner_name))
233391
}
234-
392+
d.Set("is_architecture_system_default", reg.IsArchitectureSystemDefault)
393+
d.Set("client_cert", reg.ClientCert)
394+
d.Set("client_key", reg.ClientKey)
395+
d.Set("auto_pull_in_progress", reg.AutoPullInProgress)
396+
d.Set("auto_pull_processed_page_number", reg.AutoPullProcessedPageNumber)
397+
d.Set("architecture", reg.Architecture)
398+
d.Set("error_msg", reg.ErrorMsg)
399+
d.Set("nexus_mtts_ff_enabled", reg.NexusMttsFfEnabled)
400+
d.Set("force_save", reg.ForceSave)
401+
d.Set("force_ootb", reg.ForceOotb)
402+
d.Set("is_registry_connected", reg.IsRegistryConnected)
403+
d.Set("permission", reg.Permission)
404+
d.Set("pull_max_tags", reg.PullMaxTags)
405+
d.Set("registries_type", reg.RegistriesType)
406+
d.Set("detected_type", reg.DetectedType)
407+
d.Set("auto_pull_latest_xff_enabled", reg.AutoPullLatestXffEnabled)
408+
d.Set("image_s3_prefixes", reg.ImageS3Prefixes)
409+
d.Set("cloud_resources", reg.CloudResources)
410+
d.Set("pull_repo_patterns", reg.PullRepoPatterns)
411+
d.Set("pull_tags_pattern", reg.PullTagsPattern)
235412
d.SetId(name)
236413
} else {
237-
return err
414+
return diag.FromErr(err)
238415
}
239416

240417
return nil

aquasec/data_registry_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,52 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1010
)
1111

12-
func TestAquasecRegistryDatasource(t *testing.T) {
12+
func TestAquasecRegistryAnyDatasourceAny(t *testing.T) {
1313
t.Parallel()
1414
name := acctest.RandomWithPrefix("terraform-test")
1515
url := "https://docker.io"
1616
rtype := "HUB"
1717
username := ""
1818
password := ""
1919
autopull := false
20+
option := "status"
21+
value := "Connected"
2022
resource.Test(t, resource.TestCase{
2123
PreCheck: func() { testAccPreCheck(t) },
2224
Providers: testAccProviders,
2325
Steps: []resource.TestStep{
2426
{
25-
Config: testAccCheckAquasecRegistryDataSource(name, url, rtype, username, password, autopull),
27+
Config: testAccCheckAquasecRegistryDataSourceAny(name, url, rtype, username, password, option, value, autopull),
2628
Check: testAccCheckAquasecRegistryDataSourceExists("data.aquasec_integration_registries.testregistries"),
2729
},
2830
},
2931
})
3032
}
3133

32-
func testAccCheckAquasecRegistryDataSource(name, url, rtype, username, password string, autopull bool) string {
34+
func testAccCheckAquasecRegistryDataSourceAny(name, url, rtype, username, password, option, value string, autopull bool) string {
3335
return fmt.Sprintf(`
34-
resource "aquasec_integration_registry" "new" {
36+
resource "aquasec_integration_registry" "any" {
3537
name = "%s"
3638
url = "%s"
3739
type = "%s"
3840
username = "%s"
3941
password = "%s"
4042
auto_pull = "%v"
43+
44+
options {
45+
option = "%s"
46+
value = "%s"
47+
}
48+
4149
}
4250
4351
data "aquasec_integration_registries" "testregistries" {
44-
name = aquasec_integration_registry.new.name
52+
name = aquasec_integration_registry.any.name
4553
depends_on = [
46-
aquasec_integration_registry.new
54+
aquasec_integration_registry.any
4755
]
4856
}
49-
`, name, url, rtype, username, password, autopull)
57+
`, name, url, rtype, username, password, autopull, option, value)
5058

5159
}
5260

0 commit comments

Comments
 (0)