Skip to content

Commit

Permalink
updated godo, added 're-assign' test
Browse files Browse the repository at this point in the history
  • Loading branch information
imaskm committed Dec 11, 2024
1 parent 7994218 commit cd7448d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func resourceDigitalOceanReservedIPV6AssignmentCreate(ctx context.Context, d *sc
d.SetId(id.PrefixedUniqueId(fmt.Sprintf("%d-%s-", dropletID, ipAddress)))

return resourceDigitalOceanReservedIPV6AssignmentRead(ctx, d, meta)

}

func resourceDigitalOceanReservedIPV6AssignmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,39 @@ func TestAccDigitalOceanReservedIPV6Assignment_createBeforeDestroy(t *testing.T)
})
}

func TestAccDigitalOceanReservedIPV6Assignment_unassignAndAssignToNewDroplet(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanReservedIPV6Destroy,
Steps: []resource.TestStep{
{
Config: testAccCheckDigitalOceanReservedIPV6AssignmentConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "ip", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
},
{
Config: testAccCheckDigitalOceanReservedIPV6AssignmentUnAssign,
},
{
Config: testAccCheckDigitalOceanReservedIPV6ReAssignmentConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "ip", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
},
},
})
}

func testAccCheckDigitalOceanReservedIPV6AttachmentExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -114,7 +147,7 @@ resource "digitalocean_reserved_ipv6" "foobar" {
resource "digitalocean_droplet" "foobar" {
count = 1
name = "tf-acc-test-${count.index}"
name = "tf-acc-test-assign"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
Expand All @@ -127,6 +160,50 @@ resource "digitalocean_reserved_ipv6_assignment" "foobar" {
}
`

var testAccCheckDigitalOceanReservedIPV6AssignmentUnAssign = `
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}
resource "digitalocean_droplet" "foobar" {
count = 1
image = "ubuntu-22-04-x64"
name = "tf-acc-test-assign"
region = "nyc3"
size = "s-1vcpu-1gb"
ipv6 = true
}
`

var testAccCheckDigitalOceanReservedIPV6ReAssignmentConfig = `
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
}
resource "digitalocean_droplet" "foobar1" {
count = 1
name = "tf-acc-test-reassign"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
}
resource "digitalocean_droplet" "foobar" {
count = 1
name = "tf-acc-test-assign"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
ip = digitalocean_reserved_ipv6.foobar.ip
droplet_id = digitalocean_droplet.foobar1.0.id
}
`

var testAccCheckDigitalOceanReservedIPV6AssignmentDeleteAssignment = `
resource "digitalocean_reserved_ipv6" "foobar" {
region_slug = "nyc3"
Expand All @@ -139,7 +216,6 @@ resource "digitalocean_droplet" "foobar" {
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
}
`

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean

require (
github.com/aws/aws-sdk-go v1.42.18
github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918
github.com/digitalocean/godo v1.131.1
github.com/hashicorp/awspolicyequivalence v1.5.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918 h1:7xOw7i5AFH1n5vIMMH7HtR87jdxV8XnLKOBafNbVetM=
github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/digitalocean/godo v1.131.1 h1:2QsRwjNukKgOQbflMxOsTDoC05o5UKBpqQMFKXegYKE=
github.com/digitalocean/godo v1.131.1/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down
3 changes: 3 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/godo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions vendor/github.com/digitalocean/godo/reserved_ipv6.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
# github.com/davecgh/go-spew v1.1.1
## explicit
github.com/davecgh/go-spew/spew
# github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918
# github.com/digitalocean/godo v1.131.1
## explicit; go 1.22
github.com/digitalocean/godo
github.com/digitalocean/godo/metrics
Expand Down

0 comments on commit cd7448d

Please sign in to comment.