terraform-provider-digitalocean icon indicating copy to clipboard operation
terraform-provider-digitalocean copied to clipboard

Export endpoint for `digitalocean_spaces_bucket` resource and data source

Open dro-sh opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I would like to use digitalocean_spaces_bucket data source. I need endpoint for bucket because S3 API requires just endpoint without bucket name. Just ams3.digitaloceanspaces.com, not my-bucket.ams3.digitalocean.com

Describe the solution you'd like

Get exported attribute endpoint at digitalocean_spaces_bucket resource and data source

Describe alternatives you've considered

Additional context

As I understand this attribute should be added there and add helper function like bucketEndpoint(region string)

dro-sh avatar Feb 11 '22 08:02 dro-sh

Thanks for the request @dro-sh That does seem like it would be a useful addition. In the mean time, you should be able to infer the endpoint from the region using something like this as a workaround.

format("%s.digitaloceanspaces.com",  digitalocean_spaces_bucket.my-bucket.region)

https://www.terraform.io/language/functions/format#format-function

andrewsomething avatar Feb 11 '22 16:02 andrewsomething

Hello, I'd like to work on this issue for Hacktoberfest 2022!

I intend to add an endpoint attribute to the digitalocean_spaces_bucket data source and resource that will be available as an output.

Example terraform manifest

# terraform-provider-digitalocean/examples/spaces/main.tf
terraform {
  required_providers {
    digitalocean = {
      source = "digitalocean/digitalocean"
      version = ">= 2.22.3"
    }
  }
}

provider "digitalocean" {}

resource "digitalocean_spaces_bucket" "example" {
  name   = "unique-bucket-cc7bf683"
  region = "nyc3"
}

output "bucket_attributes" {
    value = digitalocean_spaces_bucket.example
}

Current output with Terraform 1.3.1 and terraform-provider-digitalocean_v2.22.3

root@335ea5343560:/go/src/github.com/digitalocean/terraform-provider-digitalocean/examples/spaces# terraform plan -out tf.plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # digitalocean_spaces_bucket.example will be created
  + resource "digitalocean_spaces_bucket" "example" {
      + acl                = "private"
      + bucket_domain_name = (known after apply)
      + force_destroy      = false
      + id                 = (known after apply)
      + name               = "unique-bucket-cc7bf683"
      + region             = "nyc3"
      + urn                = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + bucket_attributes = {
      + acl                = "private"
      + bucket_domain_name = (known after apply)
      + cors_rule          = []
      + force_destroy      = false
      + id                 = (known after apply)
      + lifecycle_rule     = []
      + name               = "unique-bucket-cc7bf683"
      + region             = "nyc3"
      + urn                = (known after apply)
      + versioning         = []
    }

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: tf.plan

To perform exactly these actions, run the following command to apply:
    terraform apply "tf.plan"


root@335ea5343560:/go/src/github.com/digitalocean/terraform-provider-digitalocean/examples/spaces# terraform apply -auto-approve "tf.plan"              
digitalocean_spaces_bucket.example: Creating...
digitalocean_spaces_bucket.example: Still creating... [10s elapsed]
digitalocean_spaces_bucket.example: Still creating... [20s elapsed]
digitalocean_spaces_bucket.example: Still creating... [30s elapsed]
digitalocean_spaces_bucket.example: Creation complete after 39s [id=unique-bucket-cc7bf683]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

bucket_attributes = {
  "acl" = "private"
  "bucket_domain_name" = "unique-bucket-cc7bf683.nyc3.digitaloceanspaces.com"
  "cors_rule" = tolist([])
  "force_destroy" = false
  "id" = "unique-bucket-cc7bf683"
  "lifecycle_rule" = tolist([])
  "name" = "unique-bucket-cc7bf683"
  "region" = "nyc3"
  "urn" = "do:space:unique-bucket-cc7bf683"
  "versioning" = tolist([
    {
      "enabled" = false
    },
  ])
}

New output after change:

root@335ea5343560:/go/src/github.com/digitalocean/terraform-provider-digitalocean/examples/spaces# terraform plan -out tf.plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # digitalocean_spaces_bucket.example will be created
  + resource "digitalocean_spaces_bucket" "example" {
      + acl                = "private"
      + bucket_domain_name = (known after apply)
      + endpoint           = (known after apply)
      + force_destroy      = false
      + id                 = (known after apply)
      + name               = "unique-bucket-cc7bf683"
      + region             = "nyc3"
      + urn                = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + bucket_attributes = {
      + acl                = "private"
      + bucket_domain_name = (known after apply)
      + cors_rule          = []
      + endpoint           = (known after apply)
      + force_destroy      = false
      + id                 = (known after apply)
      + lifecycle_rule     = []
      + name               = "unique-bucket-cc7bf683"
      + region             = "nyc3"
      + urn                = (known after apply)
      + versioning         = []
    }

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: tf.plan

To perform exactly these actions, run the following command to apply:
    terraform apply "tf.plan"
root@335ea5343560:/go/src/github.com/digitalocean/terraform-provider-digitalocean/examples/spaces# terraform apply -auto-approve "tf.plan"
digitalocean_spaces_bucket.example: Creating...
digitalocean_spaces_bucket.example: Still creating... [10s elapsed]
digitalocean_spaces_bucket.example: Still creating... [20s elapsed]
digitalocean_spaces_bucket.example: Still creating... [30s elapsed]
digitalocean_spaces_bucket.example: Still creating... [40s elapsed]
digitalocean_spaces_bucket.example: Creation complete after 48s [id=unique-bucket-cc7bf683]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

bucket_attributes = {
  "acl" = "private"
  "bucket_domain_name" = "unique-bucket-cc7bf683.nyc3.digitaloceanspaces.com"
  "cors_rule" = tolist([])
  "endpoint" = "nyc3.digitaloceanspaces.com"
  "force_destroy" = false
  "id" = "unique-bucket-cc7bf683"
  "lifecycle_rule" = tolist([])
  "name" = "unique-bucket-cc7bf683"
  "region" = "nyc3"
  "urn" = "do:space:unique-bucket-cc7bf683"
  "versioning" = tolist([
    {
      "enabled" = false
    },
  ])
}

I can submit a draft PR on 10/1. Let me know what you think!

selborsolrac avatar Sep 29 '22 03:09 selborsolrac

That looks great @selborsolrac! Feel free to tag me for a review when you're ready to open a PR.

andrewsomething avatar Sep 29 '22 17:09 andrewsomething

Closed via https://github.com/digitalocean/terraform-provider-digitalocean/pull/886

Thanks for the great work @selborsolrac!

andrewsomething avatar Oct 04 '22 14:10 andrewsomething