Skip to content

Commit

Permalink
Update default_system_registry behavior in rancher2_app_v2 resource (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasSUSE committed Nov 28, 2023
1 parent daae17b commit 298f917
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
18 changes: 18 additions & 0 deletions docs/resources/app_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ resource "rancher2_app_v2" "foo" {
}
```

### Create an App from a Helm Chart using a different registry

The `system_default_registry` argument can override the global value at App installation. If argument is not provided, the global value for System Default Registry will be used instead.

```hcl
resource "rancher2_app_v2" "cis_benchmark" {
cluster_id = "<CLUSTER_ID>"
name = "rancher-cis-benchmark"
namespace = "cis-operator-system"
repo_name = "rancher-charts"
chart_name = "rancher-cis-benchmark"
# Valid DNS for Private Registry
system_default_registry = "<some.dns.here>:<PORT>"
}
```

## Argument Reference

The following arguments are supported:
Expand All @@ -40,6 +57,7 @@ The following arguments are supported:
* `wait` - (Optional) Wait until app is deployed. Default: `true` (bool)
* `annotations` - (Optional/Computed) Annotations for the app v2 (map)
* `labels` - (Optional/Computed) Labels for the app v2 (map)
* `system_default_registry` - (Optional/Computed) System default registry providing images for app deployment (string)

## Attributes Reference

Expand Down
8 changes: 6 additions & 2 deletions rancher2/resource_rancher2_app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func resourceRancher2AppV2Create(d *schema.ResourceData, meta interface{}) error
repoName := d.Get("repo_name").(string)
chartName := d.Get("chart_name").(string)
chartVersion := d.Get("chart_version").(string)
systemDefaultRegistry := d.Get("system_default_registry").(string)

log.Printf("[INFO] Creating App V2 %s at cluster ID %s", name, clusterID)

Expand All @@ -49,11 +50,14 @@ func resourceRancher2AppV2Create(d *schema.ResourceData, meta interface{}) error
}
d.Set("cluster_name", cluster.Name)

systemDefaultRegistry, err := meta.(*Config).GetSettingV2ByID(appV2DefaultRegistryID)
globalSystemDefaultRegistry, err := meta.(*Config).GetSettingV2ByID(appV2DefaultRegistryID)
if err != nil {
return err
}
d.Set("system_default_registry", systemDefaultRegistry.Value)

if systemDefaultRegistry == "" {
d.Set("system_default_registry", globalSystemDefaultRegistry.Value)
}

repo, chartInfo, err := infoAppV2(meta.(*Config), clusterID, repoName, chartName, chartVersion)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions rancher2/schema_app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
norman "github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1"
v1 "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1"
)

const (
Expand Down Expand Up @@ -79,8 +79,10 @@ func appV2Fields() map[string]*schema.Schema {
Description: "Deploy app within project ID",
},
"system_default_registry": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "System default registry providing images for app deployment.",
},
"values": {
Type: schema.TypeString,
Expand Down

0 comments on commit 298f917

Please sign in to comment.