-
Notifications
You must be signed in to change notification settings - Fork 636
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
Conversation
@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 |
Hi @catsby is there anything else we need to do here or can this be merged? |
There was a problem hiding this 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"), |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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
cloudflare/utils.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
@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 |
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: Here's a simple configuration I'm using:
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? |
Here's debug log info from the log:
|
@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: 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? |
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 🤔 [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 ... |
The reason it "doesn't show in the API" is that the provider is using the 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. |
Thanks @elithrar ! You're this mornings hero 😄 I've verified the test pool I created is there with the orgs endpoint |
@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 |
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 |
Thanks @benjvi! |
Looks good now @benjvi , thanks!
|
Continued from #31 . Reopening this so others can contribute to address issues identified there in the next few days