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

Allow zone_id to set zone and vice versa #162

Merged

Conversation

jacobbednarz
Copy link
Member

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.

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.
@ghost ghost added the size/XS label Nov 23, 2018
}
}

if zoneName == "" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a safe guard to ensure that if we do get to this point, we really do have a zoneName set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need to check for zoneID being empty here, will be always populated by Create or Import.
We should also mark zone field as Computed: true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that causes a bit of confusion here because zone_id is already marked as computed in the schema.

https://github.com/terraform-providers/terraform-provider-cloudflare/blob/5c9bbc63bcd4cbe0d108aec8e575e3e1e1b1129f/cloudflare/resource_cloudflare_filter.go#L29-L34

Should it only be zone that is computed? If that's the case, we won't need majority of this PR as we'll assume we always have the zone_id and can work everything around that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computed here means that the code may set it itself, so it should not be taken into consideration on diff unless explicitly set (yes, Computed fields can be set in HCL).

Because now in Create we set zone_id if we provide zone, but we will be setting zone when we import with zone_id only, we need both to be Computed.

I made a mistake coding in the zone field, I was young and stupid at that time ;)
We really need to clean zone vs zone_id mess in v2.0 😰

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computed here means that the code may set it itself, so it should not be taken into consideration on diff unless explicitly set (yes, Computed fields can be set in HCL).

TIL, other uses of this that I have seen have all been for things like UUIDs or generating values at runtime.

We really need to clean zone vs zone_id mess in v2.0 😰

Do you want to start a v2.0 issue where we can keep track of these things so that we have a record of it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good idea. Issue and/or milestone (will need to read GitHub guides on this).

Copy link
Contributor

@SteveGoldthorpe-Work SteveGoldthorpe-Work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and now fills in zone on import.

}
}

if zoneName == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need to check for zoneID being empty here, will be always populated by Create or Import.
We should also mark zone field as Computed: true.

@jacobbednarz
Copy link
Member Author

I've updated this to mark zone as Computed and removed the additional guard clause via b9ab72e and b14b7f8 respectively.

@patryk patryk merged commit 3b1ed02 into cloudflare:master Dec 4, 2018
@jacobbednarz jacobbednarz deleted the set-zone-id-and-zone-name-for-filter branch December 4, 2018 20:42
boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this pull request Feb 28, 2022
* Added CheckRegions field to LoadBalancerPool

* Fixed TestCreateLoadBalancerPool to wirk with check_regions

* Fixed TestDeleteLoadBalancerPool to wirk with check_regions

* Added documentation for the CheckRegions field in LoadBalancerPool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants