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

Cannot create a PageRule - Zone could not be found #23

Closed
rosskevin opened this issue Jul 10, 2019 · 2 comments
Closed

Cannot create a PageRule - Zone could not be found #23

rosskevin opened this issue Jul 10, 2019 · 2 comments
Assignees

Comments

@rosskevin
Copy link

rosskevin commented Jul 10, 2019

First, let me say that the zone is found/available and in the same block of code I am imperatively calling the cloudflare api directly with the same zone, token, and email with a check on the result and it is successful.

Therefore, I think there is a problem with either the pulumi provider or execution of PageRule.

Sample code:

/**
 * Cloudflare page rules to control edge caches
 */
const cloudflareConfig = new Config('cloudflare')
const [email, token, zone, domain] = ['email', 'token', 'zone', 'domain'].map(key =>
  cloudflareConfig.require(key),
)

const cloudflareProvider = new cloudflare.Provider('cloudflare', {
  email,
  token,
})

const targets = [`https://${domain}`]
targets.forEach(target => {
  new cloudflare.PageRule(
    target,
    {
      actions: {
        cacheLevel: 'cache_everything',
        edgeCacheTtl: 3600, // 1 hour
      },
      priority: 1,
      status: 'active',
      target,
      zone,
    },
    { provider: cloudflareProvider },
  )
})

/**
 * Wait for rollout status to be good on web, then clear the cloudflare cache
 */
rolloutStatus(web.deployment).apply(rStatus => {
  log.info('Rollout status of web:', rStatus)
  if (!rStatus.finished) {
    log.error('deployment not yet finished!!!')
  } else if (rStatus.availableReplicas < rStatus.updatedReplicas) {
    log.error('availableReplicas are less than updatedReplicas!!!')
  }

  const cloudflareClient = new CloudflareClient(email, token)
  cloudflareClient.purgeCache(zone, {
    files: [
      `https://${domain}/index.html`,
      `https://www.${domain}/index.html`,
      `https://${domain}/webpack/a/manifest.json`,
    ],
  })
})

Error:

Updating (alienfast/production):

     Type                            Name                          Status                  Info
     pulumi:pulumi:Stack             acme-app-production  **failed**              1 error; 4 messages
 +   ├─ pulumi:providers:cloudflare  cloudflare                    created                 
 +   └─ cloudflare:index:PageRule    https://acme.com     **creating failed**     1 error
 
Diagnostics:
 
    error: update failed
 
  cloudflare:index:PageRule (https://acme.com):
    error: Plan apply failed: Error finding zone "xyz123": Zone could not be found
@rosskevin
Copy link
Author

I tried creating a simpler rule name but no change:

let rule = 0
targets.forEach(target => {
  rule += 1
  new cloudflare.PageRule(
    `rule-${rule}`,

@rosskevin
Copy link
Author

zone is zone name, not zone id. That solves this issue.

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

2 participants