Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudflare_filter import issue - zone not set #161

Closed
SteveGoldthorpe-Work opened this issue Nov 22, 2018 · 8 comments
Closed

cloudflare_filter import issue - zone not set #161

SteveGoldthorpe-Work opened this issue Nov 22, 2018 · 8 comments

Comments

@SteveGoldthorpe-Work
Copy link
Contributor

SteveGoldthorpe-Work commented Nov 22, 2018

  • terraform import for cloudflare_filter resource forces a new resource on next apply as zone is not added up on import.
    zone: "" => "domain.name" (forces new resource)

  • terraform import for cloudflare_filter resource requires a zone_id rather than zone unlike the other resources. We should be consistent.
    $ terraform import cloudflare_filter.default d41d8cd98f00b204e9800998ecf8427e/9e107d9d372bb6826bd81d3542a419d6

provider.cloudflare 1.9

@jacobbednarz
Copy link
Member

terraform import for cloudflare_filter resource requires a zone_id rather than zone unlike the other resources. We should be consistent.
$ terraform import cloudflare_filter.default d41d8cd98f00b204e9800998ecf8427e/9e107d9d372bb6826bd81d3542a419d6

@patryk did mention in an earlier comment that there was a push to go one or the other (zone vs zone ID) however I'm not sure where that is at. I don't think it's worth doing by itself and we should probably wait on that decision as there will need to be shuffling of the internals to achieve this. It's not a make or break thing at the moment and the import processes documented to reflect these key differences.

terraform import for cloudflare_filter resource forces a new resource on next apply as zone is not added up on import.
zone: "" => "domain.name" (forces new resource)

This feels like a bug. Let me take a look at what we can do to handle setting a zone or zone ID and work out getting the other.

@patryk
Copy link
Contributor

patryk commented Nov 22, 2018

Re: import - yes, we are moving away from using zone names directly, so I'd like to new code use IDs instead. For existing things, we cannot do it without breaking change, so we will retrofit with IDs support. Eventually (sometime 1H2019) we'll do a 2.0 release where we remove all legacy constructs.

Re: empty field, yes, it's most definitely a bug.

jacobbednarz added a commit to jacobbednarz/terraform-provider-cloudflare that referenced this issue Nov 23, 2018
During an import of the `clouflare_filter` resource, the `zone_id` is
defined within the composite ID. This value is then populated and synced
within `resourceCloudflareFilterRead` to match the expected schema
resource. However, we don't currently set `zone` (the zone name)
anywhere. This becomes problematic on subsequent terraform operations as
the `Read` attempts to sync the schema with the filter and ends up
attempting to recreate the resource due to detecting a change.

Initially I thought we could just iterate over all zones and pull out
the one that matched the zone ID but this only works _if_ the zone ID
has been provided (which isn't guaranteed since both fields are optional
but one is required). Instead, I've opted to ensure we update both the
`zone` and `zone_id` properties when we have one of them. I.e when we
only have the `zone_id`, use that value to find and set the `zone` value
(and vice versa). This will ensure that both values are defined and a
change in either will retrigger the update.

Fixes cloudflare#161.
@SteveGoldthorpe-Work
Copy link
Contributor Author

I've just checked - ditto import for cloudflare_firewall_rule.
zone: "" => "domain.name" (forces new resource)
I'm just wondering why zone_id is marked as computed and zone isn't. Is it the wrong way around? Or does zone_id get computed from zone in normal operation (just not import)?

@jacobbednarz
Copy link
Member

@SteveGoldthorpe-Work I've just pushed up #162 which should aim to address this by keeping both in sync. Give it a whirl and let me know if you hit any snags.

@jacobbednarz
Copy link
Member

@SteveGoldthorpe-Work I'd recommend we open a new issue for the issue above so that we can track it individually and not have it close when this one is resolved.

@SteveGoldthorpe-Work SteveGoldthorpe-Work changed the title cloudflare_filter import issues cloudflare_filter import issue - zone not set Nov 23, 2018
@SteveGoldthorpe-Work
Copy link
Contributor Author

tested PR #162, zone is now set on import.
Moreover same code added to cloudflare/resource_cloudflare_firewall_rule.go fixes #165

@abohne
Copy link

abohne commented Nov 27, 2018

I'm seeing similar behavior with a cloudflare_zone resource that has been imported.

@SteveGoldthorpe-Work
Copy link
Contributor Author

I suspect the problem exists for anything importing using a zone id rather than a zone name. I think they want a separate ticket for each resource for tracking purposes.
As I mentioned in another ticket, the workaround is to pull the state, edit the statefile to add the missing zone definition and push the modified state.

patryk pushed a commit that referenced this issue Dec 4, 2018
* Allow `zone_id` to set `zone` and vice versa

During an import of the `clouflare_filter` resource, the `zone_id` is
defined within the composite ID. This value is then populated and synced
within `resourceCloudflareFilterRead` to match the expected schema
resource. However, we don't currently set `zone` (the zone name)
anywhere. This becomes problematic on subsequent terraform operations as
the `Read` attempts to sync the schema with the filter and ends up
attempting to recreate the resource due to detecting a change.

Initially I thought we could just iterate over all zones and pull out
the one that matched the zone ID but this only works _if_ the zone ID
has been provided (which isn't guaranteed since both fields are optional
but one is required). Instead, I've opted to ensure we update both the
`zone` and `zone_id` properties when we have one of them. I.e when we
only have the `zone_id`, use that value to find and set the `zone` value
(and vice versa). This will ensure that both values are defined and a
change in either will retrigger the update.

Fixes #161.
jacobbednarz added a commit to jacobbednarz/terraform-provider-cloudflare that referenced this issue Dec 4, 2018
During an import of the `cloudflare_firewall_rule` resource, the `zone_id` is
defined within the composite ID. This value is then populated and synced
within `resourceCloudflareFirewallRuleRead` to match the expected schema
resource. However, we don't currently set zone (the zone name)
anywhere. This becomes problematic on subsequent terraform operations as
the Read attempts to sync the schema with the firewall rule and ends up
attempting to recreate the resource due to detecting a change.

This is a similar issue to cloudflare#161 and is addressed in a similar manner.

Fixes cloudflare#165
jacobbednarz added a commit to jacobbednarz/terraform-provider-cloudflare that referenced this issue Dec 4, 2018
During an import of the `cloudflare_access_rule` resource, the `zone_id`
is defined within the composite ID. This value is then populated and
synced within `resourceCloudflareAccessRuleRead` to match the expected
schema resource. However, we don't currently set zone (the zone name)
anywhere. This becomes problematic on subsequent terraform operations as
the Read attempts to sync the schema with the access rule and ends up
attempting to recreate the resource due to detecting a change.

This is a similar issue to cloudflare#161 and is addressed in a similar manner.

Fixes cloudflare#166
patryk pushed a commit that referenced this issue Dec 5, 2018
During an import of the `cloudflare_firewall_rule` resource, the `zone_id` is
defined within the composite ID. This value is then populated and synced
within `resourceCloudflareFirewallRuleRead` to match the expected schema
resource. However, we don't currently set zone (the zone name)
anywhere. This becomes problematic on subsequent terraform operations as
the Read attempts to sync the schema with the firewall rule and ends up
attempting to recreate the resource due to detecting a change.

This is a similar issue to #161 and is addressed in a similar manner.

Fixes #165
patryk pushed a commit that referenced this issue Dec 5, 2018
* Ensure `zone` and `zone_id` are always set

During an import of the `cloudflare_access_rule` resource, the `zone_id`
is defined within the composite ID. This value is then populated and
synced within `resourceCloudflareAccessRuleRead` to match the expected
schema resource. However, we don't currently set zone (the zone name)
anywhere. This becomes problematic on subsequent terraform operations as
the Read attempts to sync the schema with the access rule and ends up
attempting to recreate the resource due to detecting a change.

This is a similar issue to #161 and is addressed in a similar manner.

Fixes #166
jacobbednarz referenced this issue in jacobbednarz/terraform-provider-cloudflare Jul 18, 2019
Zone names within Cloudflare are not universally unique which makes
performing a lookup based on just the name a little troublesome. Two
accounts can have the same zone name and both of these can be returned
if the lookups are not restricted to the zone ID or account ID.

To rememdy this, `zone` is being deprecated in favour of explicit
`zone_id` values. See the discussion[1] on this for full details.

Following Terraform's guidelines for deprecations[2], we are putting in
a deprecation notice as part of a minor release and then in our next
major release, we will actually perform the schema and functionality
removal. This update will not prevent people from using `zone` however
use will trigger a warning that it's going away and they should migrate
themselves.

[1]: https://github.com/terraform-providers/terraform-provider-cloudflare/issues/161#issuecomment-441128985
[2]: https://www.terraform.io/docs/extend/best-practices/deprecations.html#provider-attribute-removal
jacobbednarz referenced this issue in jacobbednarz/terraform-provider-cloudflare Jul 18, 2019
Zone names within Cloudflare are not universally unique which makes
performing a lookup based on just the name a little troublesome. Two
accounts can have the same zone name and both of these can be returned
if the lookups are not restricted to the zone ID or account ID.

To rememdy this, `zone` is being deprecated in favour of explicit
`zone_id` values. See the discussion[1] on this for full details.

Following Terraform's guidelines for deprecations[2], we are putting in
a deprecation notice as part of a minor release and then in our next
major release, we will actually perform the schema and functionality
removal. This update will not prevent people from using `zone` however
use will trigger a warning that it's going away and they should migrate
themselves.

[1]: https://github.com/terraform-providers/terraform-provider-cloudflare/issues/161#issuecomment-441128985
[2]: https://www.terraform.io/docs/extend/best-practices/deprecations.html#provider-attribute-removal
patryk referenced this issue Jul 19, 2019
Zone names within Cloudflare are not universally unique which makes
performing a lookup based on just the name a little troublesome. Two
accounts can have the same zone name and both of these can be returned
if the lookups are not restricted to the zone ID or account ID.

To rememdy this, `zone` is being deprecated in favour of explicit
`zone_id` values. See the discussion[1] on this for full details.

Following Terraform's guidelines for deprecations[2], we are putting in
a deprecation notice as part of a minor release and then in our next
major release, we will actually perform the schema and functionality
removal. This update will not prevent people from using `zone` however
use will trigger a warning that it's going away and they should migrate
themselves.

[1]: https://github.com/terraform-providers/terraform-provider-cloudflare/issues/161#issuecomment-441128985
[2]: https://www.terraform.io/docs/extend/best-practices/deprecations.html#provider-attribute-removal
boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this issue Feb 28, 2022
* add rate limiting definitions + functions with tests, examples

* handle pagination in listing rate limits

* add pointer values where empty values conflict with api defaults

+ cleanup review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants