Skip to content

Commit e9ef381

Browse files
authored
Merge branch 'main' into PLT-1551
2 parents c5e6473 + 592d890 commit e9ef381

File tree

16 files changed

+786
-21
lines changed

16 files changed

+786
-21
lines changed

docs/data-sources/pack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ data "spectrocloud_pack" "cni" {
6161
- `name` (String) The name of the pack to search for.
6262
- `registry_uid` (String) The unique identifier (UID) of the registry where the pack is located. Specify `registry_uid` to search within a specific registry.
6363
- `type` (String) The type of pack to search for. Supported values are `helm`, `manifest`, `container`, `operator-instance`.
64-
- `version` (String) The version of the pack to search for.
64+
- `version` (String) Specify the version of the pack to search for. If not set, the latest available version from the specified registry will be used.
6565

6666
### Read-Only
6767

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

docs/resources/resource_limit.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
page_title: "spectrocloud_resource_limit Resource - terraform-provider-spectrocloud"
3+
subcategory: ""
4+
description: |-
5+
6+
---
7+
8+
# spectrocloud_resource_limit (Resource)
9+
10+
11+
12+
You can learn more about managing resource limit in Palette by reviewing the [Default Resource Limit](https://docs.spectrocloud.com/tenant-settings/palette-resource-limits/?utm_source=palette&utm_medium=product2docs) guide.
13+
14+
~> The resource_limit resource enforces a resource limit in Palette. By default, a resource limit is configured in Palette with default values. Users can update the resource limit settings as per their requirements. When a spectrocloud_resource_limit resource is destroyed, the resource limits will revert to the Palette default settings.
15+
16+
## Example Usage
17+
18+
An example of managing an password policy in Palette.
19+
20+
```hcl
21+
resource "spectrocloud_resource_limit" "resource_limit" {
22+
alert = 101
23+
api_keys = 201
24+
appliance = 6001
25+
appliance_token = 201
26+
application_deployment = 200
27+
application_profile = 200
28+
certificate = 20
29+
cloud_account = 355
30+
cluster = 300
31+
cluster_group = 50
32+
cluster_profile = 2500
33+
filter = 200
34+
location = 100
35+
macro = 6000
36+
private_gateway = 100
37+
project = 200
38+
registry = 200
39+
role = 100
40+
ssh_key = 300
41+
team = 100
42+
user = 300
43+
workspace = 60
44+
}
45+
46+
## import existing resource limit
47+
#import {
48+
# to = spectrocloud_resource_limit.resource_limit
49+
# id = "5eea74e919f5e0d43fd3f316" // tenant-uid
50+
#}
51+
```
52+
53+
<!-- schema generated by tfplugindocs -->
54+
## Schema
55+
56+
### Optional
57+
58+
- `alert` (Number) The maximum number of alerts that can be created. Must be between 1 and 10,000.
59+
- `api_keys` (Number) The maximum number of API keys that can be generated. Must be between 1 and 10,000.
60+
- `appliance` (Number) The maximum number of appliances that can be managed. Must be between 1 and 50,000.
61+
- `appliance_token` (Number) The maximum number of appliance tokens that can be issued. Must be between 1 and 10,000.
62+
- `application_deployment` (Number) The maximum number of application deployments allowed. Must be between 1 and 10,000.
63+
- `application_profile` (Number) The maximum number of application profiles that can be configured. Must be between 1 and 10,000.
64+
- `certificate` (Number) The maximum number of certificates that can be managed. Must be between 1 and 10,000.
65+
- `cloud_account` (Number) The maximum number of cloud accounts that can be added. Must be between 1 and 10,000.
66+
- `cluster` (Number) The maximum number of clusters that can be created. Must be between 1 and 50,000.
67+
- `cluster_group` (Number) The maximum number of cluster groups that can be created. Must be between 1 and 10,000.
68+
- `cluster_profile` (Number) The maximum number of cluster profiles that can be configured. Must be between 1 and 10,000.
69+
- `filter` (Number) The maximum number of filters that can be defined. Must be between 1 and 10,000.
70+
- `location` (Number) The maximum number of locations that can be configured. Must be between 1 and 10,000.
71+
- `macro` (Number) The maximum number of macros that can be created. Must be between 1 and 10,000.
72+
- `private_gateway` (Number) The maximum number of private gateways that can be managed. Must be between 1 and 10,000.
73+
- `project` (Number) The maximum number of projects that can be created. Must be between 1 and 10,000.
74+
- `registry` (Number) The maximum number of registries that can be configured. Must be between 1 and 10,000.
75+
- `role` (Number) The maximum number of roles that can be assigned. Must be between 1 and 10,000.
76+
- `ssh_key` (Number) The maximum number of SSH keys that can be managed. Must be between 1 and 10,000.
77+
- `team` (Number) The maximum number of teams that can be created. Must be between 1 and 10,000.
78+
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
79+
- `user` (Number) The maximum number of users that can be added. Must be between 1 and 10,000.
80+
- `workspace` (Number) The maximum number of workspaces that can be created. Must be between 1 and 10,000.
81+
82+
### Read-Only
83+
84+
- `id` (String) The ID of this resource.
85+
86+
<a id="nestedblock--timeouts"></a>
87+
### Nested Schema for `timeouts`
88+
89+
Optional:
90+
91+
- `create` (String)
92+
- `delete` (String)
93+
- `update` (String)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
spectrocloud = {
4+
version = ">= 0.1"
5+
source = "spectrocloud/spectrocloud"
6+
}
7+
}
8+
}
9+
10+
provider "spectrocloud" {
11+
host = var.sc_host
12+
api_key = var.sc_api_key
13+
project_name = var.sc_project_name
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
resource "spectrocloud_resource_limit" "resource_limit" {
2+
alert = 101
3+
api_keys = 201
4+
appliance = 6001
5+
appliance_token = 201
6+
application_deployment = 200
7+
application_profile = 200
8+
certificate = 20
9+
cloud_account = 355
10+
cluster = 300
11+
cluster_group = 50
12+
cluster_profile = 2500
13+
filter = 200
14+
location = 100
15+
macro = 6000
16+
private_gateway = 100
17+
project = 200
18+
registry = 200
19+
role = 100
20+
ssh_key = 300
21+
team = 100
22+
user = 300
23+
workspace = 60
24+
}
25+
26+
## import existing resource limit
27+
#import {
28+
# to = spectrocloud_resource_limit.resource_limit
29+
# id = "5eea74e919f5e0d43fd3f316" // tenant-uid
30+
#}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Spectro Cloud credentials
2+
sc_host = "{Enter Spectro Cloud API Host}" #e.g: api.spectrocloud.com (for SaaS)
3+
sc_api_key = "{Enter Spectro Cloud API Key}"
4+
sc_project_name = "{Enter Spectro Cloud Project Name}" #e.g: Default
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
variable "sc_host" {
2+
description = "Spectro Cloud Endpoint"
3+
default = "api.spectrocloud.com"
4+
}
5+
6+
variable "sc_api_key" {
7+
description = "Spectro Cloud API key"
8+
}
9+
10+
variable "sc_project_name" {
11+
description = "Spectro Cloud Project (e.g: Default)"
12+
default = "Default"
13+
}
14+
15+
variable "ssh_key_value" {
16+
description = "ssh key value"
17+
default = "ssh-rsa ...... == [email protected]"
18+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ module github.com/spectrocloud/terraform-provider-spectrocloud
33
go 1.22.5
44

55
require (
6+
github.com/Masterminds/semver/v3 v3.1.1
67
github.com/go-openapi/strfmt v0.23.0
78
github.com/google/go-cmp v0.6.0
89
github.com/gorilla/mux v1.8.0
910
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1011
github.com/hashicorp/terraform-plugin-docs v0.16.0
1112
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
1213
github.com/robfig/cron v1.2.0
13-
github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368
14+
github.com/spectrocloud/gomi v1.14.1-0.20241226051628-5517f1108187
1415
github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d
15-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250128174237-7ff93c608ae2
16+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250129091228-61bad491e5e8
1617
github.com/stretchr/testify v1.10.0
1718
gotest.tools v2.2.0+incompatible
1819
k8s.io/api v0.23.5
@@ -23,7 +24,6 @@ require (
2324

2425
require (
2526
github.com/Masterminds/goutils v1.1.1 // indirect
26-
github.com/Masterminds/semver/v3 v3.1.1 // indirect
2727
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
2828
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
2929
github.com/agext/levenshtein v1.2.2 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,12 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
597597
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
598598
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
599599
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
600-
github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368 h1:eY0BOyEbGuNZcLtILVQrh7D7oEu+UezpLkuCzlK6Ae4=
601-
github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368/go.mod h1:LlZ9We4kDaELYi7Is0SVmnySuDhwphJLS6ZT4wXxFIk=
600+
github.com/spectrocloud/gomi v1.14.1-0.20241226051628-5517f1108187 h1:P1VH0jiSo/KND6pYxDPM+wy4bPthH9uxdPu0We8kQFk=
601+
github.com/spectrocloud/gomi v1.14.1-0.20241226051628-5517f1108187/go.mod h1:HUKoN5t9KjBY7R2F4gj9rIBnpN8jRPEFWqe1ul+SKCA=
602602
github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d h1:OMRbHxMJ1a+G1BYzvUYuMM0wLkYJPdnEOFx16faQ/UY=
603603
github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d/go.mod h1:MktpRPnSXDTHsQrFSD+daJFQ1zMLSR+1gWOL31jVvWE=
604-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250128174237-7ff93c608ae2 h1:dgisL6mrzj4aEUEfOfotrTPGvClYjf+m3DeiLciR1CQ=
605-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250128174237-7ff93c608ae2/go.mod h1:Zv1+/Imw/lIOPAa+q9TzdyKiXmIzfLSwVTj11WemIZc=
604+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250129091228-61bad491e5e8 h1:VjJvMdivBh0TLPKJhtbZa1OYcGmbvoVIAHNN8v1cnvc=
605+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250129091228-61bad491e5e8/go.mod h1:Zv1+/Imw/lIOPAa+q9TzdyKiXmIzfLSwVTj11WemIZc=
606606
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
607607
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
608608
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=

spectrocloud/data_source_pack.go

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package spectrocloud
33
import (
44
"context"
55
"fmt"
6+
"github.com/Masterminds/semver/v3"
7+
"github.com/spectrocloud/gomi/pkg/ptr"
8+
"github.com/spectrocloud/palette-sdk-go/api/models"
9+
"github.com/spectrocloud/palette-sdk-go/client"
10+
"sort"
611
"strings"
712

813
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -46,7 +51,7 @@ func dataSourcePack() *schema.Resource {
4651
},
4752
"version": {
4853
Type: schema.TypeString,
49-
Description: "The version of the pack to search for.",
54+
Description: "Specify the version of the pack to search for. If not set, the latest available version from the specified registry will be used.",
5055
Computed: true,
5156
Optional: true,
5257
},
@@ -73,6 +78,7 @@ func dataSourcePack() *schema.Resource {
7378

7479
func dataSourcePackRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
7580
c := getV1ClientWithResourceContext(m, "")
81+
var packName = ""
7682

7783
// Warning or errors can be collected in a slice type
7884
var diags diag.Diagnostics
@@ -115,17 +121,24 @@ func dataSourcePackRead(_ context.Context, d *schema.ResourceData, m interface{}
115121
and first part would be any random name to make overall pack name unique and 2nd part is actual pack name.
116122
Thus, splitting pack name with '--' to get the correct pack name to find pack uuid
117123
*/
124+
118125
if strings.Contains(v.(string), "--") {
119126
v = strings.Split(v.(string), "--")[1]
120127
}
128+
packName = v.(string)
121129
filters = append(filters, fmt.Sprintf("spec.name=%s", v.(string)))
122130
}
123-
if v, ok := d.GetOk("version"); ok {
124-
filters = append(filters, fmt.Sprintf("spec.version=%s", v.(string)))
125-
}
126131
if v, ok := d.GetOk("registry_uid"); ok {
127132
registryUID = v.(string)
128133
}
134+
if v, ok := d.GetOk("version"); ok {
135+
filters = append(filters, fmt.Sprintf("spec.version=%s", v.(string)))
136+
} else {
137+
latestVersion := setLatestPackVersionToFilters(packName, registryUID, c)
138+
if latestVersion != "" {
139+
filters = append(filters, fmt.Sprintf("spec.version=%s", latestVersion))
140+
}
141+
}
129142
if v, ok := d.GetOk("cloud"); ok {
130143
clouds := expandStringList(v.(*schema.Set).List())
131144
if !stringContains(clouds, "all") {
@@ -140,7 +153,7 @@ func dataSourcePackRead(_ context.Context, d *schema.ResourceData, m interface{}
140153
return diag.FromErr(err)
141154
}
142155

143-
packName := "unknown"
156+
packName = "unknown"
144157
if v, ok := d.GetOk("name"); ok {
145158
packName = v.(string)
146159
}
@@ -196,3 +209,49 @@ func dataSourcePackRead(_ context.Context, d *schema.ResourceData, m interface{}
196209

197210
return diags
198211
}
212+
213+
func setLatestPackVersionToFilters(packName string, registryUID string, c *client.V1Client) string {
214+
var packLayers = []models.V1PackLayer{"addon", "csi", "cni", "os", "kernel"}
215+
var packTypes = []models.V1PackType{"spectro", "helm", "manifest", "oci"}
216+
var packAddOnTypes = []string{"load balancer", "ingress", "logging", "monitoring", "security", "authentication",
217+
"servicemesh", "system app", "app services", "registry", "csi", "cni", "integration", ""}
218+
219+
newFilter := &models.V1PackFilterSpec{
220+
Name: &models.V1FilterString{
221+
Eq: ptr.StringPtr(packName),
222+
},
223+
Type: packTypes,
224+
Layer: packLayers,
225+
Environment: []string{"all"},
226+
AddOnType: packAddOnTypes,
227+
}
228+
if registryUID != "" {
229+
newFilter.RegistryUID = []string{registryUID}
230+
}
231+
var newSort []*models.V1PackSortSpec
232+
latestVersion := ""
233+
packsResults, _ := c.SearchPacks(newFilter, newSort)
234+
if len(packsResults) == 1 {
235+
latestVersion, _ = getLatestVersion(packsResults[0].Spec.Registries)
236+
return latestVersion
237+
}
238+
return ""
239+
}
240+
241+
// getLatestVersion returns the latest version from a list of version strings.
242+
func getLatestVersion(versions []*models.V1RegistryPackMetadata) (string, error) {
243+
if len(versions) == 0 {
244+
return "", fmt.Errorf("no versions provided")
245+
}
246+
semverVersions := make([]*semver.Version, len(versions))
247+
for i, v := range versions {
248+
ver, err := semver.NewVersion(v.LatestVersion)
249+
if err != nil {
250+
return "", fmt.Errorf("invalid version %q: %w", v, err)
251+
}
252+
semverVersions[i] = ver
253+
}
254+
sort.Sort(semver.Collection(semverVersions))
255+
256+
return semverVersions[len(semverVersions)-1].String(), nil
257+
}

0 commit comments

Comments
 (0)