Skip to content

Commit

Permalink
fix: Resources should be recreated when removed outside of Terraform (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm authored Sep 27, 2024
1 parent b9eda25 commit 2a3124d
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 15 deletions.
8 changes: 7 additions & 1 deletion internal/resource_digitalcertificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -234,8 +235,13 @@ func (r *digitalCertificateResource) Read(ctx context.Context, req resource.Read
}
}

certificateResponse, response, err := r.client.digitalCertificatesApi.RetrieveDigitalCertificateByIDApi.GetCertificate(ctx, CertificateID).Execute() //nolint
certificateResponse, response, err := r.client.digitalCertificatesApi.
RetrieveDigitalCertificateByIDApi.GetCertificate(ctx, CertificateID).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_dnssec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -207,7 +208,8 @@ func (r *dnssecResource) Create(ctx context.Context, req resource.CreateRequest,
}
}

func (r *dnssecResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
func (r *dnssecResource) Read(
ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var state dnssecResourceModel
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
Expand All @@ -232,6 +234,10 @@ func (r *dnssecResource) Read(ctx context.Context, req resource.ReadRequest, res
getDnsSec, response, err := r.client.idnsApi.DNSSECAPI.
GetZoneDnsSec(ctx, zoneID32).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -212,8 +213,13 @@ func (r *domainResource) Read(ctx context.Context, req resource.ReadRequest, res
domainId = state.ID.ValueString()
}

getDomain, response, err := r.client.domainsApi.DomainsAPI.GetDomain(ctx, domainId).Execute() //nolint
getDomain, response, err := r.client.domainsApi.DomainsAPI.
GetDomain(ctx, domainId).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_edgeFunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -249,8 +250,13 @@ func (r *edgeFunctionResource) Read(ctx context.Context, req resource.ReadReques
}
}

getEdgeFunction, response, err := r.client.edgefunctionsApi.EdgeFunctionsAPI.EdgeFunctionsIdGet(ctx, edgeFunctionId).Execute() //nolint
getEdgeFunction, response, err := r.client.edgefunctionsApi.EdgeFunctionsAPI.
EdgeFunctionsIdGet(ctx, edgeFunctionId).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
10 changes: 9 additions & 1 deletion internal/resource_edge_application_cache_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -420,8 +421,15 @@ func (r *edgeApplicationCacheSettingsResource) Read(ctx context.Context, req res
return
}

cacheSettingResponse, response, err := r.client.edgeApplicationsApi.EdgeApplicationsCacheSettingsAPI.EdgeApplicationsEdgeApplicationIdCacheSettingsCacheSettingsIdGet(ctx, EdgeApplicationId, CacheSettingId).Execute() //nolint
cacheSettingResponse, response, err := r.client.edgeApplicationsApi.
EdgeApplicationsCacheSettingsAPI.
EdgeApplicationsEdgeApplicationIdCacheSettingsCacheSettingsIdGet(
ctx, EdgeApplicationId, CacheSettingId).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
10 changes: 9 additions & 1 deletion internal/resource_edge_application_edge_functions_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -220,8 +221,15 @@ func (r *edgeFunctionsInstanceResource) Read(ctx context.Context, req resource.R
return
}

edgeFunctionInstancesResponse, response, err := r.client.edgeApplicationsApi.EdgeApplicationsEdgeFunctionsInstancesAPI.EdgeApplicationsEdgeApplicationIdFunctionsInstancesFunctionsInstancesIdGet(ctx, ApplicationID, functionsInstancesId).Execute() //nolint
edgeFunctionInstancesResponse, response, err := r.client.edgeApplicationsApi.
EdgeApplicationsEdgeFunctionsInstancesAPI.
EdgeApplicationsEdgeApplicationIdFunctionsInstancesFunctionsInstancesIdGet(
ctx, ApplicationID, functionsInstancesId).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
5 changes: 5 additions & 0 deletions internal/resource_edge_application_main_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -367,6 +368,10 @@ func (r *edgeApplicationResource) Read(ctx context.Context, req resource.ReadReq
EdgeApplicationsMainSettingsAPI.
EdgeApplicationsIdGet(ctx, state.ID.ValueString()).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
9 changes: 8 additions & 1 deletion internal/resource_edge_application_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -367,8 +368,14 @@ func (r *originResource) Read(ctx context.Context, req resource.ReadRequest, res
return
}

originResponse, response, err := r.client.edgeApplicationsApi.EdgeApplicationsOriginsAPI.EdgeApplicationsEdgeApplicationIdOriginsOriginKeyGet(ctx, ApplicationID, OriginKey).Execute() //nolint
originResponse, response, err := r.client.edgeApplicationsApi.
EdgeApplicationsOriginsAPI.EdgeApplicationsEdgeApplicationIdOriginsOriginKeyGet(
ctx, ApplicationID, OriginKey).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
9 changes: 8 additions & 1 deletion internal/resource_edge_application_rule_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,15 @@ func (r *rulesEngineResource) Read(ctx context.Context, req resource.ReadRequest
phase = "request"
}

ruleEngineResponse, response, err := r.client.edgeApplicationsApi.EdgeApplicationsRulesEngineAPI.EdgeApplicationsEdgeApplicationIdRulesEnginePhaseRulesRuleIdGet(ctx, edgeApplicationID, phase, ruleID).Execute() //nolint
ruleEngineResponse, response, err := r.client.edgeApplicationsApi.
EdgeApplicationsRulesEngineAPI.
EdgeApplicationsEdgeApplicationIdRulesEnginePhaseRulesRuleIdGet(
ctx, edgeApplicationID, phase, ruleID).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
12 changes: 9 additions & 3 deletions internal/resource_edge_firewall_edge_functions_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -230,10 +231,15 @@ func (r *edgeFirewallFunctionsInstanceResource) Read(ctx context.Context, req re
return
}

edgeFunctionInstancesResponse, response, err := r.client.edgefunctionsinstanceEdgefirewallApi.DefaultAPI.
EdgeFirewallEdgeFirewallIdFunctionsInstancesEdgeFunctionInstanceIdGet(ctx, edgeFirewallID, functionsInstancesId).
Execute() //nolint
edgeFunctionInstancesResponse, response, err := r.client.
edgefunctionsinstanceEdgefirewallApi.DefaultAPI.
EdgeFirewallEdgeFirewallIdFunctionsInstancesEdgeFunctionInstanceIdGet(
ctx, edgeFirewallID, functionsInstancesId).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_edge_firewall_main_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -217,8 +218,13 @@ func (r *edgeFirewallResource) Read(ctx context.Context, req resource.ReadReques
edgeFirewallID = state.ID.ValueString()
}

edgeFirewallResponse, response, err := r.client.edgeFirewallApi.DefaultAPI.EdgeFirewallUuidGet(ctx, edgeFirewallID).Execute() //nolint
edgeFirewallResponse, response, err := r.client.edgeFirewallApi.DefaultAPI.
EdgeFirewallUuidGet(ctx, edgeFirewallID).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"time"

"github.com/aziontech/azionapi-go-sdk/variables"
Expand Down Expand Up @@ -193,8 +194,13 @@ func (r *environmentVariableResource) Read(ctx context.Context, req resource.Rea
uuid = state.ID.ValueString()
}

getEnvironmentVariable, response, err := r.client.variablesApi.VariablesAPI.ApiVariablesRetrieve(ctx, uuid).Execute() //nolint
getEnvironmentVariable, response, err := r.client.variablesApi.VariablesAPI.
ApiVariablesRetrieve(ctx, uuid).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_network_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -196,8 +197,13 @@ func (r *networkListResource) Read(ctx context.Context, req resource.ReadRequest
networkListId = state.ID.ValueString()
}

getNetworkList, response, err := r.client.networkListApi.DefaultAPI.NetworkListsUuidGet(ctx, networkListId).Execute() //nolint
getNetworkList, response, err := r.client.networkListApi.DefaultAPI.
NetworkListsUuidGet(ctx, networkListId).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
8 changes: 7 additions & 1 deletion internal/resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -263,8 +264,13 @@ func (r *recordResource) Read(ctx context.Context, req resource.ReadRequest, res
idRecord = utils.AtoiNoError(valueFromCmd[1], resp)
}

recordsResponse, httpResponse, err := r.client.idnsApi.RecordsAPI.GetZoneRecords(ctx, idZone).PageSize(largeRecordsPageSize).Execute() //nolint
recordsResponse, httpResponse, err := r.client.idnsApi.RecordsAPI.
GetZoneRecords(ctx, idZone).PageSize(largeRecordsPageSize).Execute() //nolint
if err != nil {
if httpResponse.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
usrMsg, errMsg := errorPrint(httpResponse.StatusCode, err)
resp.Diagnostics.AddError(usrMsg, errMsg)
return
Expand Down
5 changes: 5 additions & 0 deletions internal/resource_waf_rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -295,6 +296,10 @@ func (r *wafRuleSetResource) Read(ctx context.Context, req resource.ReadRequest,

wafResponse, response, err := r.client.wafApi.WAFAPI.GetWAFRuleset(ctx, wafRuleSetID).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down
5 changes: 5 additions & 0 deletions internal/resource_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"io"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -210,6 +211,10 @@ func (r *zoneResource) Read(ctx context.Context, req resource.ReadRequest, resp

order, response, err := r.client.idnsApi.ZonesAPI.GetZone(ctx, int32(idPlan)).Execute() //nolint
if err != nil {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
bodyBytes, errReadAll := io.ReadAll(response.Body)
if errReadAll != nil {
resp.Diagnostics.AddError(
Expand Down

0 comments on commit 2a3124d

Please sign in to comment.