-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
637 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.terraform/ | ||
terraform.* | ||
terraform-provider-cloudamqp | ||
.idea/ | ||
*.iml | ||
vendor/ | ||
crash.log | ||
graph.png |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/scalablespace/terraform-provider-scalablespace | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/hashicorp/terraform v0.12.9 | ||
github.com/scalablespace/goss v0.0.1 | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/plugin" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: func() terraform.ResourceProvider { | ||
return Provider() | ||
}, | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
provider "scalablespace" { | ||
apikey = "24870c2a-f8b2-4240-a41b-db98e2d76417" | ||
} | ||
|
||
resource "scalablespace_instance" "redis"{ | ||
name = "myredis" | ||
plan = "Free" | ||
dc = "do-fra-1" | ||
} | ||
|
||
output "myredis" { | ||
value = "${scalablespace_instance.redis.port}" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/scalablespace/goss" | ||
) | ||
|
||
func Provider() *schema.Provider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"apikey": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("SCALABLESPACE_APIKEY", nil), | ||
Description: "Key used to authentication to the CloudAMQP Customer API", | ||
}, | ||
"baseurl": { | ||
Type: schema.TypeString, | ||
Default: "https://api.scalablespace.net", | ||
Optional: true, | ||
Description: "Base URL to CloudAMQP Customer website", | ||
}, | ||
}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"scalablespace_instance": resourceInstance(), | ||
}, | ||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
return goss.New(d.Get("baseurl").(string), d.Get("apikey").(string)), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/scalablespace/goss" | ||
) | ||
|
||
func resourceInstance() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceCreate, | ||
Read: resourceRead, | ||
Update: func(data *schema.ResourceData, i interface{}) error { | ||
return nil | ||
}, | ||
Delete: resourceDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the instance", | ||
}, | ||
"plan": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the plan, valid options are: lemur, tiger, bunny, rabbit, panda, ape, hippo, lion", | ||
}, | ||
"dc": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the region you want to create your instance in", | ||
}, | ||
"port": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Sensitive: true, | ||
Description: "API key for the CloudAMQP instance", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceCreate(d *schema.ResourceData, meta interface{}) error { | ||
api := meta.(*goss.API) | ||
keys := []string{"name", "plan", "dc"} | ||
params := make(map[string]interface{}) | ||
for _, k := range keys { | ||
if v := d.Get(k); v != nil { | ||
params[k] = v | ||
} | ||
} | ||
data, err := api.CreateInstance(params) | ||
if err != nil { | ||
return err | ||
} | ||
d.SetId(data["id"].(string)) | ||
for k, v := range data { | ||
d.Set(k, v) | ||
} | ||
return nil | ||
|
||
} | ||
|
||
func resourceRead(d *schema.ResourceData, meta interface{}) error { | ||
api := meta.(*goss.API) | ||
data, err := api.ReadInstance(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
for k, v := range data { | ||
d.Set(k, v) | ||
} | ||
return nil | ||
} | ||
|
||
func resourceDelete(d *schema.ResourceData, meta interface{}) error { | ||
api := meta.(*goss.API) | ||
return api.DeleteInstance(d.Id()) | ||
} |