diff --git a/CHANGELOG.md b/CHANGELOG.md index 141fa18..46ce174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.1.14 (unreleased) - Use `set` type for list attributes with primitive values +- Implement workaround for API issue when creating multiple network device groups at once ## 0.1.13 diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 9bdcb9e..4a7b7bb 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -10,6 +10,7 @@ description: |- ## 0.1.14 (unreleased) - Use `set` type for list attributes with primitive values +- Implement workaround for API issue when creating multiple network device groups at once ## 0.1.13 diff --git a/gen/templates/provider.go b/gen/templates/provider.go index a35340c..166eda1 100644 --- a/gen/templates/provider.go +++ b/gen/templates/provider.go @@ -57,7 +57,7 @@ type IseProviderModel struct { // IseProviderData describes the data maintained by the provider. type IseProviderData struct { Client *ise.Client - UpdateMutex *sync.Mutex + NetworkDeviceGroupMutex *sync.Mutex } // Metadata returns the provider type name. @@ -236,7 +236,7 @@ func (p *IseProvider) Configure(ctx context.Context, req provider.ConfigureReque return } - data := IseProviderData{Client: &c, UpdateMutex: &sync.Mutex{}} + data := IseProviderData{Client: &c, NetworkDeviceGroupMutex: &sync.Mutex{}} resp.DataSourceData = &data resp.ResourceData = &data } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index b21f3c0..5197bbc 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -55,8 +55,8 @@ type IseProviderModel struct { // IseProviderData describes the data maintained by the provider. type IseProviderData struct { - Client *ise.Client - UpdateMutex *sync.Mutex + Client *ise.Client + NetworkDeviceGroupMutex *sync.Mutex } // Metadata returns the provider type name. @@ -235,7 +235,7 @@ func (p *IseProvider) Configure(ctx context.Context, req provider.ConfigureReque return } - data := IseProviderData{Client: &c, UpdateMutex: &sync.Mutex{}} + data := IseProviderData{Client: &c, NetworkDeviceGroupMutex: &sync.Mutex{}} resp.DataSourceData = &data resp.ResourceData = &data } diff --git a/internal/provider/resource_ise_network_device_group.go b/internal/provider/resource_ise_network_device_group.go index ee7533e..32fe218 100644 --- a/internal/provider/resource_ise_network_device_group.go +++ b/internal/provider/resource_ise_network_device_group.go @@ -19,12 +19,13 @@ package provider -//template:begin imports import ( "context" "fmt" "net/url" "strings" + "sync" + "time" "github.com/CiscoDevNet/terraform-provider-ise/internal/provider/helpers" "github.com/hashicorp/terraform-plugin-framework/path" @@ -37,10 +38,6 @@ import ( "github.com/netascode/go-ise" ) -//template:end imports - -//template:begin header - // Ensure provider defined types fully satisfy framework interfaces var _ resource.Resource = &NetworkDeviceGroupResource{} var _ resource.ResourceWithImportState = &NetworkDeviceGroupResource{} @@ -50,15 +47,14 @@ func NewNetworkDeviceGroupResource() resource.Resource { } type NetworkDeviceGroupResource struct { - client *ise.Client + client *ise.Client + networkDeviceGroupMutex *sync.Mutex } func (r *NetworkDeviceGroupResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_network_device_group" } -//template:end header - //template:begin model func (r *NetworkDeviceGroupResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ @@ -91,18 +87,15 @@ func (r *NetworkDeviceGroupResource) Schema(ctx context.Context, req resource.Sc //template:end model -//template:begin configure func (r *NetworkDeviceGroupResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { if req.ProviderData == nil { return } r.client = req.ProviderData.(*IseProviderData).Client + r.networkDeviceGroupMutex = req.ProviderData.(*IseProviderData).NetworkDeviceGroupMutex } -//template:end configure - -//template:begin create func (r *NetworkDeviceGroupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var plan NetworkDeviceGroup @@ -116,6 +109,8 @@ func (r *NetworkDeviceGroupResource) Create(ctx context.Context, req resource.Cr tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object + r.networkDeviceGroupMutex.Lock() + defer r.networkDeviceGroupMutex.Unlock() body := plan.toBody(ctx, NetworkDeviceGroup{}) res, location, err := r.client.Post(plan.getPath(), body) if err != nil { @@ -125,14 +120,14 @@ func (r *NetworkDeviceGroupResource) Create(ctx context.Context, req resource.Cr locationElements := strings.Split(location, "/") plan.Id = types.StringValue(locationElements[len(locationElements)-1]) + time.Sleep(5 * time.Second) + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Id.ValueString())) diags = resp.State.Set(ctx, &plan) resp.Diagnostics.Append(diags...) } -//template:end create - //template:begin read func (r *NetworkDeviceGroupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var state NetworkDeviceGroup diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 9bdcb9e..4a7b7bb 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -10,6 +10,7 @@ description: |- ## 0.1.14 (unreleased) - Use `set` type for list attributes with primitive values +- Implement workaround for API issue when creating multiple network device groups at once ## 0.1.13