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

Add structs; impl Create for CloudFlare PageRules #38

Merged
merged 1 commit into from
Mar 12, 2018
Merged

Add structs; impl Create for CloudFlare PageRules #38

merged 1 commit into from
Mar 12, 2018

Conversation

catsby
Copy link
Contributor

@catsby catsby commented Mar 12, 2018

This is #34 but rebased and with merge conflicts resolved.

This commit adds most of the boilerplate for implementing CloudFlare
Page Rules, and implements the Create method.

`PageRuleActionValue`s still need a validator; this is complex and
depends on `PageRuleActionId`.

Read, Update, and Delete methods will throw 'not implemented' errors.

Towards hashicorp/terraform#9040; #3.

Require at least one page rule action

Simplify page rule targets API

Asking for a list of targets is just confusing to a user when Cloudflare
only accepts  a single `"url"` target.

Implement action value validation

Improve legibility

Change action Elems to be Schema

Implement Read/Update/Delete Page Rules

Simplify Page Rule action schema

This commit changes Page Rule actions to be a TypeSet of maps containing
the action ID, and optionally its sub-setting. This makes validation a
bit nicer, too.

Fix crash while running apply

Page Rule Read implementation was naïvely copying Cloudflare's returned
data structure, rather than transforming to fit schema.

Fix passing PageRuleAction value error back up

Flatten PageRule action schema

Fix flattened structure

Unfortunately, we cannot have the desired structure with a
`schema.Resource` `actions` in the main schema:

    resource "cloudflare_page_rule" "foo" {
      actions = {
        always_online = true
      }
    }

where `always_online` and other Actions are explicitly defined, since
`actions` needs to be a `schema.Schema`.

This commit moves the `Resource` inside `actions`, which now becomes a
`Schema` of `TypeSet`, which means Cloudflare's binary options such as
`always_online` will default to `false` if we have them be `TypeBool`.
To circumvent that, we instead use `TypeString` and validate `"on"` or
`"off"` (matching Cloudflare's API) - since these will be empty if not
set.

The logic's a little less clean, since we now have to loop through every
possible action type for each action in the set, testing the type and
value of its sub-setting/mode to determine if it was really set by the
user.

Document page rule resources

Appease linter

Add acceptance tests for page rules

Fix allowing multiple entries in page rule actions

Improve error reporting

get page rule resource working, add tests

random fixes

standardise on zone + implement import

tests check api attributes + docs update for page rule

error check on set complex attr + remove failing attributes from page rules tests
@catsby catsby merged commit cd9f581 into master Mar 12, 2018
@patryk patryk deleted the pr-34 branch July 12, 2018 15:04
jacobbednarz referenced this pull request in jacobbednarz/terraform-provider-cloudflare Apr 30, 2019
This cleans up the acceptance tests which have been broken since they were introduced in #38.

I'm not sure what the initial intentions behind this were however they no longer make sense with the current state of the API.
jacobbednarz referenced this pull request in jacobbednarz/terraform-provider-cloudflare Apr 30, 2019
This cleans up the acceptance tests which have been broken since they were introduced in #38.

I'm not sure what the initial intentions behind this were however they no longer make sense with the current state of the API.
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

Successfully merging this pull request may close these issues.

2 participants