Question

Create Spaces bucket with Terraform gives malformed request

I want to create a space bucket using Terraform. Here is my attempt:

provider "digitalocean" {
  token = var.do_token
  spaces_access_id = var.do_spaces_client_id
  spaces_secret_key = var.do_spaces_secret_key
}

resource "digitalocean_spaces_bucket" "shop_images" {
  name = "shop_images"
  region = var.do_region
  acl = "public-read"
}

The token and spaces client id/secret key work as I can create droplet but not spaces. The do_region variable is fra1.

The error I get in return is:

digitalocean_spaces_bucket.shop_images: Creating...
2020/05/15 09:51:43 [DEBUG] digitalocean_spaces_bucket.shop_images: apply errored, but we're indicating that via the Error pointer rather than returning it: Error creating Spaces bucket: InvalidRequest: Malformed request
        status code: 400, request id: , host id: 
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/05/15 09:51:43 [TRACE] EvalMaybeTainted: digitalocean_spaces_bucket.shop_images encountered an error during creation, so it is now marked as tainted
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/05/15 09:51:43 [TRACE] EvalWriteState: removing state object for digitalocean_spaces_bucket.shop_images
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalApplyProvisioners
2020/05/15 09:51:43 [TRACE] EvalApplyProvisioners: digitalocean_spaces_bucket.shop_images has no state, so skipping provisioners
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/05/15 09:51:43 [TRACE] EvalMaybeTainted: digitalocean_spaces_bucket.shop_images encountered an error during creation, so it is now marked as tainted
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/05/15 09:51:43 [TRACE] EvalWriteState: removing state object for digitalocean_spaces_bucket.shop_images
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalIf
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalIf
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalWriteDiff
2020/05/15 09:51:43 [TRACE] <root>: eval: *terraform.EvalApplyPost
2020/05/15 09:51:43 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: Error creating Spaces bucket: InvalidRequest: Malformed request
        status code: 400, request id: , host id: 
2020/05/15 09:51:43 [ERROR] <root>: eval: *terraform.EvalSequence, err: Error creating Spaces bucket: InvalidRequest: Malformed request
        status code: 400, request id: , host id: 
2020/05/15 09:51:43 [TRACE] [walkApply] Exiting eval tree: digitalocean_spaces_bucket.shop_images
2020/05/15 09:51:43 [TRACE] vertex "digitalocean_spaces_bucket.shop_images": visit complete
2020/05/15 09:51:43 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2020/05/15 09:51:43 [TRACE] dag/walk: upstream of "provider.digitalocean (close)" errored, so skipping
2020/05/15 09:51:43 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020/05/15 09:51:43 [TRACE] statemgr.Filesystem: not making a backup, because the new snapshot is identical to the old
2020/05/15 09:51:43 [TRACE] statemgr.Filesystem: no state changes since last snapshot
2020/05/15 09:51:43 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate

I have no clue what is blocking here.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 15, 2020
Accepted Answer

The error being returned by the API here is unclear, but the cause is the underscore (_) in the Space name. In the control panel, when creating a new Space, it notes that names must be between 3 and 63 characters long and may only contain letters, numbers, dots (.), and dashes (-).

Thanks @aboeglin67 and @asb. You were both right. I did at first had the problem with the underscore but then I also had the problem with the non-unique spaces name. I thought that names would not need to be unique if you link them to a project but I guess it is not the case.

Thank you very much.

I’m not certain but my bet is that this bucket already exists. I believe like on aws the names must be unique for each data center. And shop_images seem very generic not to already exist. Try prefixing the name with your project’s name or slug.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.