forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Vendor Rancher Go library. * Implement Rancher Provider. Starting implementation taken from https://github.com/platanus/terraform-provider-rancher Commits from jidonoso@gmail.com and raphael.pinson@camptocamp.com
- Loading branch information
1 parent
8a120d8
commit 26043a9
Showing
241 changed files
with
53,807 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,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/builtin/providers/rancher" | ||
"github.com/hashicorp/terraform/plugin" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: func() terraform.ResourceProvider { | ||
return rancher.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,76 @@ | ||
package rancher | ||
|
||
import ( | ||
"log" | ||
|
||
rancherClient "github.com/rancher/go-rancher/client" | ||
"github.com/raphink/go-rancher/catalog" | ||
) | ||
|
||
type Config struct { | ||
*rancherClient.RancherClient | ||
APIURL string | ||
AccessKey string | ||
SecretKey string | ||
} | ||
|
||
// Create creates a generic Rancher client | ||
func (c *Config) CreateClient() error { | ||
client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{ | ||
Url: c.APIURL, | ||
AccessKey: c.AccessKey, | ||
SecretKey: c.SecretKey, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[INFO] Rancher Client configured for url: %s", c.APIURL) | ||
|
||
c.RancherClient = client | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) EnvironmentClient(env string) (*rancherClient.RancherClient, error) { | ||
|
||
url := c.APIURL + "/projects/" + env + "/schemas" | ||
client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{ | ||
Url: url, | ||
AccessKey: c.AccessKey, | ||
SecretKey: c.SecretKey, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Printf("[INFO] Rancher Client configured for url: %s", url) | ||
|
||
return client, nil | ||
} | ||
|
||
func (c *Config) RegistryClient(id string) (*rancherClient.RancherClient, error) { | ||
reg, err := c.Registry.ById(id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return c.EnvironmentClient(reg.AccountId) | ||
} | ||
|
||
func (c *Config) CatalogClient() (*catalog.RancherClient, error) { | ||
|
||
url := c.APIURL + "-catalog/schemas" | ||
client, err := catalog.NewRancherClient(&catalog.ClientOpts{ | ||
Url: url, | ||
AccessKey: c.AccessKey, | ||
SecretKey: c.SecretKey, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Printf("[INFO] Rancher Catalog Client configured for url: %s", url) | ||
|
||
return client, nil | ||
} |
28 changes: 28 additions & 0 deletions
28
builtin/providers/rancher/import_rancher_environment_test.go
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,28 @@ | ||
package rancher | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccRancherEnvironment_importBasic(t *testing.T) { | ||
resourceName := "rancher_environment.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckRancherEnvironmentDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccRancherEnvironmentConfig, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
28 changes: 28 additions & 0 deletions
28
builtin/providers/rancher/import_rancher_registration_token_test.go
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,28 @@ | ||
package rancher | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccRancherRegistrationToken_importBasic(t *testing.T) { | ||
resourceName := "rancher_registration_token.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckRancherRegistrationTokenDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccRancherRegistrationTokenConfig, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/rancher/import_rancher_registry_credential_test.go
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,30 @@ | ||
package rancher | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccRancherRegistryCredential_importBasic(t *testing.T) { | ||
resourceName := "rancher_registry_credential.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckRancherRegistryCredentialDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccRancherRegistryCredentialConfig, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"secret_value"}, | ||
}, | ||
}, | ||
}) | ||
} |
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,28 @@ | ||
package rancher | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccRancherRegistry_importBasic(t *testing.T) { | ||
resourceName := "rancher_registry.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckRancherRegistryDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccRancherRegistryConfig, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
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,28 @@ | ||
package rancher | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccRancherStack_importBasic(t *testing.T) { | ||
resourceName := "rancher_stack.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckRancherStackDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccRancherStackConfig, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
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,66 @@ | ||
package rancher | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// Provider returns a terraform.ResourceProvider. | ||
func Provider() terraform.ResourceProvider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"api_url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("RANCHER_URL", nil), | ||
Description: descriptions["api_url"], | ||
}, | ||
"access_key": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("RANCHER_ACCESS_KEY", ""), | ||
Description: descriptions["access_key"], | ||
}, | ||
"secret_key": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("RANCHER_SECRET_KEY", ""), | ||
Description: descriptions["secret_key"], | ||
}, | ||
}, | ||
|
||
ResourcesMap: map[string]*schema.Resource{ | ||
"rancher_environment": resourceRancherEnvironment(), | ||
"rancher_registration_token": resourceRancherRegistrationToken(), | ||
"rancher_registry": resourceRancherRegistry(), | ||
"rancher_registry_credential": resourceRancherRegistryCredential(), | ||
"rancher_stack": resourceRancherStack(), | ||
}, | ||
|
||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
var descriptions map[string]string | ||
|
||
func init() { | ||
descriptions = map[string]string{ | ||
"access_key": "API Key used to authenticate with the rancher server", | ||
|
||
"secret_key": "API secret used to authenticate with the rancher server", | ||
|
||
"api_url": "The URL to the rancher API", | ||
} | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
config := &Config{ | ||
APIURL: d.Get("api_url").(string) + "/v1", | ||
AccessKey: d.Get("access_key").(string), | ||
SecretKey: d.Get("secret_key").(string), | ||
} | ||
|
||
err := config.CreateClient() | ||
|
||
return config, err | ||
} |
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,35 @@ | ||
package rancher | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
var testAccProviders map[string]terraform.ResourceProvider | ||
var testAccProvider *schema.Provider | ||
|
||
func init() { | ||
testAccProvider = Provider().(*schema.Provider) | ||
testAccProviders = map[string]terraform.ResourceProvider{ | ||
"rancher": testAccProvider, | ||
} | ||
} | ||
|
||
func TestProvider(t *testing.T) { | ||
if err := Provider().(*schema.Provider).InternalValidate(); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func TestProvider_impl(t *testing.T) { | ||
var _ terraform.ResourceProvider = Provider() | ||
} | ||
|
||
func testAccPreCheck(t *testing.T) { | ||
if v := os.Getenv("RANCHER_URL"); v == "" { | ||
t.Fatal("RANCHER_URL must be set for acceptance tests") | ||
} | ||
} |
Oops, something went wrong.