问题
I am able to create VLANs using control.softlayer.com (we have the automated VLAN ordering flag turned on). However, when I attempt to use the Terraform provider from github slash ibm-bluemix.github.io/tf-ibm-docs/v0.3-tf-v0.9.3/r/infra_vlan.html, I get an error. I am using the API key from my account, so permissions should be the same.
Here's the .tf file content:
resource "ibmcloud_infra_vlan" "dev_vlan_01" {
name = "pancakes_dev_vlan_01"
datacenter = "FRA02"
type = "PRIVATE"
subnet_size = 8
router_hostname = "bcr01a.fra02"
}
Here's the error:
Error applying plan:
1 error(s) occurred:
* ibmcloud_infra_vlan.dev_vlan_01: 1 error(s) occurred:
* ibmcloud_infra_vlan.dev_vlan_01: Error creating vlan: SoftLayer_Exception_Public: Access Denied. (HTTP 401)
the contents of my ~/.softlayer file are:
[softlayer]
username = <username as it appears in users list in control.softlayer.com>
api_key = <api key as it appears both in my Profile page and in the users list>
Thanks in advance!
Update 1:
It appears that the new build of the plugin no longer looks at ~/.softlayer. Makes sense that I'm getting 401s then - it looks like the plugin is being executed with no credentials. After looking at the code here https://github.com/IBM-Bluemix/terraform/blob/v0.3-tf-v0.9.3/builtin/providers/ibmcloud/provider.go I've tried setting the SL_USERNAME and SL_API_KEY environment variables to no apparent effect. I also tried adding a provider "bluemix"
section with the credentials in it to my .tf file, also seemingly with no effect.
Update 2:
Figured out that I need to be using the "vpn" username (not the username from the Users page) and now the environment variables are working. However, terraform apply
results in a crash:
$ terraform apply
ibmcloud_infra_vlan.dev_vlan_01: Creating...
child_resource_count: "" => "<computed>"
datacenter: "" => "FRA02"
name: "" => "pancakes_dev_vlan_01"
router_hostname: "" => "bcr01a.fra02"
softlayer_managed: "" => "<computed>"
subnet_size: "" => "8"
subnets.#: "" => "<computed>"
type: "" => "PRIVATE"
vlan_number: "" => "<computed>"
Error applying plan:
1 error(s) occurred:
* ibmcloud_infra_vlan.dev_vlan_01: 1 error(s) occurred:
* ibmcloud_infra_vlan.dev_vlan_01: unexpected EOF
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
panic: runtime error: invalid memory address or nil pointer dereference
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x17a61bb]
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64:
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: goroutine 68 [running]:
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: github.com/hashicorp/terraform/builtin/providers/ibmcloud.buildVlanProductOrderContainer(0xc4203b00e0, 0xc420392070, 0x1a293c6, 0x20, 0xc420349300, 0x0, 0xc42000e998)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /Users/akthakur/git/terraformgo/src/github.com/hashicorp/terraform/builtin/providers/ibmcloud/resource_ibmcloud_infra_vlan.go:386 +0x9fb
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: github.com/hashicorp/terraform/builtin/providers/ibmcloud.resourceIBMCloudInfraVlanCreate(0xc4203b00e0, 0x19b2c00, 0xc4203920e0, 0x0, 0x0)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /Users/akthakur/git/terraformgo/src/github.com/hashicorp/terraform/builtin/providers/ibmcloud/resource_ibmcloud_infra_vlan.go:125 +0x20b
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc42036ede0, 0xc420016f50, 0xc420396760, 0x19b2c00, 0xc4203920e0, 0x1, 0x28, 0xc4202adcb0)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /Users/akthakur/git/terraformgo/src/github.com/hashicorp/terraform/helper/schema/resource.go:186 +0x48d
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc4202b37a0, 0xc420016f00, 0xc420016f50, 0xc420396760, 0x213b000, 0x0, 0x0)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /Users/akthakur/git/terraformgo/src/github.com/hashicorp/terraform/helper/schema/provider.go:242 +0x9b
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0xc42034ed80, 0xc4203961c0, 0xc420349260, 0x0, 0x0)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /Users/akthakur/git/terraformgo/src/github.com/hashicorp/terraform/plugin/resource_provider.go:488 +0x57
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: reflect.Value.call(0xc42026d6e0, 0xc4202cad40, 0x13, 0x1a0662e, 0x4, 0xc420042f20, 0x3, 0x3, 0x0, 0x0, ...)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /usr/local/go/src/reflect/value.go:434 +0x91f
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: reflect.Value.Call(0xc42026d6e0, 0xc4202cad40, 0x13, 0xc4202c4720, 0x3, 0x3, 0x0, 0x0, 0x0)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /usr/local/go/src/reflect/value.go:302 +0xa4
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: net/rpc.(*service).call(0xc420362100, 0xc4203620c0, 0xc4203517f8, 0xc4202bb880, 0xc42034f500, 0x182db20, 0xc4203961c0, 0x16, 0x182db60, 0xc420349260, ...)
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /usr/local/go/src/net/rpc/server.go:387 +0x144
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: created by net/rpc.(*Server).ServeCodec
2017/06/12 16:44:41 [DEBUG] plugin: terraform-provider-ibmcloud_darwin_amd64: /usr/local/go/src/net/rpc/server.go:481 +0x404
2017/06/12 16:44:41 [DEBUG] root: eval: *terraform.EvalWriteState
2017/06/12 16:44:41 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/06/12 16:44:41 [DEBUG] root: eval: *terraform.EvalIf
2017/06/12 16:44:41 [DEBUG] root: eval: *terraform.EvalWriteState
2017/06/12 16:44:41 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/06/12 16:44:41 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/06/12 16:44:41 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
* ibmcloud_infra_vlan.dev_vlan_01: unexpected EOF
2017/06/12 16:44:41 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
* ibmcloud_infra_vlan.dev_vlan_01: unexpected EOF
2017/06/12 16:44:41 [TRACE] [walkApply] Exiting eval tree: ibmcloud_infra_vlan.dev_vlan_01
2017/06/12 16:44:41 [DEBUG] dag/walk: upstream errored, not walking "provider.ibmcloud (close)"
2017/06/12 16:44:41 [DEBUG] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
2017/06/12 16:44:41 [DEBUG] dag/walk: upstream errored, not walking "root"
2017/06/12 16:44:41 [TRACE] Preserving existing state lineage "91e8972c-40fa-4802-8117-e26fbd21cf8c"
2017/06/12 16:44:41 [TRACE] Preserving existing state lineage "91e8972c-40fa-4802-8117-e26fbd21cf8c"
2017/06/12 16:44:41 [DEBUG] plugin: /Users/mihasya/bin/terraform-provider-ibmcloud_darwin_amd64: plugin process exited
2017/06/12 16:44:41 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/12 16:44:41 [WARN] plugin: error closing client during Kill: connection is shut down
回答1:
Here are all the traps I fell into:
- Account Pre-requisites: This will only work if someone from SoftLayer has turned on automatic VLAN ordering on your account.
- Credentials: the "username" you are supposed to use is the "API Username" from your Profile. Latest builds from https://github.com/IBM-Bluemix/terraform/tree/v0.3-tf-v0.9.3 does not respect
~/.softlayer
, but I was able to pass the credentials using environment variablesSL_USERNAME
andSL_API_KEY
- Capitalization: I was capitalizing the datacenter name as in
FRA02
, which was causing a terraform crash. Switching it tofra02
made everything happy.
来源:https://stackoverflow.com/questions/44509756/how-do-i-create-a-softlayer-vlan-using-terraform