cloudflare
cloudflare copied to clipboard
Provider does not support CloudFlare multi-user accounts
Hi Jack,
I really appreciate the work you've done on the Terraform CloudFlare provider. It works perfectly for regular cloudflare accounts. But for multi-user organization accounts it does not, because you use the old api which doesn't support those type of accounts.
I've already created this ticket at terraform, but realized they're using your implementation:
https://github.com/hashicorp/terraform/issues/2551
It is possible to update it to use the new api? I've already scripted this before in powershell, maybe it helps.
If you don't have time let me know, when I do I can dive into go lang, do the updates and create a PR. That might take some time though.
Thanks, Jorrit
$zoneName = "example.com"
$recordName = "subdomain"
$recordValue = "127.0.0.1"
$cloudFlareApiBaseUrl = "https://api.cloudflare.com/client/v4"
if (($cloudFlareApiAuthKey -ne "") -and ($cloudFlareApiAuthEmail -ne ""))
{
# update existing record at cloudflare
$headers = @{
"X-Auth-Key" = $cloudFlareApiAuthKey;
"X-Auth-Email" = $cloudFlareApiAuthEmail;
"Content-Type" = "application/json"
}
# get zone id
$request = Invoke-WebRequest -Uri "${cloudFlareApiBaseUrl}/zones/?name=${zoneName}" -Method "GET" -Headers $headers
$zoneId = $(ConvertFrom-Json $request.Content).result[0].id
# get dns record
$request = Invoke-WebRequest -Uri "${cloudFlareApiBaseUrl}/zones/$zoneId/dns_records/?name=${recordName}.${zoneName}" -Method "GET" -Headers $headers
$results = $(ConvertFrom-Json $request.Content).result
if ($results.Count -gt 0)
{
$dnsRecord = $results[0]
# update dns record
$dnsRecord.Content = "${recordValue}"
# update record at cloudflare
$request = Invoke-WebRequest -Uri "${cloudFlareApiBaseUrl}/zones/${zoneId}/dns_records/$($dnsRecord.id)/" -Method "PUT" -Headers $headers -Body $(ConvertTo-Json $dnsRecord)
}
else
{
# create dns record
$newDnsRecord = @{
"type" = "A";
"name" = "${recordName}.${zoneName}";
"content" = "${recordValue}"
}
# create record at cloudflare
$request = Invoke-WebRequest -Uri "${cloudFlareApiBaseUrl}/zones/${zoneId}/dns_records" -Method "POST" -Headers $headers -Body $(ConvertTo-Json $newDnsRecord)
}
}
Hey Jorrit!
Yea, agree we should upgrade the API. I'm going to make an issue over in Terraform and link to this, so it can be seen by others.
I don't have immediate time to work on this, but perhaps someone over there can.
Ah misread your ticket and see you already made the issue. All good then!