Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reserved ipv6 resource #1277

Merged
merged 14 commits into from
Dec 11, 2024
Merged

Conversation

imaskm
Copy link
Contributor

@imaskm imaskm commented Nov 26, 2024

This PR adds a new resource "reserved_ipv6"

@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 3970caa to ee9364d Compare November 26, 2024 09:50
@loosla
Copy link
Contributor

loosla commented Nov 28, 2024

Nice work! Let's update terraform-provider-digitalocean/digitalocean/provider.go to be able to run terraform plan.

Let's add

"digitalocean_reserved_ipv6":            reservedipv6.DataSourceDigitalOceanReservedIPV6(),

to DataSourcesMap: map[string]*schema.Resource

and

"digitalocean_reserved_ipv6":                         reservedipv6.ResourceDigitalOceanReservedIPV6(),
"digitalocean_reserved_ipv6_assignment":              reservedipv6.ResourceDigitalOceanReservedIPV6Assignment(),

to ResourcesMap: map[string]*schema.Resource


Here are some notes that will help you to check your changes locally

  1. to apply your changes you need to rebuild terraform with make build from the root of the project:
    terraform-provider-digitalocean$ make build
  2. When it's rebuilt, from the root of the project you can run
mkdir -p examples/my-tf
touch examples/my-tf/main.tf

to create a terraform config

Here is the example of the main.tf you can run (please update the token with your token):

terraform {
  required_providers {
    digitalocean = {
      source  = "digitalocean/digitalocean"
      version = ">= 5.3"
    }
  }
}

provider "digitalocean" {
  token = "dop_v1_12345d7ce104413a59023656565"
}

resource "digitalocean_droplet" "foobar-my-tf" {
  image  = "ubuntu-22-04-x64"
  name   = "tf-acc-test-my-tf"
  region = "nyc3"
  size   = "s-1vcpu-1gb"
}
  1. Then
cd examples/my-tf
terraform plan
  1. If changes that will be performed look good to you can run
terraform apply

This will use with your real DigitalOcean account by using your token. It's a good practice to remove created resources when you are done.

  1. If you want to see more logs, run
export TF_LOG=DEBUG

or if you want more detailed logs:

export TF_LOG=TRACE

Then you will see more logs when you run terraform plan or terraform apply.

@loosla
Copy link
Contributor

loosla commented Nov 28, 2024

Hey Ashwani,

Could you take a look please?
It doesn't look like the API is actually working. Let me know if I'm wrong 🙏

This is the curl command taken from your openapi PR:

curl -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
    -d '{"region_slug": "nyc3"}' \
    "https://api.digitalocean.com/v2/reserved_ipv6" 
{"error":"The path you're trying to reach does not exist"}

I'm seeing the same error form terraform when run terraform apply with this config:

resource "digitalocean_droplet" "foobar" {
  image  = "ubuntu-22-04-x64"
  name   = "tf-acc-test"
  region = "nyc3"
  size   = "s-1vcpu-1gb"
  ipv6   = true
}

resource "digitalocean_reserved_ipv6" "foobar" {
  droplet_id  = digitalocean_droplet.foobar.id
  region_slug = digitalocean_droplet.foobar.region
}

TF error

---[ REQUEST ]---------------------------------------
POST /v2/reserved_ipv6 HTTP/1.1
Host: api.digitalocean.com
User-Agent: Terraform/1.9.7 godo/1.131.0
Content-Length: 23
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

{
 "region_slug": "nyc3"
}

-----------------------------------------------------: timestamp=2024-11-28T15:51:14.483-0500
2024-11-28T15:51:14.483-0500 [INFO]  provider.terraform-provider-digitalocean: 2024/11/28 15:51:14 [DEBUG] POST https://api.digitalocean.com/v2/reserved_ipv6: timestamp=2024-11-28T15:51:14.483-0500
2024-11-28T15:51:14.586-0500 [INFO]  provider.terraform-provider-digitalocean: 2024/11/28 15:51:14 [DEBUG] DigitalOcean API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 404 Not Found
Cf-Cache-Status: DYNAMIC
Cf-Ray: 8e9d3c1f6b83ac36-YYZ
Content-Type: application/json
Date: Thu, 28 Nov 2024 20:51:14 GMT
Server: cloudflare
Set-Cookie: __cf_bm=EC8dKbhSZKB8X4kkhEktm6IUIZa458GUebcBV4wVVik-1732827074-1.0.1.1-ELfEPlbdHscry5VM0L57Du9xeSXB10GUhqWxGTlIVxsjUel8Kli6sLdaWGq3FZSjOXbV.301xhMLPG3qjYAi4ZHliEDnNmQqyBKj4zAxpcE; path=/; expires=Thu, 28-Nov-24 21:21:14 GMT; domain=.digitalocean.com; HttpOnly; Secure; SameSite=None
X-Gateway: Edge-Gateway
X-Response-From: Edge-Gateway

{
 "error": "The path you're trying to reach does not exist"
}

If the API call isn't functioning correctly, I believe it would be best to first ensure that the API endpoint is working properly before moving forward with Terraform, OpenAPI, or anything related to this endpoint.

@imaskm
Copy link
Contributor Author

imaskm commented Nov 29, 2024

Hey Ashwani,

Could you take a look please? It doesn't look like the API is actually working. Let me know if I'm wrong 🙏

This is the curl command taken from your openapi PR:

curl -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
    -d '{"region_slug": "nyc3"}' \
    "https://api.digitalocean.com/v2/reserved_ipv6" 
{"error":"The path you're trying to reach does not exist"}

I'm seeing the same error form terraform when run terraform apply with this config:

resource "digitalocean_droplet" "foobar" {
  image  = "ubuntu-22-04-x64"
  name   = "tf-acc-test"
  region = "nyc3"
  size   = "s-1vcpu-1gb"
  ipv6   = true
}

resource "digitalocean_reserved_ipv6" "foobar" {
  droplet_id  = digitalocean_droplet.foobar.id
  region_slug = digitalocean_droplet.foobar.region
}

TF error

---[ REQUEST ]---------------------------------------
POST /v2/reserved_ipv6 HTTP/1.1
Host: api.digitalocean.com
User-Agent: Terraform/1.9.7 godo/1.131.0
Content-Length: 23
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

{
 "region_slug": "nyc3"
}

-----------------------------------------------------: timestamp=2024-11-28T15:51:14.483-0500
2024-11-28T15:51:14.483-0500 [INFO]  provider.terraform-provider-digitalocean: 2024/11/28 15:51:14 [DEBUG] POST https://api.digitalocean.com/v2/reserved_ipv6: timestamp=2024-11-28T15:51:14.483-0500
2024-11-28T15:51:14.586-0500 [INFO]  provider.terraform-provider-digitalocean: 2024/11/28 15:51:14 [DEBUG] DigitalOcean API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 404 Not Found
Cf-Cache-Status: DYNAMIC
Cf-Ray: 8e9d3c1f6b83ac36-YYZ
Content-Type: application/json
Date: Thu, 28 Nov 2024 20:51:14 GMT
Server: cloudflare
Set-Cookie: __cf_bm=EC8dKbhSZKB8X4kkhEktm6IUIZa458GUebcBV4wVVik-1732827074-1.0.1.1-ELfEPlbdHscry5VM0L57Du9xeSXB10GUhqWxGTlIVxsjUel8Kli6sLdaWGq3FZSjOXbV.301xhMLPG3qjYAi4ZHliEDnNmQqyBKj4zAxpcE; path=/; expires=Thu, 28-Nov-24 21:21:14 GMT; domain=.digitalocean.com; HttpOnly; Secure; SameSite=None
X-Gateway: Edge-Gateway
X-Response-From: Edge-Gateway

{
 "error": "The path you're trying to reach does not exist"
}

If the API call isn't functioning correctly, I believe it would be best to first ensure that the API endpoint is working properly before moving forward with Terraform, OpenAPI, or anything related to this endpoint.

This feature is behind a flipper, that's why you are getting 404, please add yourself to https://flipperui.internal.digitalocean.com/features/reserved_ipv6

@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 979e174 to 12391cc Compare November 29, 2024 12:22
@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 12391cc to 890e30d Compare November 29, 2024 12:31
@imaskm
Copy link
Contributor Author

imaskm commented Nov 29, 2024

@loosla I have updated the changes you requested but I am getting this error while testing locally

2024-11-29T17:54:41.271+0530 [DEBUG] GET https://registry.terraform.io/v1/providers/digitalocean/digitalocean/versions
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for
│ provider digitalocean/digitalocean: no available releases
│ match the given constraints >= 5.3.0

@loosla
Copy link
Contributor

loosla commented Nov 29, 2024

Sorry about that.

  1. You can take the latest DO TF provider here: https://registry.terraform.io/providers/digitalocean/digitalocean/2.44.1
    Update config with
terraform {
  required_providers {
    digitalocean = {
      source  = "digitalocean/digitalocean"
      version = ">= 2.44.1"
    }
  }
}
  1. From examples/my-tf run teraform init
    or terraform init -upgrade if you already had another version of TF provider.

  2. You can check the results with terraform -v
    + provider registry.terraform.io/digitalocean/digitalocean v2.44.1 should be there.


I happened to update mine some time ago, but I didn't actually use it because I didn't re-initialised it. Good catch . Thanks for your feedback 👍

@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from e0c2eec to 9bb7f4a Compare November 29, 2024 17:17
@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 9bb7f4a to ba7f286 Compare November 29, 2024 17:23
@loosla
Copy link
Contributor

loosla commented Dec 2, 2024

👋 Ashwani, could you check the case below 🙏
I'm getting an error

Error deleting reserved IPv6: DELETE https://api.digitalocean.com/v2/reserved_ipv6/1234:1234800:14::4d86:1700: 400 (request "c6eeea2f-aaaa-47ee-bdc6-e50787c3edae") flipv6 released failed: assigned FLIP cannot be released

Steps:

  1. Create 2 dropets with different names and one resource digitalocean_reserved_ipv6 with droplet_id of the first droplet.
  2. Try to update digitalocean_reserved_ipv6 droplet_id with the value of the second droplet
    Here I'm getting
Error: Error waiting for reserved IP (1234:1234800:14::4d86:1700) to be Assigned: error retrieving reserved IPv6 (1234:1234800:14::4d86:1700) ActionId (1234543306): GET https://api.digitalocean.com/v2/actions/1234543306: 500 (request "1234c829c-ebd1-42c0-9428-019k20fa41d0") Server Error; giving up after 5 attempt(s)
  1. Then I'm trying to remove digitalocean_reserved_ipv6 by commenting it in my Terraform config and see the error:
Error deleting reserved IPv6: DELETE https://api.digitalocean.com/v2/reserved_ipv6/1234:1234800:14::4d86:1700: 400 (request "c6eeea2f-aaaa-47ee-bdc6-e50787c3edae") flipv6 released failed: assigned FLIP cannot be released

Looks like this digitalocean_reserved_ipv6 is stuck forever under my account as I can't remove it with curl as well:
{"id":"bad_request","message":"flipv6 released failed: assigned FLIP cannot be released","request_id":"8aetr1231-dca7-46df-ac08-44bd12931234"}

Could you please advise or do some fixes?
Many thanks

*Just in case I'm still able to create or delete resource "digitalocean_droplet", but I'm failing to update.

@imaskm
Copy link
Contributor Author

imaskm commented Dec 3, 2024

👋 Ashwani, could you check the case below 🙏 I'm getting an error

Error deleting reserved IPv6: DELETE https://api.digitalocean.com/v2/reserved_ipv6/1234:1234800:14::4d86:1700: 400 (request "c6eeea2f-aaaa-47ee-bdc6-e50787c3edae") flipv6 released failed: assigned FLIP cannot be released

Steps:

  1. Create 2 dropets with different names and one resource digitalocean_reserved_ipv6 with droplet_id of the first droplet.
  2. Try to update digitalocean_reserved_ipv6 droplet_id with the value of the second droplet
    Here I'm getting
Error: Error waiting for reserved IP (1234:1234800:14::4d86:1700) to be Assigned: error retrieving reserved IPv6 (1234:1234800:14::4d86:1700) ActionId (1234543306): GET https://api.digitalocean.com/v2/actions/1234543306: 500 (request "1234c829c-ebd1-42c0-9428-019k20fa41d0") Server Error; giving up after 5 attempt(s)
  1. Then I'm trying to remove digitalocean_reserved_ipv6 by commenting it in my Terraform config and see the error:
Error deleting reserved IPv6: DELETE https://api.digitalocean.com/v2/reserved_ipv6/1234:1234800:14::4d86:1700: 400 (request "c6eeea2f-aaaa-47ee-bdc6-e50787c3edae") flipv6 released failed: assigned FLIP cannot be released

Looks like this digitalocean_reserved_ipv6 is stuck forever under my account as I can't remove it with curl as well: {"id":"bad_request","message":"flipv6 released failed: assigned FLIP cannot be released","request_id":"8aetr1231-dca7-46df-ac08-44bd12931234"}

Could you please advise or do some fixes? Many thanks

*Just in case I'm still able to create or delete resource "digitalocean_droplet", but I'm failing to update.

There are 2 issues which are causing these failures, PRs are up for both, I will update you once those are deployed.

@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 3378957 to fded416 Compare December 10, 2024 10:18
@loosla loosla self-assigned this Dec 10, 2024
@loosla
Copy link
Contributor

loosla commented Dec 10, 2024

@imaskm Could you please run make terrafmt from the root of the project to fix an indention in digitalocean/reservedipv6/resource_reserved_ipv6_test.go and push a changed file.
This should help tests to pass. Thank you.

@imaskm
Copy link
Contributor Author

imaskm commented Dec 10, 2024

@imaskm Could you please run make terrafmt from the root of the project to fix an indention in digitalocean/reservedipv6/resource_reserved_ipv6_test.go and push a changed file. This should help tests to pass. Thank you.

Done @loosla thanks

@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 7909622 to 646e5e8 Compare December 10, 2024 18:11
@imaskm imaskm requested a review from loosla December 10, 2024 18:13
@imaskm imaskm requested a review from loosla December 11, 2024 08:24
@loosla
Copy link
Contributor

loosla commented Dec 11, 2024

@imaskm Ashwani, Looks good to me 👍 Thanks for your patience and all updates 🙏

Could you just add one acceptance test that will ensure that we can assign reserved ipv6 to another droplet.
To show how this should be done.
I suppose you can use #1277 (comment) but change the name from reassigning to what describes it better for you.

Also, please update godo to the latest released 🙏 - v1.131.1
Thanks a lot!
Great job 👏

@imaskm imaskm force-pushed the add-reserved-ipv6-resource branch from 79dd3eb to cd7448d Compare December 11, 2024 19:39
Copy link
Contributor

@loosla loosla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks 🚀
Excellent job!

@loosla loosla merged commit 1712fca into digitalocean:main Dec 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants