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

Bug .accelerated_pullzone #5

Closed
s5002557 opened this issue Aug 28, 2024 · 4 comments
Closed

Bug .accelerated_pullzone #5

s5002557 opened this issue Aug 28, 2024 · 4 comments

Comments

@s5002557
Copy link

Test terraform code:

terraform {
  required_providers {
    bunnynet = {
      source  = "BunnyWay/bunnynet"
      version = "0.3.9"
    }
  }
}
provider "bunnynet" {
  api_key = "***"
}

resource "bunnynet_dns_zone" "example" {
  domain            = "test.me"
  nameserver_custom = true
  nameserver1       = "testme.bunny.net"
  nameserver2       = "testme.bunny.net"
  soa_email         = "[email protected]"
}

resource "bunnynet_dns_record" "A" {
  zone = bunnynet_dns_zone.example.id

  name        = ""
  type        = "A"
  value       = "12.12.12.12"
  accelerated = true
  enabled     = true
  #   accelerated_pullzone = bunnynet_pullzone.example.id
}

Error:

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to bunnynet_dns_record.A, provider "provider[\"registry.terraform.io/bunnyway/bunnynet\"]" produced an unexpected new value: .accelerated_pullzone: was cty.NumberIntVal(0), but now cty.NumberIntVal(2.476977e+06).
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
@rafael-at-bunny
Copy link
Collaborator

Hi,

Thank you for your report.

Unfortunately, the accelerated_pullzone field cannot be set, as a new pullzone will be automatically created when you set accelerated = true. I've updated the provider to expose accelerated_pullzone as a read-only field. The fix is released on v0.3.10.

Thank you.

@rafael-at-bunny
Copy link
Collaborator

To import the accelerated pullzone into your terraform plan, you can use the following:

resource "bunnynet_dns_zone" "example" {
  domain = "my.domain"
}

resource "bunnynet_dns_record" "A" {
  zone = bunnynet_dns_zone.example.id

  name        = ""
  type        = "A"
  value       = "192.0.2.1"
  accelerated = true
  enabled     = true
}

resource "bunnynet_pullzone" "example" {
  name = "generated-pullzone-name"

  origin {
    type = "DnsAccelerate"
    url = "https://192.0.2.1:443/"
    forward_host_header = true
  }

  routing {
    tier = "Standard"
  }

  cache_enabled = true
  strip_cookies = false
}

import {
  id = bunnynet_dns_record.A.accelerated_pullzone
  to = bunnynet_pullzone.example
}

The import block requires Terraform v1.5.0 or above. For versions prior to that, you'll have to create the bunnynet_dns_record first and then import the pullzone.

Thank you.

@s5002557
Copy link
Author

Thank you. The new release fixed the error! However, when I try to use import, I have two problems.
My code:

resource "bunnynet_dns_zone" "example" {
  domain = "testbunnynet.com"
  nameserver_custom = true
  nameserver1       = "testbunnynetcom1.bunny.net"
  nameserver2       = "testbunnynetcom2.bunny.net"
  soa_email         = "[email protected]"
}

resource "bunnynet_dns_record" "A" {
  zone = bunnynet_dns_zone.example.id

  name        = ""
  type        = "A"
  value       = "12.12.12.12"
  accelerated = true
  enabled     = true
}

resource "bunnynet_pullzone" "example" {
  depends_on = [bunnynet_dns_record.A]
  name = "testcom-pullzone"

  origin {
    type = "DnsAccelerate"
    url = "12.12.12.12"
    forward_host_header = true
  }

  routing {
    tier = "Standard"
  }

  cache_enabled = true
  strip_cookies = false
}

import {
  id = bunnynet_dns_record.A.accelerated_pullzone
  to = bunnynet_pullzone.example
}

error:

╷
│ Error: Invalid import id argument
│ 
│   on dns_zone.tf line 157, in import:
│  157:   id = bunnynet_dns_record.A.accelerated_pullzone
│ 
│ The import block "id" argument depends on resource attributes that cannot be determined until apply, so Terraform cannot plan to import this resource.

I comment out a line of code import and resource "bunnynet_pullzone", run terrafrom and then run terraform again wihout comment.
error:

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to bunnynet_pullzone.example, provider "provider[\"registry.terraform.io/bunnyway/bunnynet\"]" produced an unexpected new value: .origin.type: was cty.StringVal("DnsAccelerate"), but now
│ cty.StringVal("OriginUrl").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to bunnynet_pullzone.example, provider "provider[\"registry.terraform.io/bunnyway/bunnynet\"]" produced an unexpected new value: .origin.url: was cty.StringVal("12.12.12.12"), but now
│ cty.StringVal("http://12.12.12.12").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

I tried setting url = "https://12.12.12.12" and changing type = "DnsAccelerate" to type = "OriginUrl".
I think the correct parameter is DnsAccelerate, but Terraform sees OriginUrl."

Could you please provide guidance on how to modify the code to enable Terraform to create all required resources in a single run, eliminating the need for a second Terraform execution? Additionally, should I submit a new bug report for the second issue?

@rafael-at-bunny
Copy link
Collaborator

Hi!

From what I am reading, terraform itself does not have support for doing this in a single call: hashicorp/terraform#34152 (comment)

When doing it with two calls (first without import and pullzone), I had success importing the pullzone with the following block:

resource "bunnynet_pullzone" "example" {
  name = "d73a02cb-d"
  origin {
    type = "DnsAccelerate"
    url = "http://12.12.12.12"
    forward_host_header = true
  }
  routing {
    tier = "Standard"
  }
  cache_enabled = true
  strip_cookies = false
}

This should result in a "clean" plan, where it will only import the pullzone without any changes:

$ terraform plan 
bunnynet_dns_zone.example: Refreshing state...
bunnynet_dns_record.A: Refreshing state...
bunnynet_pullzone.example: Preparing import... [id=2481791]
bunnynet_pullzone.example: Refreshing state... [name=d73a02cb-d]

Terraform will perform the following actions:

  # bunnynet_pullzone.example will be imported
    resource "bunnynet_pullzone" "example" {
        [removed]
        name                                  = "d73a02cb-d"
        [removed]

        origin {
            follow_redirects    = false
            forward_host_header = true
            host_header         = null
            type                = "DnsAccelerate"
            url                 = "http://12.12.12.12"
            verify_ssl          = false
        }

        [removed]
    }

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

Thank you.

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

No branches or pull requests

2 participants