pulumi-cloudflare icon indicating copy to clipboard operation
pulumi-cloudflare copied to clipboard

Creating an R2 resource with a Location hint will error on subsequent runs

Open ProgrammerAL opened this issue 1 year ago • 3 comments

What happened?

When creating an R2 resource with a Location hint, the resource it created fine the first time. But in subsequent runs, Pulumi will try to replace the R2 resource. This ends with the error message: failed to create R2 bucket: The bucket you tried to create already exists, and you own it. (10004)

If you don't have a Location hint, the resource will not be replaced in subsequent runs.

Expected Behavior

The R2 resource should not be replaced.

Steps to reproduce

  1. Create a C# Pulumi project with the following code
using System.Collections.Generic;
using Pulumi;
using Pulumi.Cloudflare;

return await Deployment.RunAsync(() =>
{
    var apiToken = "uqtiSyipZtn6Tr2I-RbZUl3_NeZfZ_GzG_Bh3Kqd";
    var accountId = "43384b2dacb3c8d5a846f9eb53ef3aef";

    var provider = new Provider("my-cloudflare-provider", new ProviderArgs
    {
        ApiToken = apiToken
    });

    var name = "my-bucket";
    var bucket = new R2Bucket(name, new()
    {
        Name = name,
        AccountId = accountId,
        Location = "enam",
    }, new CustomResourceOptions
    {
        Provider = provider
    });

    return new Dictionary<string, object?>();
});

  1. Update the apiToken and accountId variables
  2. Add a reference to the Pulumi.Cloudflare NuGet, version 5.8.0
  3. Run pulumi up. Everything will be created correctly
  4. Run pulumi up again. The preview will say the R2 resource will be replaced. If you choose to run it anyway after the preview, the above mentioned error message will appear.

Output of pulumi about

CLI
Version      3.77.1
Go Version   go1.20.6
Go Compiler  gc

Plugins
NAME        VERSION
cloudflare  5.8.0
dotnet      unknown

Host
OS       Microsoft Windows 11 Home
Version  10.0.22621 Build 22621
Arch     x86_64

This project is written in dotnet: executable='C:\Program Files\dotnet\dotnet.exe' version='7.0.400'

Current Stack: ProgrammerAl/pulumi-cloudflare-r2-bug/dev

TYPE                                URN
pulumi:pulumi:Stack                 urn:pulumi:dev::pulumi-cloudflare-r2-bug::pulumi:pulumi:Stack::pulumi-cloudflare-r2-bug-dev
pulumi:providers:cloudflare         urn:pulumi:dev::pulumi-cloudflare-r2-bug::pulumi:providers:cloudflare::my-cloudflare-provider
cloudflare:index/r2Bucket:R2Bucket  urn:pulumi:dev::pulumi-cloudflare-r2-bug::cloudflare:index/r2Bucket:R2Bucket::my-bucket


Found no pending operations associated with dev

Backend
Name           pulumi.com
URL            https://app.pulumi.com/ProgrammerAl
User           ProgrammerAl
Organizations  ProgrammerAl

Dependencies:
NAME               VERSION
Pulumi             3.56.0
Pulumi.Cloudflare  5.8.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

ProgrammerAL avatar Aug 09 '23 23:08 ProgrammerAL

Hi @ProgrammerAL , thanks for opening this issue. Can you confirm that the resource is recorded in state correctly – just want to confirm that it somehow wasn't corrupted. Also, as a workaround for now, you may be able to use the ignoreChanges property (https://www.pulumi.com/docs/concepts/options/ignorechanges/).

aq17 avatar Aug 10 '23 19:08 aq17

Hi @aq17 , I think the resource state is correct (screenshot below). I noticed it doesn't have a property for the Location hint field, so I'm guessing that's why this is happening. I assume it's not there because the Location hint is still in preview for R2.

I am able to work around this, so it's not a blocker. But that's for the suggestion.

image

ProgrammerAL avatar Aug 10 '23 19:08 ProgrammerAL

This sounds like this upstream issue: https://github.com/cloudflare/terraform-provider-cloudflare/issues/2608

Unfortunately, it has been closed with no action. But I'm curious @ProgrammerAL - does it help if you capitalize the location when initially creating the resource? Also, could you show the exact diff that you are seeing on update?

mikhailshilkov avatar Sep 15 '23 15:09 mikhailshilkov