From 7884182da498693bd6ed7142871a3ad3b68e581c Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Thu, 12 Sep 2024 19:06:11 -0600 Subject: [PATCH 1/5] fix: add context to PCG IP pool Signed-off-by: Tyler Gillson --- docs/resources/privatecloudgateway_ippool.md | 1 + spectrocloud/resource_pcg_ippool.go | 22 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/resources/privatecloudgateway_ippool.md b/docs/resources/privatecloudgateway_ippool.md index b32976a3..4406f828 100644 --- a/docs/resources/privatecloudgateway_ippool.md +++ b/docs/resources/privatecloudgateway_ippool.md @@ -27,6 +27,7 @@ description: |- ### Optional +- `context` (String) Specifies cluster context where IP Pool is created. Allowed values are `project` or `tenant`. Defaults to `project`. If the `project` context is specified, the project name will sourced from the provider configuration parameter [`project_name`](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs#schema). - `ip_end_range` (String) - `ip_start_range` (String) - `nameserver_addresses` (Set of String) diff --git a/spectrocloud/resource_pcg_ippool.go b/spectrocloud/resource_pcg_ippool.go index 6469ddb6..dfd56397 100644 --- a/spectrocloud/resource_pcg_ippool.go +++ b/spectrocloud/resource_pcg_ippool.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/spectrocloud/palette-sdk-go/api/models" ) @@ -27,6 +29,14 @@ func resourcePrivateCloudGatewayIpPool() *schema.Resource { SchemaVersion: 2, Schema: map[string]*schema.Schema{ + "context": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"project", "tenant"}, false), + Default: "project", + Description: "Specifies cluster context where IP Pool is created. " + + "Allowed values are `project` or `tenant`. Defaults to `project`. " + PROJECT_NAME_NUANCE, + }, "name": { Type: schema.TypeString, Required: true, @@ -88,7 +98,8 @@ func resourcePrivateCloudGatewayIpPool() *schema.Resource { } func resourceIpPoolCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + resourceContext := d.Get("context").(string) + c := getV1ClientWithResourceContext(m, resourceContext) var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) @@ -104,7 +115,8 @@ func resourceIpPoolCreate(ctx context.Context, d *schema.ResourceData, m interfa } func resourceIpPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + resourceContext := d.Get("context").(string) + c := getV1ClientWithResourceContext(m, resourceContext) var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) @@ -158,7 +170,8 @@ func resourceIpPoolRead(ctx context.Context, d *schema.ResourceData, m interface } func resourceIpPoolUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + resourceContext := d.Get("context").(string) + c := getV1ClientWithResourceContext(m, resourceContext) var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) @@ -174,7 +187,8 @@ func resourceIpPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfa } func resourceIpPoolDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + resourceContext := d.Get("context").(string) + c := getV1ClientWithResourceContext(m, resourceContext) var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) From 4b23c2a208f9016cd5d600455cf2408350aecf1e Mon Sep 17 00:00:00 2001 From: Karl Cardenas Date: Thu, 12 Sep 2024 19:11:40 -0700 Subject: [PATCH 2/5] docs: missing word --- docs/resources/privatecloudgateway_ippool.md | 2 +- templates/resources/privatecloudgateway_ippool.md.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/privatecloudgateway_ippool.md b/docs/resources/privatecloudgateway_ippool.md index 25ae2004..f77fad81 100644 --- a/docs/resources/privatecloudgateway_ippool.md +++ b/docs/resources/privatecloudgateway_ippool.md @@ -52,7 +52,7 @@ An example of creating an IP Pool for a Private Cloud Gateway using a subnet of } ``` -The following example is for creating an IP that belongs to a Private Cloud Gateway created at the tenant scope. +The following example is for creating an IP pool that belongs to a Private Cloud Gateway created at the tenant scope. ```hcl data "spectrocloud_private_cloud_gateway" "pcg" { diff --git a/templates/resources/privatecloudgateway_ippool.md.tmpl b/templates/resources/privatecloudgateway_ippool.md.tmpl index 74a59b88..bf547c38 100644 --- a/templates/resources/privatecloudgateway_ippool.md.tmpl +++ b/templates/resources/privatecloudgateway_ippool.md.tmpl @@ -52,7 +52,7 @@ An example of creating an IP Pool for a Private Cloud Gateway using a subnet of } ``` -The following example is for creating an IP that belongs to a Private Cloud Gateway created at the tenant scope. +The following example is for creating an IP pool that belongs to a Private Cloud Gateway created at the tenant scope. ```hcl data "spectrocloud_private_cloud_gateway" "pcg" { From 13541e6141881a4114f1d9ff5571b5dde02ef796 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Fri, 13 Sep 2024 06:54:46 -0600 Subject: [PATCH 3/5] fix: hard code tenant scope for PCG IP pools Signed-off-by: Tyler Gillson --- docs/resources/privatecloudgateway_ippool.md | 1 - spectrocloud/resource_pcg_ippool.go | 21 ++++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/docs/resources/privatecloudgateway_ippool.md b/docs/resources/privatecloudgateway_ippool.md index f77fad81..0c1cdd1e 100644 --- a/docs/resources/privatecloudgateway_ippool.md +++ b/docs/resources/privatecloudgateway_ippool.md @@ -88,7 +88,6 @@ The following example is for creating an IP pool that belongs to a Private Cloud ### Optional -- `context` (String) Specifies cluster context where IP Pool is created. Allowed values are `project` or `tenant`. Defaults to `project`. If the `project` context is specified, the project name will sourced from the provider configuration parameter [`project_name`](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs#schema). - `ip_end_range` (String) The end IP address of the IP pool. Required if `network_type` is `range`. - `ip_start_range` (String) The start IP address of the IP pool. Required if `network_type` is `range`. - `nameserver_addresses` (Set of String) The list of nameserver IP addresses for the IP pool. diff --git a/spectrocloud/resource_pcg_ippool.go b/spectrocloud/resource_pcg_ippool.go index 02d53937..98ffdc77 100644 --- a/spectrocloud/resource_pcg_ippool.go +++ b/spectrocloud/resource_pcg_ippool.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/spectrocloud/palette-sdk-go/api/models" ) @@ -30,14 +29,6 @@ func resourcePrivateCloudGatewayIpPool() *schema.Resource { SchemaVersion: 2, Schema: map[string]*schema.Schema{ - "context": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{"project", "tenant"}, false), - Default: "project", - Description: "Specifies cluster context where IP Pool is created. " + - "Allowed values are `project` or `tenant`. Defaults to `project`. " + PROJECT_NAME_NUANCE, - }, "name": { Type: schema.TypeString, Required: true, @@ -110,8 +101,7 @@ func resourcePrivateCloudGatewayIpPool() *schema.Resource { } func resourceIpPoolCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - resourceContext := d.Get("context").(string) - c := getV1ClientWithResourceContext(m, resourceContext) + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) @@ -127,8 +117,7 @@ func resourceIpPoolCreate(ctx context.Context, d *schema.ResourceData, m interfa } func resourceIpPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - resourceContext := d.Get("context").(string) - c := getV1ClientWithResourceContext(m, resourceContext) + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) @@ -182,8 +171,7 @@ func resourceIpPoolRead(ctx context.Context, d *schema.ResourceData, m interface } func resourceIpPoolUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - resourceContext := d.Get("context").(string) - c := getV1ClientWithResourceContext(m, resourceContext) + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) @@ -199,8 +187,7 @@ func resourceIpPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfa } func resourceIpPoolDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - resourceContext := d.Get("context").(string) - c := getV1ClientWithResourceContext(m, resourceContext) + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics pcgUID := d.Get("private_cloud_gateway_id").(string) From df99b5e4c543c82ea6adbadb67b90d986ca503ce Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Fri, 13 Sep 2024 07:07:08 -0600 Subject: [PATCH 4/5] docs: fix nameserver_addresses Signed-off-by: Tyler Gillson --- docs/resources/privatecloudgateway_ippool.md | 6 +++--- templates/resources/privatecloudgateway_ippool.md.tmpl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/resources/privatecloudgateway_ippool.md b/docs/resources/privatecloudgateway_ippool.md index 0c1cdd1e..c84ecb3c 100644 --- a/docs/resources/privatecloudgateway_ippool.md +++ b/docs/resources/privatecloudgateway_ippool.md @@ -28,7 +28,7 @@ An example of creating an IP Pool for a Private Cloud Gateway using a range of I private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id ip_start_range = "192.168.1.10" ip_end_range = "192.168.1.100" - nameserver_addresses = "192.168.1.8" + nameserver_addresses = ["192.168.1.8"] restrict_to_single_cluster = true } ``` @@ -48,7 +48,7 @@ An example of creating an IP Pool for a Private Cloud Gateway using a subnet of prefix = "24" subnet_cidr = "10.10.100.0/24" private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id - nameserver_addresses = "192.168.1.8" + nameserver_addresses = ["192.168.1.8"] } ``` @@ -67,7 +67,7 @@ The following example is for creating an IP pool that belongs to a Private Cloud private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id ip_start_range = "192.168.1.10" ip_end_range = "192.168.1.100" - nameserver_addresses = "192.168.1.8" + nameserver_addresses = ["192.168.1.8"] restrict_to_single_cluster = true context = "tenant" } diff --git a/templates/resources/privatecloudgateway_ippool.md.tmpl b/templates/resources/privatecloudgateway_ippool.md.tmpl index bf547c38..73239373 100644 --- a/templates/resources/privatecloudgateway_ippool.md.tmpl +++ b/templates/resources/privatecloudgateway_ippool.md.tmpl @@ -28,7 +28,7 @@ An example of creating an IP Pool for a Private Cloud Gateway using a range of I private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id ip_start_range = "192.168.1.10" ip_end_range = "192.168.1.100" - nameserver_addresses = "192.168.1.8" + nameserver_addresses = ["192.168.1.8"] restrict_to_single_cluster = true } ``` @@ -48,7 +48,7 @@ An example of creating an IP Pool for a Private Cloud Gateway using a subnet of prefix = "24" subnet_cidr = "10.10.100.0/24" private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id - nameserver_addresses = "192.168.1.8" + nameserver_addresses = ["192.168.1.8"] } ``` @@ -67,7 +67,7 @@ The following example is for creating an IP pool that belongs to a Private Cloud private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id ip_start_range = "192.168.1.10" ip_end_range = "192.168.1.100" - nameserver_addresses = "192.168.1.8" + nameserver_addresses = ["192.168.1.8"] restrict_to_single_cluster = true context = "tenant" } From 2156c6cb3c192c3c590ab5869408ce237bc28223 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Fri, 13 Sep 2024 07:09:43 -0600 Subject: [PATCH 5/5] docs: remove example with context Signed-off-by: Tyler Gillson --- docs/resources/privatecloudgateway_ippool.md | 22 ------------------- .../privatecloudgateway_ippool.md.tmpl | 22 ------------------- 2 files changed, 44 deletions(-) diff --git a/docs/resources/privatecloudgateway_ippool.md b/docs/resources/privatecloudgateway_ippool.md index c84ecb3c..7d0a3980 100644 --- a/docs/resources/privatecloudgateway_ippool.md +++ b/docs/resources/privatecloudgateway_ippool.md @@ -52,28 +52,6 @@ An example of creating an IP Pool for a Private Cloud Gateway using a subnet of } ``` -The following example is for creating an IP pool that belongs to a Private Cloud Gateway created at the tenant scope. - -```hcl - data "spectrocloud_private_cloud_gateway" "pcg" { - name = "tenant-pcg" - } - - resource "spectrocloud_privatecloudgateway_ippool" "ippool" { - gateway = "192.168.1.1" - name = "tenant-compute-pool-1" - network_type = "range" - prefix = "24" - private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id - ip_start_range = "192.168.1.10" - ip_end_range = "192.168.1.100" - nameserver_addresses = ["192.168.1.8"] - restrict_to_single_cluster = true - context = "tenant" - } -``` - - ## Schema diff --git a/templates/resources/privatecloudgateway_ippool.md.tmpl b/templates/resources/privatecloudgateway_ippool.md.tmpl index 73239373..236f54ca 100644 --- a/templates/resources/privatecloudgateway_ippool.md.tmpl +++ b/templates/resources/privatecloudgateway_ippool.md.tmpl @@ -52,27 +52,5 @@ An example of creating an IP Pool for a Private Cloud Gateway using a subnet of } ``` -The following example is for creating an IP pool that belongs to a Private Cloud Gateway created at the tenant scope. - -```hcl - data "spectrocloud_private_cloud_gateway" "pcg" { - name = "tenant-pcg" - } - - resource "spectrocloud_privatecloudgateway_ippool" "ippool" { - gateway = "192.168.1.1" - name = "tenant-compute-pool-1" - network_type = "range" - prefix = "24" - private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id - ip_start_range = "192.168.1.10" - ip_end_range = "192.168.1.100" - nameserver_addresses = ["192.168.1.8"] - restrict_to_single_cluster = true - context = "tenant" - } -``` - - {{ .SchemaMarkdown | trimspace }} \ No newline at end of file