From 1e04c1a0595771d285cdd6fb281f3a7415449ef0 Mon Sep 17 00:00:00 2001 From: Zhen Jian <33081474+happyjian97@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:57:53 +0800 Subject: [PATCH] Rename resources (#8) --- cdnetworks/provider.go | 4 +- ...> resource_content_acceleration_domain.go} | 52 +++++++++---------- ...ain.go => resource_flood_shield_domain.go} | 50 +++++++++--------- 3 files changed, 53 insertions(+), 53 deletions(-) rename cdnetworks/{resource_shield_domain.go => resource_content_acceleration_domain.go} (70%) rename cdnetworks/{resource_cdn_domain.go => resource_flood_shield_domain.go} (73%) diff --git a/cdnetworks/provider.go b/cdnetworks/provider.go index 7d515e8..9d88b5c 100644 --- a/cdnetworks/provider.go +++ b/cdnetworks/provider.go @@ -161,8 +161,8 @@ func (p *cdnetworksProvider) DataSources(_ context.Context) []func() datasource. func (p *cdnetworksProvider) Resources(_ context.Context) []func() resource.Resource { return []func() resource.Resource{ NewSslCertificateResource, - NewCdnDomainResource, - NewShieldDomainResource, + NewContentAccelerationDomainResource, + NewFloodShieldDomainResource, NewDomainSslAssociationResource, NewHttpHeaderConfigResource, NewHttp2SettingsConfigResource, diff --git a/cdnetworks/resource_shield_domain.go b/cdnetworks/resource_content_acceleration_domain.go similarity index 70% rename from cdnetworks/resource_shield_domain.go rename to cdnetworks/resource_content_acceleration_domain.go index 1a1bf05..78d9b93 100644 --- a/cdnetworks/resource_shield_domain.go +++ b/cdnetworks/resource_content_acceleration_domain.go @@ -14,37 +14,37 @@ import ( "github.com/myklst/terraform-provider-st-cdnetworks/cdnetworksapi" ) -type shieldDomainResource struct { +type contentAccelerationDomainResource struct { client *cdnetworksapi.Client } var ( - _ resource.Resource = &shieldDomainResource{} - _ resource.ResourceWithConfigure = &shieldDomainResource{} - _ resource.ResourceWithImportState = &shieldDomainResource{} - _ resource.ResourceWithModifyPlan = &shieldDomainResource{} + _ resource.Resource = &contentAccelerationDomainResource{} + _ resource.ResourceWithConfigure = &contentAccelerationDomainResource{} + _ resource.ResourceWithImportState = &contentAccelerationDomainResource{} + _ resource.ResourceWithModifyPlan = &contentAccelerationDomainResource{} ) -func NewShieldDomainResource() resource.Resource { - return &shieldDomainResource{} +func NewContentAccelerationDomainResource() resource.Resource { + return &contentAccelerationDomainResource{} } -func (r *shieldDomainResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_shield_domain" +func (r *contentAccelerationDomainResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_content_acceleration_domain" } -func (r *shieldDomainResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *contentAccelerationDomainResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = DomainSchema } -func (r *shieldDomainResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *contentAccelerationDomainResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { if req.ProviderData == nil { return } r.client = req.ProviderData.(*cdnetworksapi.Client) } -func (r *shieldDomainResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *contentAccelerationDomainResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var model *DomainResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &model)...) @@ -65,7 +65,7 @@ func (r *shieldDomainResource) Create(ctx context.Context, req resource.CreateRe addCdnDomainResponse, err := r.client.AddCdnDomain(addCdnDomainRequest) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Add Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Add Content Acceleration Domain", err.Error()) return } @@ -92,7 +92,7 @@ func (r *shieldDomainResource) Create(ctx context.Context, req resource.CreateRe // Required as copying computedFields from queryResponse. queryCdnDomainResponse, err := r.client.QueryCdnDomain(model.DomainId.ValueString()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Query Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Query Content Acceleration Domain", err.Error()) return } model.CopyComputedFields(&queryCdnDomainResponse) @@ -100,7 +100,7 @@ func (r *shieldDomainResource) Create(ctx context.Context, req resource.CreateRe resp.State.Set(ctx, model) } -func (r *shieldDomainResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *contentAccelerationDomainResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var model *DomainResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &model)...) if resp.Diagnostics.HasError() { @@ -119,7 +119,7 @@ func (r *shieldDomainResource) Read(ctx context.Context, req resource.ReadReques if err != nil { if cdnErr, ok := err.(*cdnetworksapi.ErrorResponse); ok { if cdnErr.ResponseCode == "WRONG_OPERATOR" { - resp.Diagnostics.AddWarning("[Call API] Trying to bind CDN Domain to Control Group.", fmt.Sprintf("Domain: %s", model.Domain.ValueString())) + resp.Diagnostics.AddWarning("[Call API] Trying to bind Content Acceleration Domain to Control Group.", fmt.Sprintf("Domain: %s", model.Domain.ValueString())) // Bind CDN domains to ControlGroup, in case previous bind action doesn't complete. // Prevent error from Read(), Create() might failed to bind into controlGroup. err := r.bindCdnDomainToControlGroup(model) @@ -141,13 +141,13 @@ func (r *shieldDomainResource) Read(ctx context.Context, req resource.ReadReques err := backoff.Retry(queryCdnDomain, backoff.NewExponentialBackOff()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Query Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Query Content Acceleration Domain", err.Error()) } resp.Diagnostics.Append(resp.State.Set(ctx, &model)...) } -func (r *shieldDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *contentAccelerationDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var state, plan DomainResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if resp.Diagnostics.HasError() { @@ -169,7 +169,7 @@ func (r *shieldDomainResource) Update(ctx context.Context, req resource.UpdateRe } _, err := r.client.UpdateCdnDomain(plan.DomainId.ValueString(), updateCdnDomainRequest) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Update Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Update Content Acceleration Domain", err.Error()) return } } else if plan.Enabled.Equal(state.Enabled) { @@ -186,7 +186,7 @@ func (r *shieldDomainResource) Update(ctx context.Context, req resource.UpdateRe _, err = r.client.DisableDomain(plan.DomainId.ValueString()) } if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Enable/Disable Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Enable/Disable Content Acceleration Domain", err.Error()) return } } @@ -199,7 +199,7 @@ func (r *shieldDomainResource) Update(ctx context.Context, req resource.UpdateRe queryCdnDomainResponse, err := r.client.QueryCdnDomain(plan.DomainId.ValueString()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Query Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Query Content Acceleration Domain", err.Error()) return } plan.CopyComputedFields(&queryCdnDomainResponse) @@ -207,7 +207,7 @@ func (r *shieldDomainResource) Update(ctx context.Context, req resource.UpdateRe resp.State.Set(ctx, plan) } -func (r *shieldDomainResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *contentAccelerationDomainResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var model *DomainResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &model)...) @@ -217,7 +217,7 @@ func (r *shieldDomainResource) Delete(ctx context.Context, req resource.DeleteRe _, err := r.client.DeleteApiDomain(model.DomainId.ValueString()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Delete Shield Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Delete Content Acceleration Domain", err.Error()) return } @@ -228,11 +228,11 @@ func (r *shieldDomainResource) Delete(ctx context.Context, req resource.DeleteRe } } -func (r *shieldDomainResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *contentAccelerationDomainResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("domain"), req, resp) } -func (r *shieldDomainResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { +func (r *contentAccelerationDomainResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var plan *DomainResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if plan == nil { @@ -247,7 +247,7 @@ func (r *shieldDomainResource) ModifyPlan(ctx context.Context, req resource.Modi resp.Plan.Set(ctx, plan) } -func (r *shieldDomainResource) bindCdnDomainToControlGroup(model *DomainResourceModel) (err error) { +func (r *contentAccelerationDomainResource) bindCdnDomainToControlGroup(model *DomainResourceModel) (err error) { _, err = r.client.EditControlGroup(model.BuildEditControlGroupRequest()) if err != nil { return err diff --git a/cdnetworks/resource_cdn_domain.go b/cdnetworks/resource_flood_shield_domain.go similarity index 73% rename from cdnetworks/resource_cdn_domain.go rename to cdnetworks/resource_flood_shield_domain.go index 65c425f..bb0cfe8 100644 --- a/cdnetworks/resource_cdn_domain.go +++ b/cdnetworks/resource_flood_shield_domain.go @@ -14,37 +14,37 @@ import ( "github.com/myklst/terraform-provider-st-cdnetworks/cdnetworksapi" ) -type cdnDomainResource struct { +type floodShieldDomainResource struct { client *cdnetworksapi.Client } var ( - _ resource.Resource = &cdnDomainResource{} - _ resource.ResourceWithConfigure = &cdnDomainResource{} - _ resource.ResourceWithImportState = &cdnDomainResource{} - _ resource.ResourceWithModifyPlan = &cdnDomainResource{} + _ resource.Resource = &floodShieldDomainResource{} + _ resource.ResourceWithConfigure = &floodShieldDomainResource{} + _ resource.ResourceWithImportState = &floodShieldDomainResource{} + _ resource.ResourceWithModifyPlan = &floodShieldDomainResource{} ) -func NewCdnDomainResource() resource.Resource { - return &cdnDomainResource{} +func NewFloodShieldDomainResource() resource.Resource { + return &floodShieldDomainResource{} } -func (r *cdnDomainResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_cdn_domain" +func (r *floodShieldDomainResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_flood_shield_domain" } -func (r *cdnDomainResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *floodShieldDomainResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = DomainSchema } -func (r *cdnDomainResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *floodShieldDomainResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { if req.ProviderData == nil { return } r.client = req.ProviderData.(*cdnetworksapi.Client) } -func (r *cdnDomainResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *floodShieldDomainResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var model *DomainResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &model)...) @@ -65,7 +65,7 @@ func (r *cdnDomainResource) Create(ctx context.Context, req resource.CreateReque addCdnDomainResponse, err := r.client.AddCdnDomain(addCdnDomainRequest) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Add CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Add Flood Shield Domain", err.Error()) return } @@ -92,7 +92,7 @@ func (r *cdnDomainResource) Create(ctx context.Context, req resource.CreateReque // Required as copying computedFields from queryResponse. queryCdnDomainResponse, err := r.client.QueryCdnDomain(model.DomainId.ValueString()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Query CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Query Flood Shield Domain", err.Error()) return } model.CopyComputedFields(&queryCdnDomainResponse) @@ -100,7 +100,7 @@ func (r *cdnDomainResource) Create(ctx context.Context, req resource.CreateReque resp.State.Set(ctx, model) } -func (r *cdnDomainResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *floodShieldDomainResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var model *DomainResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &model)...) if resp.Diagnostics.HasError() { @@ -141,13 +141,13 @@ func (r *cdnDomainResource) Read(ctx context.Context, req resource.ReadRequest, err := backoff.Retry(queryCdnDomain, backoff.NewExponentialBackOff()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Query CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Query Flood Shield Domain", err.Error()) } resp.Diagnostics.Append(resp.State.Set(ctx, &model)...) } -func (r *cdnDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *floodShieldDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var state, plan DomainResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if resp.Diagnostics.HasError() { @@ -169,7 +169,7 @@ func (r *cdnDomainResource) Update(ctx context.Context, req resource.UpdateReque } _, err := r.client.UpdateCdnDomain(plan.DomainId.ValueString(), updateCdnDomainRequest) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Update CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Update Flood Shield Domain", err.Error()) return } } else if plan.Enabled.Equal(state.Enabled) { @@ -186,7 +186,7 @@ func (r *cdnDomainResource) Update(ctx context.Context, req resource.UpdateReque _, err = r.client.DisableDomain(plan.DomainId.ValueString()) } if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Enable/Disable CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Enable/Disable Flood Shield Domain", err.Error()) return } } @@ -199,7 +199,7 @@ func (r *cdnDomainResource) Update(ctx context.Context, req resource.UpdateReque queryCdnDomainResponse, err := r.client.QueryCdnDomain(plan.DomainId.ValueString()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Query CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Query Flood Shield Domain", err.Error()) return } plan.CopyComputedFields(&queryCdnDomainResponse) @@ -207,7 +207,7 @@ func (r *cdnDomainResource) Update(ctx context.Context, req resource.UpdateReque resp.State.Set(ctx, plan) } -func (r *cdnDomainResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *floodShieldDomainResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var model *DomainResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &model)...) @@ -217,7 +217,7 @@ func (r *cdnDomainResource) Delete(ctx context.Context, req resource.DeleteReque _, err := r.client.DeleteApiDomain(model.DomainId.ValueString()) if err != nil { - resp.Diagnostics.AddError("[API ERROR] Fail to Delete CDN Domain", err.Error()) + resp.Diagnostics.AddError("[API ERROR] Fail to Delete Flood Shield Domain", err.Error()) return } @@ -228,11 +228,11 @@ func (r *cdnDomainResource) Delete(ctx context.Context, req resource.DeleteReque } } -func (r *cdnDomainResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *floodShieldDomainResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("domain"), req, resp) } -func (r *cdnDomainResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { +func (r *floodShieldDomainResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var plan *DomainResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) if plan == nil { @@ -247,7 +247,7 @@ func (r *cdnDomainResource) ModifyPlan(ctx context.Context, req resource.ModifyP resp.Plan.Set(ctx, plan) } -func (r *cdnDomainResource) bindCdnDomainToControlGroup(model *DomainResourceModel) (err error) { +func (r *floodShieldDomainResource) bindCdnDomainToControlGroup(model *DomainResourceModel) (err error) { _, err = r.client.EditControlGroup(model.BuildEditControlGroupRequest()) if err != nil { return err