Skip to content

Commit

Permalink
Restore timeout and regenerate docs
Browse files Browse the repository at this point in the history
Signed-off-by: Stoyan Zhelyazkov <[email protected]>
  • Loading branch information
spacegospod committed Jun 20, 2024
1 parent 8c21e82 commit 2087e5e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
9 changes: 5 additions & 4 deletions docs/resources/network_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ The following data is prerequisite for creating a new Network Pool

### Optional

- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `network` (Block List) Represents a network in a network pool (see [below for nested schema](#nestedblock--network))
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `id` (String) The ID of this resource.
- `id` (String) Service generated identifier for the network pool.

<a id="nestedblock--network"></a>
### Nested Schema for `network`
Expand Down Expand Up @@ -67,9 +68,9 @@ Optional:



<a id="nestedblock--timeouts"></a>
<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String)
- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-framework v1.9.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.16.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ github.com/hashicorp/terraform-plugin-docs v0.19.4 h1:G3Bgo7J22OMtegIgn8Cd/CaSey
github.com/hashicorp/terraform-plugin-docs v0.19.4/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA=
github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU=
github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=
Expand Down
20 changes: 16 additions & 4 deletions internal/provider/resource_network_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package provider

import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/vmware/vcf-sdk-go/client/network_pools"
"github.com/vmware/vcf-sdk-go/models"
"log"
"time"
)

type IpPoolModel struct {
Expand All @@ -39,9 +41,10 @@ type NetworkModel struct {
}

type ResourceNetworkPoolModel struct {
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Networks types.List `tfsdk:"network"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Networks types.List `tfsdk:"network"`
}

type ResourceNetworkPool struct {
Expand All @@ -66,6 +69,9 @@ func (r *ResourceNetworkPool) ImportState(ctx context.Context, req resource.Impo
func (r *ResourceNetworkPool) Schema(ctx context.Context, req resource.SchemaRequest, res *resource.SchemaResponse) {
res.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
Create: true,
}),
"id": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Service generated identifier for the network pool.",
Expand Down Expand Up @@ -128,7 +134,7 @@ func (r *ResourceNetworkPool) Schema(ctx context.Context, req resource.SchemaReq
},
"end": schema.StringAttribute{
Optional: true,
Description: "Start IP address of the IP pool",
Description: "End IP address of the IP pool",
},
},
},
Expand Down Expand Up @@ -181,6 +187,12 @@ func (r *ResourceNetworkPool) Create(ctx context.Context, req resource.CreateReq

createParams.NetworkPool = &networkPool

timeout, diags := data.Timeouts.Create(ctx, 30*time.Minute)
res.Diagnostics.Append(diags...)

ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

_, created, err := r.client.NetworkPools.CreateNetworkPool(createParams)
if err != nil {
res.Diagnostics.Append(diag.NewErrorDiagnostic("Failed to create network pool", err.Error()))
Expand Down

0 comments on commit 2087e5e

Please sign in to comment.