diff --git a/docs/resources/service_compute.md b/docs/resources/service_compute.md index c9e915a22..b2a8ac3c6 100644 --- a/docs/resources/service_compute.md +++ b/docs/resources/service_compute.md @@ -111,6 +111,7 @@ $ terraform import fastly_service_compute.demo xxxxxxxxxxxxxxxxxxxx@2 - `active_version` (Number) The currently active version of your Fastly Service - `cloned_version` (Number) The latest cloned version by the provider +- `force_refresh` (Boolean) Used internally by the provider to temporarily indicate if all resources should call their associated API to update the local state. This is for scenarios where the service version has been reverted outside of Terraform (e.g. via the Fastly UI) and the provider needs to resync the state for a different active version (this is only if `activate` is `true`). - `id` (String) The ID of this resource. - `imported` (Boolean) Used internally by the provider to temporarily indicate if the service is being imported, and is reset to false once the import is finished diff --git a/docs/resources/service_vcl.md b/docs/resources/service_vcl.md index 1b343ae13..e85bd21c5 100644 --- a/docs/resources/service_vcl.md +++ b/docs/resources/service_vcl.md @@ -294,6 +294,7 @@ $ terraform import fastly_service_vcl.demo xxxxxxxxxxxxxxxxxxxx@2 - `active_version` (Number) The currently active version of your Fastly Service - `cloned_version` (Number) The latest cloned version by the provider +- `force_refresh` (Boolean) Used internally by the provider to temporarily indicate if all resources should call their associated API to update the local state. This is for scenarios where the service version has been reverted outside of Terraform (e.g. via the Fastly UI) and the provider needs to resync the state for a different active version (this is only if `activate` is `true`). - `id` (String) The ID of this resource. - `imported` (Boolean) Used internally by the provider to temporarily indicate if the service is being imported, and is reset to false once the import is finished diff --git a/fastly/base_fastly_service.go b/fastly/base_fastly_service.go index 517e19d83..8e3aeea7b 100644 --- a/fastly/base_fastly_service.go +++ b/fastly/base_fastly_service.go @@ -116,6 +116,11 @@ func resourceService(serviceDef ServiceDefinition) *schema.Resource { Description: "Services that are active cannot be destroyed. In order to destroy the Service, set `force_destroy` to `true`. Default `false`", ConflictsWith: []string{"reuse"}, }, + "force_refresh": { + Type: schema.TypeBool, + Computed: true, + Description: "Used internally by the provider to temporarily indicate if all resources should call their associated API to update the local state. This is for scenarios where the service version has been reverted outside of Terraform (e.g. via the Fastly UI) and the provider needs to resync the state for a different active version (this is only if `activate` is `true`).", + }, "imported": { Type: schema.TypeBool, Computed: true, @@ -452,6 +457,35 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta any, if err != nil { return diag.FromErr(err) } + + var activeVersionFromPriorState int + if i := d.Get("active_version"); i != nil { + activeVersionFromPriorState = i.(int) + } + + var activate bool + if i := d.Get("activate"); i != nil { + activate = i.(bool) + } + + // If the user has reverted a service version via the Fastly UI, then the + // active version of the service will no longer match the version being + // tracked in the state file. This means we can use this information to help + // force each nested service resource to call its API to update the state. + // + // REFERENCE: + // https://github.com/fastly/terraform-provider-fastly/issues/629 + // + // NOTE: We only force a refresh if `activate = true` in config. + // This is because if the user has set it to false, then the expectation is + // for the version to drift and so there will be no active version to use. + if activeVersionFromPriorState != s.ActiveVersion.Number && activate { + err = d.Set("force_refresh", true) + if err != nil { + return diag.FromErr(err) + } + } + err = d.Set("active_version", s.ActiveVersion.Number) if err != nil { return diag.FromErr(err) @@ -528,13 +562,19 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta any, } // To ensure nested resources (e.g. backends, domains etc) don't continue to - // call the API to refresh the internal Terraform state, once an import is - // complete, we reset the 'imported' computed attribute to false. + // call the API to refresh the internal Terraform state, once an import or a + // forced refresh is complete, we reset both the 'imported' and + // 'force_refresh' computed attributes back to false. err = d.Set("imported", false) if err != nil { return diag.FromErr(err) } + err = d.Set("force_refresh", false) + if err != nil { + return diag.FromErr(err) + } + return diags } diff --git a/fastly/block_fastly_service_acl.go b/fastly/block_fastly_service_acl.go index 42b0b6d73..2146611d6 100644 --- a/fastly/block_fastly_service_acl.go +++ b/fastly/block_fastly_service_acl.go @@ -75,7 +75,7 @@ func (h *ACLServiceAttributeHandler) Create(_ context.Context, d *schema.Resourc func (h *ACLServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, latestVersion int, conn *gofastly.Client) error { localState := d.Get(h.Key()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing ACLs for (%s)", d.Id()) remoteState, err := conn.ListACLs(&gofastly.ListACLsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_backend.go b/fastly/block_fastly_service_backend.go index f7eb87a9c..45f3cefce 100644 --- a/fastly/block_fastly_service_backend.go +++ b/fastly/block_fastly_service_backend.go @@ -211,7 +211,7 @@ func (h *BackendServiceAttributeHandler) Create(_ context.Context, d *schema.Res func (h *BackendServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Backends for (%s)", d.Id()) remoteState, err := conn.ListBackends(&gofastly.ListBackendsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_cachesetting.go b/fastly/block_fastly_service_cachesetting.go index 95389441a..8a841bdac 100644 --- a/fastly/block_fastly_service_cachesetting.go +++ b/fastly/block_fastly_service_cachesetting.go @@ -90,7 +90,7 @@ func (h *CacheSettingServiceAttributeHandler) Create(_ context.Context, d *schem func (h *CacheSettingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Cache Settings for (%s)", d.Id()) remoteState, err := conn.ListCacheSettings(&gofastly.ListCacheSettingsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_condition.go b/fastly/block_fastly_service_condition.go index a135abce1..c5236f7de 100644 --- a/fastly/block_fastly_service_condition.go +++ b/fastly/block_fastly_service_condition.go @@ -89,7 +89,7 @@ func (h *ConditionServiceAttributeHandler) Create(_ context.Context, d *schema.R func (h *ConditionServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Conditions for (%s)", d.Id()) remoteState, err := conn.ListConditions(&gofastly.ListConditionsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_dictionary.go b/fastly/block_fastly_service_dictionary.go index 56939fe04..781c23653 100644 --- a/fastly/block_fastly_service_dictionary.go +++ b/fastly/block_fastly_service_dictionary.go @@ -85,7 +85,7 @@ func (h *DictionaryServiceAttributeHandler) Create(_ context.Context, d *schema. func (h *DictionaryServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Dictionaries for (%s)", d.Id()) remoteState, err := conn.ListDictionaries(&gofastly.ListDictionariesInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_director.go b/fastly/block_fastly_service_director.go index b8b3d8a48..755816a7f 100644 --- a/fastly/block_fastly_service_director.go +++ b/fastly/block_fastly_service_director.go @@ -140,7 +140,7 @@ func (h *DirectorServiceAttributeHandler) Create(_ context.Context, d *schema.Re func (h *DirectorServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Directors for (%s)", d.Id()) remoteState, err := conn.ListDirectors(&gofastly.ListDirectorsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_domain.go b/fastly/block_fastly_service_domain.go index f3898eff9..0abffed51 100644 --- a/fastly/block_fastly_service_domain.go +++ b/fastly/block_fastly_service_domain.go @@ -76,7 +76,7 @@ func (h *DomainServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *DomainServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { // TODO: update go-fastly to support an ActiveVersion struct, which contains // domain and backend info in the response. Here we do 2 additional queries // to find out that info diff --git a/fastly/block_fastly_service_dynamicsnippet.go b/fastly/block_fastly_service_dynamicsnippet.go index 579488e43..4bafb853c 100644 --- a/fastly/block_fastly_service_dynamicsnippet.go +++ b/fastly/block_fastly_service_dynamicsnippet.go @@ -92,7 +92,7 @@ func (h *DynamicSnippetServiceAttributeHandler) Create(_ context.Context, d *sch func (h *DynamicSnippetServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing VCL Snippets for (%s)", d.Id()) remoteState, err := conn.ListSnippets(&gofastly.ListSnippetsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_gzip.go b/fastly/block_fastly_service_gzip.go index f9729162c..16ca7621b 100644 --- a/fastly/block_fastly_service_gzip.go +++ b/fastly/block_fastly_service_gzip.go @@ -94,7 +94,7 @@ func (h *GzipServiceAttributeHandler) Create(_ context.Context, d *schema.Resour func (h *GzipServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Gzips for (%s)", d.Id()) remoteState, err := conn.ListGzips(&gofastly.ListGzipsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_header.go b/fastly/block_fastly_service_header.go index f77f40f3d..0f4431d78 100644 --- a/fastly/block_fastly_service_header.go +++ b/fastly/block_fastly_service_header.go @@ -134,7 +134,7 @@ func (h *HeaderServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *HeaderServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Headers for (%s)", d.Id()) remoteState, err := conn.ListHeaders(&gofastly.ListHeadersInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_healthcheck.go b/fastly/block_fastly_service_healthcheck.go index cd0bb9258..c9e7597a4 100644 --- a/fastly/block_fastly_service_healthcheck.go +++ b/fastly/block_fastly_service_healthcheck.go @@ -159,7 +159,7 @@ func (h *HealthCheckServiceAttributeHandler) Create(_ context.Context, d *schema func (h *HealthCheckServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Healthcheck for (%s)", d.Id()) remoteState, err := conn.ListHealthChecks(&gofastly.ListHealthChecksInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_bigquery.go b/fastly/block_fastly_service_logging_bigquery.go index 9e58ac521..e1bfc06da 100644 --- a/fastly/block_fastly_service_logging_bigquery.go +++ b/fastly/block_fastly_service_logging_bigquery.go @@ -155,7 +155,7 @@ func (h *BigQueryLoggingServiceAttributeHandler) Create(_ context.Context, d *sc func (h *BigQueryLoggingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing BigQuery for (%s)", d.Id()) remoteState, err := conn.ListBigQueries(&gofastly.ListBigQueriesInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_blobstorage.go b/fastly/block_fastly_service_logging_blobstorage.go index 5a66ef96a..6f79e8f09 100644 --- a/fastly/block_fastly_service_logging_blobstorage.go +++ b/fastly/block_fastly_service_logging_blobstorage.go @@ -194,7 +194,7 @@ func (h *BlobStorageLoggingServiceAttributeHandler) Create(_ context.Context, d func (h *BlobStorageLoggingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Blob Storages for (%s)", d.Id()) remoteState, err := conn.ListBlobStorages(&gofastly.ListBlobStoragesInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_cloudfiles.go b/fastly/block_fastly_service_logging_cloudfiles.go index 672eee3cf..123fa1085 100644 --- a/fastly/block_fastly_service_logging_cloudfiles.go +++ b/fastly/block_fastly_service_logging_cloudfiles.go @@ -154,7 +154,7 @@ func (h *CloudfilesServiceAttributeHandler) Create(_ context.Context, d *schema. func (h *CloudfilesServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { // Refresh Cloud Files. log.Printf("[DEBUG] Refreshing Cloud Files logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListCloudfiles(&gofastly.ListCloudfilesInput{ diff --git a/fastly/block_fastly_service_logging_datadog.go b/fastly/block_fastly_service_logging_datadog.go index 0e4dd9c9b..58f0857be 100644 --- a/fastly/block_fastly_service_logging_datadog.go +++ b/fastly/block_fastly_service_logging_datadog.go @@ -99,7 +99,7 @@ func (h *DatadogServiceAttributeHandler) Create(_ context.Context, d *schema.Res func (h *DatadogServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Datadog logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListDatadog(&gofastly.ListDatadogInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_digitalocean.go b/fastly/block_fastly_service_logging_digitalocean.go index db8b099af..25fba3f8c 100644 --- a/fastly/block_fastly_service_logging_digitalocean.go +++ b/fastly/block_fastly_service_logging_digitalocean.go @@ -154,7 +154,7 @@ func (h *DigitalOceanServiceAttributeHandler) Create(_ context.Context, d *schem func (h *DigitalOceanServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing DigitalOcean Spaces logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListDigitalOceans(&gofastly.ListDigitalOceansInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_elasticsearch.go b/fastly/block_fastly_service_logging_elasticsearch.go index e0eb45264..fe0481bf5 100644 --- a/fastly/block_fastly_service_logging_elasticsearch.go +++ b/fastly/block_fastly_service_logging_elasticsearch.go @@ -150,7 +150,7 @@ func (h *ElasticSearchServiceAttributeHandler) Create(_ context.Context, d *sche func (h *ElasticSearchServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Elasticsearch logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListElasticsearch(&gofastly.ListElasticsearchInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_ftp.go b/fastly/block_fastly_service_logging_ftp.go index 71b97ad0d..e0374c6c0 100644 --- a/fastly/block_fastly_service_logging_ftp.go +++ b/fastly/block_fastly_service_logging_ftp.go @@ -155,7 +155,7 @@ func (h *FTPServiceAttributeHandler) Create(_ context.Context, d *schema.Resourc func (h *FTPServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing FTP logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListFTPs(&gofastly.ListFTPsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_gcs.go b/fastly/block_fastly_service_logging_gcs.go index 81f1215ac..529447740 100644 --- a/fastly/block_fastly_service_logging_gcs.go +++ b/fastly/block_fastly_service_logging_gcs.go @@ -191,7 +191,7 @@ func (h *GCSLoggingServiceAttributeHandler) Create(_ context.Context, d *schema. func (h *GCSLoggingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing GCS for (%s)", d.Id()) remoteState, err := conn.ListGCSs(&gofastly.ListGCSsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_googlepubsub.go b/fastly/block_fastly_service_logging_googlepubsub.go index 2a740d09f..9e98914e9 100644 --- a/fastly/block_fastly_service_logging_googlepubsub.go +++ b/fastly/block_fastly_service_logging_googlepubsub.go @@ -116,7 +116,7 @@ func (h *GooglePubSubServiceAttributeHandler) Create(_ context.Context, d *schem func (h *GooglePubSubServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Google Cloud Pub/Sub logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListPubsubs(&gofastly.ListPubsubsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_heroku.go b/fastly/block_fastly_service_logging_heroku.go index 99c5f9f4f..fc4c0f867 100644 --- a/fastly/block_fastly_service_logging_heroku.go +++ b/fastly/block_fastly_service_logging_heroku.go @@ -101,7 +101,7 @@ func (h *HerokuServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *HerokuServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Heroku logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListHerokus(&gofastly.ListHerokusInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_honeycomb.go b/fastly/block_fastly_service_logging_honeycomb.go index c6654dce2..fa9fdf5d0 100644 --- a/fastly/block_fastly_service_logging_honeycomb.go +++ b/fastly/block_fastly_service_logging_honeycomb.go @@ -98,7 +98,7 @@ func (h *HoneycombServiceAttributeHandler) Create(_ context.Context, d *schema.R func (h *HoneycombServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Honeycomb logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListHoneycombs(&gofastly.ListHoneycombsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_https.go b/fastly/block_fastly_service_logging_https.go index c880de92c..474d204fd 100644 --- a/fastly/block_fastly_service_logging_https.go +++ b/fastly/block_fastly_service_logging_https.go @@ -165,7 +165,7 @@ func (h *HTTPSLoggingServiceAttributeHandler) Create(_ context.Context, d *schem func (h *HTTPSLoggingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing HTTPS logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListHTTPS(&gofastly.ListHTTPSInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_kafka.go b/fastly/block_fastly_service_logging_kafka.go index 9e7b94f31..ee8cc28d3 100644 --- a/fastly/block_fastly_service_logging_kafka.go +++ b/fastly/block_fastly_service_logging_kafka.go @@ -164,7 +164,7 @@ func (h *KafkaServiceAttributeHandler) Create(_ context.Context, d *schema.Resou func (h *KafkaServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Kafka logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListKafkas(&gofastly.ListKafkasInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_kinesis.go b/fastly/block_fastly_service_logging_kinesis.go index 28ba319b4..fd0529864 100644 --- a/fastly/block_fastly_service_logging_kinesis.go +++ b/fastly/block_fastly_service_logging_kinesis.go @@ -116,7 +116,7 @@ func (h *KinesisServiceAttributeHandler) Create(_ context.Context, d *schema.Res func (h *KinesisServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Kinesis logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListKinesis(&gofastly.ListKinesisInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_logentries.go b/fastly/block_fastly_service_logging_logentries.go index b2e77924a..7ad450777 100644 --- a/fastly/block_fastly_service_logging_logentries.go +++ b/fastly/block_fastly_service_logging_logentries.go @@ -129,7 +129,7 @@ func (h *LogentriesServiceAttributeHandler) Create(_ context.Context, d *schema. func (h *LogentriesServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Logentries for (%s)", d.Id()) remoteState, err := conn.ListLogentries(&gofastly.ListLogentriesInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_loggly.go b/fastly/block_fastly_service_logging_loggly.go index 3ca7d310a..a506dc677 100644 --- a/fastly/block_fastly_service_logging_loggly.go +++ b/fastly/block_fastly_service_logging_loggly.go @@ -95,7 +95,7 @@ func (h *LogglyServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *LogglyServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Loggly logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListLoggly(&gofastly.ListLogglyInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_logshuttle.go b/fastly/block_fastly_service_logging_logshuttle.go index 240191287..1a0abaad7 100644 --- a/fastly/block_fastly_service_logging_logshuttle.go +++ b/fastly/block_fastly_service_logging_logshuttle.go @@ -99,7 +99,7 @@ func (h *LogshuttleServiceAttributeHandler) Create(_ context.Context, d *schema. func (h *LogshuttleServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Log Shuttle logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListLogshuttles(&gofastly.ListLogshuttlesInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_newrelic.go b/fastly/block_fastly_service_logging_newrelic.go index 3cb8f6cf7..dee79ddc4 100644 --- a/fastly/block_fastly_service_logging_newrelic.go +++ b/fastly/block_fastly_service_logging_newrelic.go @@ -99,7 +99,7 @@ func (h *NewRelicServiceAttributeHandler) Create(_ context.Context, d *schema.Re func (h *NewRelicServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing New Relic logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListNewRelic(&gofastly.ListNewRelicInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_openstack.go b/fastly/block_fastly_service_logging_openstack.go index 784cee7f8..ea43ed87a 100644 --- a/fastly/block_fastly_service_logging_openstack.go +++ b/fastly/block_fastly_service_logging_openstack.go @@ -154,7 +154,7 @@ func (h *OpenstackServiceAttributeHandler) Create(_ context.Context, d *schema.R func (h *OpenstackServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing OpenStack logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListOpenstack(&gofastly.ListOpenstackInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_papertrail.go b/fastly/block_fastly_service_logging_papertrail.go index a3db6c4f0..9a44cf8db 100644 --- a/fastly/block_fastly_service_logging_papertrail.go +++ b/fastly/block_fastly_service_logging_papertrail.go @@ -122,7 +122,7 @@ func (h *PaperTrailServiceAttributeHandler) Create(_ context.Context, d *schema. func (h *PaperTrailServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Papertrail for (%s)", d.Id()) remoteState, err := conn.ListPapertrails(&gofastly.ListPapertrailsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_s3.go b/fastly/block_fastly_service_logging_s3.go index f90791a3a..c402289d4 100644 --- a/fastly/block_fastly_service_logging_s3.go +++ b/fastly/block_fastly_service_logging_s3.go @@ -235,7 +235,7 @@ func (h *S3LoggingServiceAttributeHandler) Create(_ context.Context, d *schema.R func (h *S3LoggingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing S3 Logging for (%s)", d.Id()) remoteState, err := conn.ListS3s(&gofastly.ListS3sInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_scalyr.go b/fastly/block_fastly_service_logging_scalyr.go index 9dc08bc0b..07b2f85a2 100644 --- a/fastly/block_fastly_service_logging_scalyr.go +++ b/fastly/block_fastly_service_logging_scalyr.go @@ -99,7 +99,7 @@ func (h *ScalyrServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *ScalyrServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Scalyr logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListScalyrs(&gofastly.ListScalyrsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_sftp.go b/fastly/block_fastly_service_logging_sftp.go index d79341908..ef38f7d2d 100644 --- a/fastly/block_fastly_service_logging_sftp.go +++ b/fastly/block_fastly_service_logging_sftp.go @@ -172,7 +172,7 @@ func (h *SFTPServiceAttributeHandler) Create(_ context.Context, d *schema.Resour func (h *SFTPServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing SFTP logging endpoints for (%s)", d.Id()) remoteState, err := conn.ListSFTPs(&gofastly.ListSFTPsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_splunk.go b/fastly/block_fastly_service_logging_splunk.go index 00e5bac75..9136ee53a 100644 --- a/fastly/block_fastly_service_logging_splunk.go +++ b/fastly/block_fastly_service_logging_splunk.go @@ -157,7 +157,7 @@ func (h *SplunkServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *SplunkServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Splunks for (%s)", d.Id()) remoteState, err := conn.ListSplunks(&gofastly.ListSplunksInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_sumologic.go b/fastly/block_fastly_service_logging_sumologic.go index 7e6296423..b90d532f4 100644 --- a/fastly/block_fastly_service_logging_sumologic.go +++ b/fastly/block_fastly_service_logging_sumologic.go @@ -123,7 +123,7 @@ func (h *SumologicServiceAttributeHandler) Create(_ context.Context, d *schema.R func (h *SumologicServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Sumologic for (%s)", d.Id()) remoteState, err := conn.ListSumologics(&gofastly.ListSumologicsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_logging_syslog.go b/fastly/block_fastly_service_logging_syslog.go index c73be31e0..34087315c 100644 --- a/fastly/block_fastly_service_logging_syslog.go +++ b/fastly/block_fastly_service_logging_syslog.go @@ -173,7 +173,7 @@ func (h *SyslogServiceAttributeHandler) Create(_ context.Context, d *schema.Reso func (h *SyslogServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Syslog for (%s)", d.Id()) remoteState, err := conn.ListSyslogs(&gofastly.ListSyslogsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_package.go b/fastly/block_fastly_service_package.go index 31ba79d92..d1ba5a17d 100644 --- a/fastly/block_fastly_service_package.go +++ b/fastly/block_fastly_service_package.go @@ -76,7 +76,7 @@ func (h *PackageServiceAttributeHandler) Process(_ context.Context, d *schema.Re func (h *PackageServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, s *gofastly.ServiceDetail, conn *gofastly.Client) error { localState := d.Get(h.key).([]any) - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing package for (%s)", d.Id()) remoteState, err := conn.GetPackage(&gofastly.GetPackageInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_requestsetting.go b/fastly/block_fastly_service_requestsetting.go index 0d4e799c1..6eaa7dd4d 100644 --- a/fastly/block_fastly_service_requestsetting.go +++ b/fastly/block_fastly_service_requestsetting.go @@ -129,7 +129,7 @@ func (h *RequestSettingServiceAttributeHandler) Create(_ context.Context, d *sch func (h *RequestSettingServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Request Settings for (%s)", d.Id()) remoteState, err := conn.ListRequestSettings(&gofastly.ListRequestSettingsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_responseobject.go b/fastly/block_fastly_service_responseobject.go index a91367b04..11a3b025c 100644 --- a/fastly/block_fastly_service_responseobject.go +++ b/fastly/block_fastly_service_responseobject.go @@ -108,7 +108,7 @@ func (h *ResponseObjectServiceAttributeHandler) Create(_ context.Context, d *sch func (h *ResponseObjectServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing Response Object for (%s)", d.Id()) remoteState, err := conn.ListResponseObjects(&gofastly.ListResponseObjectsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_snippet.go b/fastly/block_fastly_service_snippet.go index 72375cb92..8399afe8b 100644 --- a/fastly/block_fastly_service_snippet.go +++ b/fastly/block_fastly_service_snippet.go @@ -86,7 +86,7 @@ func (h *SnippetServiceAttributeHandler) Create(_ context.Context, d *schema.Res func (h *SnippetServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.Key()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing VCL Snippets for (%s)", d.Id()) remoteState, err := conn.ListSnippets(&gofastly.ListSnippetsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_vcl.go b/fastly/block_fastly_service_vcl.go index c8d094378..f2bb68820 100644 --- a/fastly/block_fastly_service_vcl.go +++ b/fastly/block_fastly_service_vcl.go @@ -80,7 +80,7 @@ func (h *VCLServiceAttributeHandler) Create(_ context.Context, d *schema.Resourc func (h *VCLServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, _ map[string]any, serviceVersion int, conn *gofastly.Client) error { localState := d.Get(h.Key()).(*schema.Set).List() - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing VCLs for (%s)", d.Id()) remoteState, err := conn.ListVCLs(&gofastly.ListVCLsInput{ ServiceID: d.Id(), diff --git a/fastly/block_fastly_service_waf.go b/fastly/block_fastly_service_waf.go index 40340aee1..838faf065 100644 --- a/fastly/block_fastly_service_waf.go +++ b/fastly/block_fastly_service_waf.go @@ -102,7 +102,7 @@ func (h *WAFServiceAttributeHandler) Process(_ context.Context, d *schema.Resour func (h *WAFServiceAttributeHandler) Read(_ context.Context, d *schema.ResourceData, s *gofastly.ServiceDetail, conn *gofastly.Client) error { localState := d.Get(h.GetKey()).([]any) - if len(localState) > 0 || d.Get("imported").(bool) { + if len(localState) > 0 || d.Get("imported").(bool) || d.Get("force_refresh").(bool) { log.Printf("[DEBUG] Refreshing WAFs for (%s)", d.Id()) remoteState, err := conn.ListWAFs(&gofastly.ListWAFsInput{ FilterService: d.Id(),