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

Provider does not support CloudFlare multi-user accounts #5

Open
JorritSalverda opened this issue Jun 30, 2015 · 2 comments
Open

Provider does not support CloudFlare multi-user accounts #5

JorritSalverda opened this issue Jun 30, 2015 · 2 comments

Comments

@JorritSalverda
Copy link

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:

hashicorp/terraform#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)
    }
}
@pearkes
Copy link
Owner

pearkes commented Jul 1, 2015

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.

@pearkes
Copy link
Owner

pearkes commented Jul 1, 2015

Ah misread your ticket and see you already made the issue. All good then!

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