Skip to content

Commit dc4b5e5

Browse files
authored
PLT-1486:Added 'zarf' and 'pack' provider type support in ecr registry (#566)
1 parent ebb5780 commit dc4b5e5

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

docs/resources/registry_oci.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ resource "spectrocloud_registry_oci" "r1" {
3939

4040
### Optional
4141

42-
- `provider_type` (String) The type of provider used for interacting with the registry. The default is 'helm'.
42+
- `is_synchronization` (Boolean) Specifies whether the registry is synchronized.
43+
- `provider_type` (String) The type of provider used for interacting with the registry. Supported value's are `helm`, `zarf` and `pack`, The default is 'helm'. `zarf` is allowed with `type="basic"`
4344
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
4445

4546
### Read-Only

spectrocloud/resource_registry_oci_ecr.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,23 @@ func resourceRegistryOciEcr() *schema.Resource {
4747
Required: true,
4848
Description: "Specifies whether the registry is private or public. Private registries require authentication to access.",
4949
},
50+
"is_synchronization": {
51+
Type: schema.TypeBool,
52+
Default: false,
53+
Optional: true,
54+
Description: "Specifies whether the registry is synchronized.",
55+
},
5056
"endpoint": {
5157
Type: schema.TypeString,
5258
Required: true,
5359
Description: "The URL endpoint of the OCI registry. This is where the container images are hosted and accessed.",
5460
},
5561
"provider_type": {
56-
Type: schema.TypeString,
57-
Optional: true,
58-
Default: "helm",
59-
Description: "The type of provider used for interacting with the registry. The default is 'helm'.",
62+
Type: schema.TypeString,
63+
Optional: true,
64+
Default: "helm",
65+
ValidateFunc: validation.StringInSlice([]string{"helm", "zarf", "pack"}, false),
66+
Description: "The type of provider used for interacting with the registry. Supported value's are `helm`, `zarf` and `pack`, The default is 'helm'. `zarf` is allowed with `type=\"basic\"` ",
6067
},
6168
"credentials": {
6269
Type: schema.TypeList,
@@ -107,6 +114,15 @@ func resourceRegistryOciEcr() *schema.Resource {
107114
},
108115
},
109116
},
117+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
118+
providerType := d.Get("provider_type").(string)
119+
registryType := d.Get("type").(string)
120+
// Validate that `provider_type` is "zarf" only if `type` is "basic"
121+
if providerType == "zarf" && registryType != "basic" {
122+
return fmt.Errorf("`provider_type` set to `zarf` is only allowed when `type` is `basic`")
123+
}
124+
return nil
125+
},
110126
}
111127
}
112128

@@ -117,6 +133,7 @@ func resourceRegistryEcrCreate(ctx context.Context, d *schema.ResourceData, m in
117133
registryType := d.Get("type").(string)
118134

119135
if registryType == "ecr" {
136+
120137
registry := toRegistryEcr(d)
121138

122139
uid, err := c.CreateOciEcrRegistry(registry)
@@ -261,22 +278,27 @@ func resourceRegistryEcrDelete(ctx context.Context, d *schema.ResourceData, m in
261278
func toRegistryEcr(d *schema.ResourceData) *models.V1EcrRegistry {
262279
endpoint := d.Get("endpoint").(string)
263280
isPrivate := d.Get("is_private").(bool)
281+
isSynchronization := d.Get("is_synchronization").(bool)
282+
providerType := d.Get("provider_type").(string)
264283
s3config := d.Get("credentials").([]interface{})[0].(map[string]interface{})
265284
return &models.V1EcrRegistry{
266285
Metadata: &models.V1ObjectMeta{
267286
Name: d.Get("name").(string),
268287
},
269288
Spec: &models.V1EcrRegistrySpec{
270-
Credentials: toRegistryAwsAccountCredential(s3config),
271-
Endpoint: &endpoint,
272-
IsPrivate: &isPrivate,
289+
Credentials: toRegistryAwsAccountCredential(s3config),
290+
Endpoint: &endpoint,
291+
IsPrivate: &isPrivate,
292+
ProviderType: &providerType,
293+
IsSyncSupported: isSynchronization,
273294
},
274295
}
275296
}
276297

277298
func toRegistryBasic(d *schema.ResourceData) *models.V1BasicOciRegistry {
278299
endpoint := d.Get("endpoint").(string)
279300
provider := d.Get("provider_type").(string)
301+
isSynchronization := d.Get("is_synchronization").(bool)
280302
authConfig := d.Get("credentials").([]interface{})[0].(map[string]interface{})
281303

282304
var username, password string
@@ -301,6 +323,7 @@ func toRegistryBasic(d *schema.ResourceData) *models.V1BasicOciRegistry {
301323
InsecureSkipVerify: false,
302324
},
303325
},
326+
IsSyncSupported: isSynchronization,
304327
},
305328
}
306329

0 commit comments

Comments
 (0)