digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
503 stars 276 forks source link

digitalocean_spaces_bucket NoSuchBucket while creating bucket #1153

Open srasul opened 5 months ago

srasul commented 5 months ago

Bug Report


Describe the bug

When creating a Spaces Bucket via Terraform, we get a timeout and and the following error:

Error: NoSuchBucket: status code: 404, request id:

Affected Resource(s)

Expected Behavior

The bucket should be created sucessfully

Actual Behavior

There is a timout waiting for the bucket to be created.

I went to the Digital Ocean web console and could see the Bucket was there, but Terraform was still waiting for this bucket to be created.

Steps to Reproduce

Terraform Configuration Files

Terraform version

2.34.1

Debug Output

{"@level":"info","@message":"digitalocean_spaces_bucket.this: Still creating... [10s elapsed]","@module":"terraform.ui","@timestamp":"2024-05-03T15:04:58.958499Z","hook":{"resource":{"addr":"digitalocean_spaces_bucket.this","module":"","resource":"digitalocean_spaces_bucket.this","implied_provider":"digitalocean","resource_type":"digitalocean_spaces_bucket","resource_name":"this","resource_key":null},"action":"create","elapsed_seconds":10},"type":"apply_progress"}
 ...

{"@level":"info","@message":"digitalocean_spaces_bucket.this: Still creating... [5m0s elapsed]","@module":"terraform.ui","@timestamp":"2024-05-03T15:09:48.984307Z","hook":{"resource":{"addr":"digitalocean_spaces_bucket.this","module":"","resource":"digitalocean_spaces_bucket.this","implied_provider":"digitalocean","resource_type":"digitalocean_spaces_bucket","resource_name":"this","resource_key":null},"action":"create","elapsed_seconds":300},"type":"apply_progress"}
{"@level":"info","@message":"digitalocean_spaces_bucket.this: Creation errored after 5m2s","@module":"terraform.ui","@timestamp":"2024-05-03T15:09:51.030848Z","hook":{"resource":{"addr":"digitalocean_spaces_bucket.this","module":"","resource":"digitalocean_spaces_bucket.this","implied_provider":"digitalocean","resource_type":"digitalocean_spaces_bucket","resource_name":"this","resource_key":null},"action":"create","elapsed_seconds":302},"type":"apply_errored"}
{"@level":"error","@message":"Error: NoSuchBucket: \n\tstatus code: 404, request id: , host id: ","@module":"terraform.ui","@timestamp":"2024-05-03T15:09:51.538465Z","diagnostic":{"severity":"error","summary":"NoSuchBucket: \n\tstatus code: 404, request id: , host id: ","detail":"","address":"digitalocean_spaces_bucket.this","range":{"filename":"storage.tf","start":{"line":1,"column":46,"byte":45},"end":{"line":1,"column":47,"byte":46}},"snippet":{"context":"resource \"digitalocean_spaces_bucket\" \"this\"","code":"resource \"digitalocean_spaces_bucket\" \"this\" {","start_line":1,"highlight_start_offset":45,"highlight_end_offset":46,"values":[]}},"type":"diagnostic"}
Operation failed: failed running terraform apply (exit 1)

Panic Output

Additional context

We are 'applying' via Terraform Cloud.

Important Factoids

References

srasul commented 5 months ago

Did some digging around and found the following:

When I use the JavaScript AWS S3 API to create a bucket and add a bucket policy to this bucket, everything works immediately. I can then get the bucket as well it's bucket policy.

When I create another bucket with JavaScript AWS S3 API, and then use the s3cmd info on this bucket, I get a 404 NoSuchBucket error. And after about a minute I get the bucket info. I dug into the code for s3cmd, and it seems that it does to check if a bucket is available is a HTTPS call to the URL:

https://${bucket-name}.${region}.digitaloceanspaces.com/?location

and this returns a HTTP 404 NoSuchBucket. What is unclear to me is why the S3 API gives a result, but calling the URL on digitaloceanspaces.com produces a 404 that eventually gives a 200. Eventually = about 1-2 minutes, sometimes longer.

nkotixwolf commented 4 months ago

This is affecting me as well @srasul . Has there been a fix or work around? @andrewsomething can you take a look at this? This is blocking creation of DO spaces via Terraform.

srasul commented 4 months ago

@nkotixwolf unfortunately I couldn't find a solution to this. My current workaround is to move the creation of the bucket out of Terraform and into additional code that runs before Terraform. Once the bucket is created, I pass the name of this bucket into Terraform as an input parameter so other Terraform resources can use it.