Hi, I seem to be having issues with Cloudflare in Pulumi. I have checked that the permissions are co...
c
Hi, I seem to be having issues with Cloudflare in Pulumi. I have checked that the permissions are correct for the api token; however, i am getting this error when trying to add a DNS record:
Copy code
error: failed to make http request: POST "<https://api.cloudflare.com/client/v4/zones/186b216107482ba7a7554f86411341ec/dns_records>": 401 Unauthorized 
{
  "success":false,
  "errors": [
      {
        "code":10000,
        "message":"Authentication error"
      }
    ]
}
When i try to do the same thing in Postman it works fine. My Pulumi code:
Copy code
ts
const cloudflareProvider = new cloudflare.Provider('cf', {
  apiToken: '<token>',
});

const cloudflareDomain = new cloudflare.DnsRecord(
  `${resourcePrefix}-cloudflare-domain`,
  {
    name: domainPrefix,
    content: cloudfrontDistribution.domainName, // lines to the A record of the cloudfront distribution 
    type: 'CNAME',
    ttl: 1,
    zoneId: zoneId,
    proxied: true,
    comment: `CNAME record for ${domainPrefix} pointing to Cloudfront distribution ${cloudfrontDistribution.domainName}`,
  },
  {
    dependsOn: [cloudfrontDistribution],
    provider: cloudflareProvider,
  }
);
n
Same error, I just find this message from Google.
Do you find a solution?
I just found a solution to fix this, from the API doc:
Copy code
Accepted Permissions (at least one required)
DNS Write
https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/create/. I realized that I configured DNS views, DNS settings permissions by using Account API tokens, but I didn't add zone level permission, so I tried to add new Zone level permission for DNS-Edit and also configured Zone resources. And the code works now.