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

Load balancer + load balancer pool resources (updated) #40

Merged
merged 15 commits into from
Apr 6, 2018

Conversation

benjvi
Copy link

@benjvi benjvi commented Mar 18, 2018

Continued from #31 . Reopening this so others can contribute to address issues identified there in the next few days

@nickithewatt
Copy link

@catsby, @benjvi answered some of your original review comments in #31, however there are still a few outstanding review items to address in this PR - we will get onto those this week.

@benjvi
Copy link
Author

benjvi commented Mar 23, 2018

@catsby merge conflicts now resolved here as well. Although at least the resources registered in the resources and list of resource links are likely to conflict again with the monitor PR. Otherwise, I think all the comments should have been addressed now

@prdonahue
Copy link

Hi @catsby is there anything else we need to do here or can this be merged?

@vancluever vancluever added kind/enhancement Categorizes issue or PR as related to improving an existing feature. kind/new-resource Categorizes issue or PR as related to creating a new resource. labels Mar 28, 2018
Copy link

@catsby catsby left a comment

Choose a reason for hiding this comment

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

The code looks good, just need the Set methods removed unless they are necessary, in which case we should document why.

},
},
},
Set: HashByMapKey("pop"),
Copy link

Choose a reason for hiding this comment

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

Custom Set methods are discouraged, unless there is a very specific reason for it.

},
},
},
Set: HashByMapKey("address"),
Copy link

Choose a reason for hiding this comment

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

Same custom Set comment here, remove unless there's a very good reason for this

@@ -28,3 +30,10 @@ func flattenIntList(list []int) []interface{} {
func IntIdentity(i interface{}) int {
return i.(int)
}

func HashByMapKey(key string) func(v interface{}) int {
Copy link

Choose a reason for hiding this comment

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

Assuming the custom Set methods are being removed, this should go too

@benjvi
Copy link
Author

benjvi commented Apr 4, 2018

@catsby - for the pool elements, removing the set function breaks the diff in case where duplicates are specified. However I guess its better to explicitly throw an error rather than quietly override the duplicate value. So I added a guard to throw an error when undesirable duplicates are added. I think this way is the clearest. Otherwise I removed the Set methods and cleaned up as suggested

@catsby
Copy link

catsby commented Apr 4, 2018

Hey @benjvi – I'm still getting an error when trying to create a load balancer pool. I can see on the console that I have load balancers enabled:

screen shot 2018-04-04 at 4 07 34 pm

Here's a simple configuration I'm using:

variable "zone" {
  default = "hashicorptest.com"
}

resource "cloudflare_load_balancer_pool" "foo" {
  name = "example-lb-pool"

  origins {
    name    = "example-1"
    address = "192.0.2.1"
    enabled = false
  }

  origins {
    name    = "example-2"
    address = "192.0.2.2"
  }
}

Here's the error/log I'm getting:

[opencredo-load-balancer](4)$ terraform apply 
cloudflare_load_balancer_pool.foo: Creating...
  check_regions.#:            "" => "<computed>"
  created_on:                 "" => "<computed>"
  enabled:                    "" => "true"
  minimum_origins:            "" => "1"
  modified_on:                "" => "<computed>"
  name:                       "" => "example-lb-pool"
  origins.#:                  "" => "2"
  origins.2744668579.address: "" => "192.0.2.2"
  origins.2744668579.enabled: "" => "true"
  origins.2744668579.name:    "" => "example-2"
  origins.3163022560.address: "" => "192.0.2.1"
  origins.3163022560.enabled: "" => "false"
  origins.3163022560.name:    "" => "example-1"

Error: Error applying plan:

1 error(s) occurred:

* cloudflare_load_balancer_pool.foo: 1 error(s) occurred:

* cloudflare_load_balancer_pool.foo: error creating load balancer pool: error from makeRequest: HTTP status 400: content "{\n  \"result\": null,\n  \"success\": false,\n  \"errors\": [\n    {\n      \"code\": 1002,\n      \"message\": \"the origin list length must be in range [1, 0]: validation failed\"\n    }\n  ],\n  \"messages\": []\n}\n"

Any ideas what I'm doing wrong or missing?

@catsby
Copy link

catsby commented Apr 4, 2018

Here's debug log info from the log:

2018-04-04T16:01:02.285-0500 [DEBUG] plugin.terraform-provider-cloudflare: 2018/04/04 16:01:02 [DEBUG] Creating CloudFlare Load Balancer Pool from struct: {ID: CreatedOn:<nil> ModifiedOn:<nil> Description: Name:example-lb-pool Enabled:true MinimumOrigins:1 Monitor: Origins:[{Name:example-1 Address:192.0.2.1 Enabled:false}] NotificationEmail: CheckRegions:[]}

@benjvi
Copy link
Author

benjvi commented Apr 4, 2018

@catsby That is a strange one. Is that log line with the same config?? I just ran with the same config you posted and I get this log line instead:
2018-04-04T22:20:10.254+0100 [DEBUG] plugin.terraform-provider-cloudflare: 2018/04/04 22:20:10 [DEBUG] Creating CloudFlare Load Balancer Pool from struct: {ID: CreatedOn:<nil> ModifiedOn:<nil> Description: Name:example-lb-pool Enabled:true MinimumOrigins:1 Monitor: Origins:[{Name:example-2 Address:192.0.2.2 Enabled:true} {Name:example-1 Address:192.0.2.1 Enabled:false}] NotificationEmail: CheckRegions:[]}

I.e. both origin elements present instead of just one, and with a successful result. Looking at the code I can't even see any place where it might drop elements. Very confusing.

Regardless, given the opaque/misleading error message I would still suspect something is different on the account. Although I don't know what it would be - can you create a pool manually in the GUI?

@catsby
Copy link

catsby commented Apr 5, 2018

Hrmm I'm not sure how I messed up the debug log, I didn't notice there was only one origin listed. Maybe I copied an older one, or one right before I added 2? Dunno ¯_(ツ)_/¯

I just tried again and get the same error, but with 2 origins included:

2018/04/05 10:24:20 [DEBUG] apply: cloudflare_load_balancer_pool.foo: executing Apply
cloudflare_load_balancer_pool.foo: Creating...
  check_regions.#:            "" => "<computed>"
2018-04-05T10:24:20.395-0500 [DEBUG] plugin.terraform-provider-cloudflare: 2018/04/05 10:24:20 [DEBUG] Creating CloudFlare Load Balancer Pool from struct: {ID: CreatedOn:<nil> ModifiedOn:<nil> Description: Name:example-lb-pool Enabled:true MinimumOrigins:1 Monitor: Origins:[{Name:example-2 Address:192.0.2.2 Enabled:true} {Name:example-1 Address:192.0.2.1 Enabled:false}] NotificationEmail: CheckRegions:[]}
  created_on:                 "" => "<computed>"
  enabled:                    "" => "true"
  minimum_origins:            "" => "1"
  modified_on:                "" => "<computed>"
  name:                       "" => "example-lb-pool"
  origins.#:                  "" => "2"
  origins.2744668579.address: "" => "192.0.2.2"
  origins.2744668579.enabled: "" => "true"
  origins.2744668579.name:    "" => "example-2"
  origins.3163022560.address: "" => "192.0.2.1"
  origins.3163022560.enabled: "" => "false"
  origins.3163022560.name:    "" => "example-1"
[...]

* cloudflare_load_balancer_pool.foo: error creating load balancer pool: error from makeRequest: HTTP status 400: content "{\n  \"result\": null,\n  \"success\": false,\n  \"errors\": [\n    {\n      \"code\": 1002,\n      \"message\": \"the origin list length must be in range [1, 0]: validation failed\"\n    }\n  ],\n  \"messages\": []\n}\n"

I have created a pool in the console, however, it doesn't show in the API 🤔

screen shot 2018-04-05 at 10 36 18 am

[opencredo-load-balancer](4)$ curl -X GET "https://api.cloudflare.com/client/v4/user/load_balancers/pools" -H "X-Auth-Email: $CLOUDFLARE_EMAIL" -H "X-Auth-Key: $CLOUDFLARE_TOKEN" -H "Content-Type: application/json"
{
  "result": [],
  "success": true,
  "errors": [],
  "messages": []
}

[opencredo-load-balancer](4)$ curl -s -X GET "https://api.cloudflare.com/client/v4/user" -H "X-Auth-Email: $CLOUDFLARE_EMAIL" -H "X-Auth-Key: $CLOUDFLARE_TOKEN" -H "Content-Type: application/json" | jq .
{
  "result": {
    "id": "<redacted>",
    "email": "terraform-acctest@hashicorp.com",
[.......]
}

I'll have to ask my contacts at Cloudflare ...

@elithrar
Copy link

elithrar commented Apr 5, 2018

The reason it "doesn't show in the API" is that the provider is using the /user endpoint, but the pools were (correctly) created under the /organization (our term for a "team"). Pools created under a user are only visible by you, not the rest of your team, which is never what you want.

The Provider should use the organization endpoints when the zone is owned by an organization, else the pools can never be attached to a Load Balancer.

@catsby
Copy link

catsby commented Apr 5, 2018

Thanks @elithrar ! You're this mornings hero 😄 I've verified the test pool I created is there with the orgs endpoint

@benjvi
Copy link
Author

benjvi commented Apr 6, 2018

@catsby All is working for me now in my newly organizations-enabled account. Can you verify? You will need to export CLOUDFLARE_ORG_ID to get the tests working (or CLOUDFLARE_ORG_ZONE which does a -somewhat convoluted- lookup using the Zone Name). This seems like the only way to get consistent behaviour when creating resources like load balancer pools which aren't in themselves associated with a zone

@benjvi
Copy link
Author

benjvi commented Apr 6, 2018

Unexpectedly, I also found the performance of API calls looked very different when using the organizations API and rate limiting started causing some problems due to the tests being in parallel. I also made the other provider config fields settable through environment variables to avoid such issues

@elithrar
Copy link

elithrar commented Apr 6, 2018

Thanks @benjvi!

@catsby
Copy link

catsby commented Apr 6, 2018

Looks good now @benjvi , thanks!

TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccCloudFlareLoadBalancer -timeout 120m
?       github.com/terraform-providers/terraform-provider-cloudflare    [no test files]
=== RUN   TestAccCloudFlareLoadBalancerMonitor_Import
=== PAUSE TestAccCloudFlareLoadBalancerMonitor_Import
=== RUN   TestAccCloudFlareLoadBalancerPool_Import
=== PAUSE TestAccCloudFlareLoadBalancerPool_Import
=== RUN   TestAccCloudFlareLoadBalancer_Import
=== PAUSE TestAccCloudFlareLoadBalancer_Import
=== RUN   TestAccCloudFlareLoadBalancerMonitor_Basic
=== PAUSE TestAccCloudFlareLoadBalancerMonitor_Basic
=== RUN   TestAccCloudFlareLoadBalancerMonitor_FullySpecified
=== PAUSE TestAccCloudFlareLoadBalancerMonitor_FullySpecified
=== RUN   TestAccCloudFlareLoadBalancerMonitor_Update
=== PAUSE TestAccCloudFlareLoadBalancerMonitor_Update
=== RUN   TestAccCloudFlareLoadBalancerMonitor_CreateAfterManualDestroy
=== PAUSE TestAccCloudFlareLoadBalancerMonitor_CreateAfterManualDestroy
=== RUN   TestAccCloudFlareLoadBalancerPool_Basic
=== PAUSE TestAccCloudFlareLoadBalancerPool_Basic
=== RUN   TestAccCloudFlareLoadBalancerPool_FullySpecified
=== PAUSE TestAccCloudFlareLoadBalancerPool_FullySpecified
=== RUN   TestAccCloudFlareLoadBalancerPool_ForceNew
=== PAUSE TestAccCloudFlareLoadBalancerPool_ForceNew
=== RUN   TestAccCloudFlareLoadBalancerPool_CreateAfterManualDestroy
=== PAUSE TestAccCloudFlareLoadBalancerPool_CreateAfterManualDestroy
=== RUN   TestAccCloudFlareLoadBalancer_Basic
=== PAUSE TestAccCloudFlareLoadBalancer_Basic
=== RUN   TestAccCloudFlareLoadBalancer_GeoBalanced
=== PAUSE TestAccCloudFlareLoadBalancer_GeoBalanced
=== RUN   TestAccCloudFlareLoadBalancer_DuplicatePool
=== PAUSE TestAccCloudFlareLoadBalancer_DuplicatePool
=== RUN   TestAccCloudFlareLoadBalancer_Update
=== PAUSE TestAccCloudFlareLoadBalancer_Update
=== RUN   TestAccCloudFlareLoadBalancer_CreateAfterManualDestroy
=== PAUSE TestAccCloudFlareLoadBalancer_CreateAfterManualDestroy
=== CONT  TestAccCloudFlareLoadBalancerMonitor_Import
=== CONT  TestAccCloudFlareLoadBalancerPool_ForceNew
=== CONT  TestAccCloudFlareLoadBalancerMonitor_Update
=== CONT  TestAccCloudFlareLoadBalancer_CreateAfterManualDestroy
=== CONT  TestAccCloudFlareLoadBalancer_Update
=== CONT  TestAccCloudFlareLoadBalancer_DuplicatePool
=== CONT  TestAccCloudFlareLoadBalancer_GeoBalanced
=== CONT  TestAccCloudFlareLoadBalancer_Basic
--- PASS: TestAccCloudFlareLoadBalancer_DuplicatePool (2.05s)
=== CONT  TestAccCloudFlareLoadBalancerPool_CreateAfterManualDestroy
--- PASS: TestAccCloudFlareLoadBalancerMonitor_Import (2.23s)
=== CONT  TestAccCloudFlareLoadBalancer_Import
--- PASS: TestAccCloudFlareLoadBalancerMonitor_Update (6.52s)
=== CONT  TestAccCloudFlareLoadBalancerMonitor_FullySpecified
--- PASS: TestAccCloudFlareLoadBalancerMonitor_FullySpecified (2.51s)
=== CONT  TestAccCloudFlareLoadBalancerPool_Basic
--- PASS: TestAccCloudFlareLoadBalancer_Basic (9.82s)
=== CONT  TestAccCloudFlareLoadBalancerPool_FullySpecified
--- PASS: TestAccCloudFlareLoadBalancerPool_ForceNew (9.89s)
=== CONT  TestAccCloudFlareLoadBalancerMonitor_CreateAfterManualDestroy
--- PASS: TestAccCloudFlareLoadBalancer_GeoBalanced (10.49s)
=== CONT  TestAccCloudFlareLoadBalancerPool_Import
--- PASS: TestAccCloudFlareLoadBalancerPool_CreateAfterManualDestroy (9.03s)
=== CONT  TestAccCloudFlareLoadBalancerMonitor_Basic
--- PASS: TestAccCloudFlareLoadBalancer_Update (11.71s)
--- PASS: TestAccCloudFlareLoadBalancer_Import (9.48s)
--- PASS: TestAccCloudFlareLoadBalancerPool_Basic (2.71s)
--- PASS: TestAccCloudFlareLoadBalancer_CreateAfterManualDestroy (12.00s)
--- PASS: TestAccCloudFlareLoadBalancerPool_FullySpecified (2.65s)
--- PASS: TestAccCloudFlareLoadBalancerMonitor_Basic (2.47s)
--- PASS: TestAccCloudFlareLoadBalancerPool_Import (4.64s)
--- PASS: TestAccCloudFlareLoadBalancerMonitor_CreateAfterManualDestroy (5.51s)
PASS
ok      github.com/terraform-providers/terraform-provider-cloudflare/cloudflare 15.420s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Categorizes issue or PR as related to improving an existing feature. kind/new-resource Categorizes issue or PR as related to creating a new resource.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants