Created
March 4, 2016 14:33
-
-
Save fatmcgav/fb555eb05d619b8996c3 to your computer and use it in GitHub Desktop.
Terraform provisioner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
## Testing Terraform CLC support | |
# | |
# Setup CLC Terraform provider | |
provider "clc" { | |
username = "xxx" | |
password = "xxx" | |
account = "IAST" | |
} | |
# Create the top-level CLC group | |
resource "clc_group" "test_group" { | |
location_id = "GB3" | |
name = "test group" | |
parent = "GB3 Hardware" | |
} | |
# Create a test server | |
resource "clc_server" "test01" { | |
name_template = "TST" | |
description = "test server" | |
source_server_id = "CENTOS-7-64-TEMPLATE" | |
type = "standard" | |
group_id = "${clc_group.test_group.id}" | |
cpu = 1 | |
memory_mb = 1024 | |
power_state = "started" | |
password = "Password123" | |
network_id = "${var.network_id}" | |
provisioner "clc_exec" { | |
package = "ACT Bootstrap" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/hashicorp/terraform/plugin" | |
"github.com/hashicorp/terraform/terraform" | |
) | |
func ResourceProvisionerBuilder() terraform.ResourceProvisioner { | |
return &ResourceProvisioner{} | |
} | |
func main() { | |
serveOpts := &plugin.ServeOpts{ | |
ProvisionerFunc: ResourceProvisionerBuilder, | |
} | |
plugin.Serve(serveOpts) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/hashicorp/terraform/helper/config" | |
"github.com/hashicorp/terraform/terraform" | |
"github.com/mitchellh/mapstructure" | |
) | |
type Provisioner struct { | |
} | |
type ResourceProvisioner struct { | |
} | |
func (r *ResourceProvisioner) Apply( | |
o terraform.UIOutput, | |
s *terraform.InstanceState, | |
c *terraform.ResourceConfig) error { | |
log.Printf("Got to Apply for CLC_Blueprint ResourceProvisioner") | |
o.Output("Got to Apply for CLC_Blueprint ResourceProvisioner") | |
// Decode the raw config for this provisioner | |
p, err := r.decodeConfig(c) | |
if err != nil { | |
return err | |
} | |
fmt.Printf("%+v\n", p) | |
return nil | |
} | |
func (r *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string, es []error) { | |
v := &config.Validator{ | |
Required: []string{ | |
"source", | |
"destination", | |
}, | |
} | |
return v.Validate(c) | |
} | |
func (r *ResourceProvisioner) decodeConfig(c *terraform.ResourceConfig) (*Provisioner, error) { | |
p := new(Provisioner) | |
decConf := &mapstructure.DecoderConfig{ | |
ErrorUnused: true, | |
WeaklyTypedInput: true, | |
Result: p, | |
} | |
dec, err := mapstructure.NewDecoder(decConf) | |
if err != nil { | |
return nil, err | |
} | |
m := make(map[string]interface{}) | |
for k, v := range c.Raw { | |
m[k] = v | |
} | |
for k, v := range c.Config { | |
m[k] = v | |
} | |
if err := dec.Decode(m); err != nil { | |
return nil, err | |
} | |
return p, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2016/03/04 14:30:56 [INFO] Terraform version: 0.6.12 | |
2016/03/04 14:30:56 [DEBUG] Detected home directory from env var: /Users/gavinw | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: atlas = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-atlas | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: aws = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-aws | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: azure = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-azure | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: azurerm = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-azurerm | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: chef = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-chef | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: cloudflare = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-cloudflare | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: cloudstack = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-cloudstack | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: consul = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-consul | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: datadog = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-datadog | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: digitalocean = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-digitalocean | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: dme = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-dme | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: dnsimple = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-dnsimple | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: docker = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-docker | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: dyn = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-dyn | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: google = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-google | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: heroku = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-heroku | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: mailgun = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-mailgun | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: mysql = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-mysql | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: null = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-null | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: openstack = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-openstack | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: packet = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-packet | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: postgresql = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-postgresql | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: powerdns = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-powerdns | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: rundeck = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-rundeck | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: statuscake = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-statuscake | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: template = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-template | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: terraform = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-terraform | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: tls = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-tls | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: vcd = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-vcd | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: vsphere = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-vsphere | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: chef = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-chef | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: file = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-file | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: local-exec = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-local-exec | |
2016/03/04 14:30:56 [DEBUG] Discovered plugin: remote-exec = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-remote-exec | |
2016/03/04 14:30:56 [DEBUG] Detected home directory from env var: /Users/gavinw | |
2016/03/04 14:30:56 [DEBUG] Attempting to open CLI config file: /Users/gavinw/.terraformrc | |
2016/03/04 14:30:56 [DEBUG] Detected home directory from env var: /Users/gavinw | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.ConfigTransformer: | |
clc_group.test_group | |
clc_server.test01 | |
clc_group.test_group | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.OrphanTransformer: | |
clc_group.test_group | |
clc_server.test01 | |
clc_group.test_group | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.AddOutputOrphanTransformer: | |
clc_group.test_group | |
clc_server.test01 | |
clc_group.test_group | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.MissingProviderTransformer: | |
clc_group.test_group | |
clc_server.test01 | |
clc_group.test_group | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.ProviderTransformer: | |
clc_group.test_group | |
provider.clc | |
clc_server.test01 | |
clc_group.test_group | |
provider.clc | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.DisableProviderTransformer: | |
clc_group.test_group | |
provider.clc | |
clc_server.test01 | |
clc_group.test_group | |
provider.clc | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [TRACE] Graph after step *terraform.MissingProvisionerTransformer: | |
clc_group.test_group | |
provider.clc | |
clc_server.test01 | |
clc_group.test_group | |
provider.clc | |
var.network_id | |
provider.clc | |
var.network_id | |
2016/03/04 14:30:56 [DEBUG] waiting for all plugin processes to complete... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TF_LOG=TRACE TF_LOG_PATH=terraform.log DEBUG=1 terraform plan | |
Error configuring: 1 error(s) occurred: | |
* clc_server.test01: provisioner clc_exec couldn't be found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Terraform RC File | |
providers { | |
clc = "$GOPATH/bin/terraform-provider-clc.networkid" | |
# clc = "$GOPATH/bin/terraform-provider-clc.darwin-amd64" | |
clc_exec = "$GOPATH/bin/terraform-provisioner-clc_exec" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment