pulumi / pulumi-cloudflare

Pulumi's Cloudflare package, providing multi-language infrastructure as code for Cloudflare
Apache License 2.0
102 stars 13 forks source link

Cloudflare DNS Record GET Issues #26

Closed ben-nagengast closed 4 years ago

ben-nagengast commented 5 years ago

I think there's an issue with the Cloudflare DNS Record GET function.

Tested on v0.17.1 and v0.17.8

https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/cloudflare/#Record-get

According to https://api.cloudflare.com/#dns-records-for-a-zone-dns-record-details We need to be generating this URI /zones/<zone-id>/dns_records/<record-id>

Currently,

const record = cloudflare.Record.get('test.example.com', 'example.com/<recordId>');

Will generate the following error

    error: Preview failed: refreshing 
urn:pulumi:sandbox::Cloudflare::cloudflare:index/record:Record::test.example.com: error from 
makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":7003,
\"message\":\"Could not route to \\/zones\\/<zoneId>\\/dns_records\\/example.com
\\/<recordId> perhaps your object identifier is invalid?\"},{\"code\":7000,\"message\":\"No route 
for that URI\"}],\"messages\":[],\"result\":null}"

It looks like the issue here is that the <zoneId>/<recordId> is being directly passed to the URI as the <record-id> instead of splitting it and resolving the ZoneID and removing it.

ben-nagengast commented 5 years ago

I'm assuming this is an issue with the Terraform provider and not Pulumi.

Here's resourceCloudflareRecordRead https://github.com/terraform-providers/terraform-provider-cloudflare/blob/70cc823581cd33376e0647ced55d5dc93dc4c573/cloudflare/resource_cloudflare_record.go#L370

Here's resourceCloudflareRecordImport https://github.com/terraform-providers/terraform-provider-cloudflare/blob/70cc823581cd33376e0647ced55d5dc93dc4c573/cloudflare/resource_cloudflare_record.go#L508

I'm assuming the issue is to do with the read function - import seems to handle it correctly just glancing at the code. Unfortunately I don't know how this is all wired together well enough to debug resourceCloudflareRecordRead :(

If this issue should instead be made on the TF repo, let me know!

damianh commented 5 years ago

Just experienced this, while attempting to import a record into a stack. At first I set the import valud to the id of the resource. Using similar to:

new cloudflare.Record("a-record, {
    name: name,
    domain: zone,
    type: "A",
    value: value,
    proxied: proxied,
}, 
{ 
    provider: provider,
    import: "1c2d230b0d7f45ff10961035ad3af3cb",
});

Results in:

cloudflare:index:Record (a-record): error: Preview failed: importing 1c2d230b0d7f45ff10961035ad3af3cb: invalid id "1c2d230b0d7f45ff10961035ad3af3cb" specified, should be in format "zoneName/recordId" for import

But then specifying the zone name:

new cloudflare.Record("a-record, {
    name: name,
    domain: zone,
    type: "A",
    value: value,
    proxied: proxied,
}, 
{ 
    provider: provider,
    import: "myhost.com/1c2d230b0d7f45ff10961035ad3af3cb",
});

results in...

  cloudflare:index:Record (a-record-wallet):
    error: Preview failed: refreshing urn:pulumi:prod::cloudflare::cloudflare:index/record:Record::a-record: error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":7003,\"message\":\"Could not route to \\/zones\\/4eadeb5b264ad5ecefb4a927b44d8935\\/dns_records\\/myhost.com\\/1c2d230b0d7f45ff10961035ad3af3cb, perhaps your object identifier is invalid?\"},{\"code\":7000,\"message\":\"No 
route for that URI\"}],\"messages\":[],\"result\":null}"

It appears to be routing to /zones/4eadeb5b264ad5ecefb4a927b44d8935/dns_records/myhost.com/1c2d230b0d7f45ff10961035ad3af3cb But is should be routing to /zones/4eadeb5b264ad5ecefb4a927b44d8935/dns_records/1c2d230b0d7f45ff10961035ad3af3cb as per URI templated mentioned by @ben-nagengast

ben-nagengast commented 5 years ago

@stack72 Just checking in on this, any updates?

stack72 commented 5 years ago

Hi @ben-nagengast

I have updated the provider. The import should be of the format zone_id/record. In your example above, you are using the zone_name which is no longer supported since 1.0 of the provider

Can you try an upgrade and see if that works for you?

P.

stack72 commented 4 years ago

Hi @damianh

Please can you tell me if this is still a problem for you since the 1.0.0 release of the provider?

P.

stack72 commented 4 years ago

Going to close this out for now - I've not heard if this can be re-created with 1.0.0 of the provider. Please let me know if this is still the case

damianh commented 4 years ago

Works here, cheers.