forked from rancher/norman
-
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.
Merge pull request rancher#53 from rawmind0/clusterdriver_ds
Cluster and node driver data sources
- Loading branch information
Showing
9 changed files
with
355 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
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,93 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceRancher2ClusterDriver() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceRancher2ClusterDriverRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"active": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"builtin": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"actual_url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"checksum": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ui_url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"whitelist_domains": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"annotations": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
"labels": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceRancher2ClusterDriverRead(d *schema.ResourceData, meta interface{}) error { | ||
client, err := meta.(*Config).ManagementClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
name := d.Get("name").(string) | ||
url := d.Get("url").(string) | ||
|
||
filters := map[string]interface{}{ | ||
"name": name, | ||
} | ||
if len(url) > 0 { | ||
filters["url"] = url | ||
} | ||
listOpts := NewListOpts(filters) | ||
|
||
clusterDrivers, err := client.KontainerDriver.List(listOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
count := len(clusterDrivers.Data) | ||
if count <= 0 { | ||
return fmt.Errorf("[ERROR] cluster driver with name \"%s\" not found", name) | ||
} | ||
if count > 1 { | ||
return fmt.Errorf("[ERROR] found %d cluster driver with name \"%s\"", count, name) | ||
} | ||
|
||
return flattenClusterDriver(d, &clusterDrivers.Data[0]) | ||
} |
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,40 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
const ( | ||
testAccRancher2ClusterDriverDataSourceType = "rancher2_cluster_driver" | ||
) | ||
|
||
var ( | ||
testAccCheckRancher2ClusterDriverDataSourceConfig string | ||
) | ||
|
||
func init() { | ||
testAccCheckRancher2ClusterDriverDataSourceConfig = ` | ||
data "` + testAccRancher2ClusterDriverDataSourceType + `" "foo" { | ||
name = "amazonElasticContainerService" | ||
} | ||
` | ||
} | ||
|
||
func TestAccRancher2ClusterDriverDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckRancher2ClusterDriverDataSourceConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data."+testAccRancher2ClusterDriverDataSourceType+".foo", "name", "amazonElasticContainerService"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2ClusterDriverDataSourceType+".foo", "id", "amazonelasticcontainerservice"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2ClusterDriverDataSourceType+".foo", "labels.cattle.io/creator", "norman"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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,97 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceRancher2NodeDriver() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceRancher2NodeDriverRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"active": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"builtin": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"checksum": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"external_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ui_url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"whitelist_domains": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"annotations": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
"labels": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceRancher2NodeDriverRead(d *schema.ResourceData, meta interface{}) error { | ||
client, err := meta.(*Config).ManagementClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
name := d.Get("name").(string) | ||
url := d.Get("url").(string) | ||
|
||
filters := map[string]interface{}{ | ||
"name": name, | ||
} | ||
if len(url) > 0 { | ||
filters["url"] = url | ||
} | ||
listOpts := NewListOpts(filters) | ||
|
||
nodeDrivers, err := client.NodeDriver.List(listOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
count := len(nodeDrivers.Data) | ||
if count <= 0 { | ||
return fmt.Errorf("[ERROR] node driver with name \"%s\" not found", name) | ||
} | ||
if count > 1 { | ||
return fmt.Errorf("[ERROR] found %d node driver with name \"%s\"", count, name) | ||
} | ||
|
||
return flattenNodeDriver(d, &nodeDrivers.Data[0]) | ||
} |
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,40 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
const ( | ||
testAccRancher2NodeDriverDataSourceType = "rancher2_node_driver" | ||
) | ||
|
||
var ( | ||
testAccCheckRancher2NodeDriverDataSourceConfig string | ||
) | ||
|
||
func init() { | ||
testAccCheckRancher2NodeDriverDataSourceConfig = ` | ||
data "` + testAccRancher2NodeDriverDataSourceType + `" "foo" { | ||
name = "amazonec2" | ||
} | ||
` | ||
} | ||
|
||
func TestAccRancher2NodeDriverDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckRancher2NodeDriverDataSourceConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data."+testAccRancher2NodeDriverDataSourceType+".foo", "name", "amazonec2"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2NodeDriverDataSourceType+".foo", "id", "amazonec2"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2NodeDriverDataSourceType+".foo", "labels.cattle.io/creator", "norman"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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
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,37 @@ | ||
--- | ||
layout: "rancher2" | ||
page_title: "Rancher2: rancher2_cluster_driver" | ||
sidebar_current: "docs-rancher2-resource-cluster_driver" | ||
description: |- | ||
Get information on a Rancher v2 Cluster Driver resource. | ||
--- | ||
|
||
# rancher2\_cluster\_driver | ||
|
||
Use this data source to retrieve information about a Rancher v2 Cluster Driver resource. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "rancher2_cluster_driver" "foo" { | ||
name = "foo" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Name of the cluster driver (string) | ||
* `url` - (Optional/Computed) The URL to download the machine driver binary for 64-bit Linux (string) | ||
|
||
## Attributes Reference | ||
|
||
* `id` - (Computed) The ID of the resource (string) | ||
* `active` - (Computed) Specify if the cluster driver state (bool) | ||
* `builtin` - (Computed) Specify wheter the cluster driver is an internal cluster driver or not (bool) | ||
* `actual_url` - (Computed) Actual url of the cluster driver (string) | ||
* `checksum` - (Computed) Verify that the downloaded driver matches the expected checksum (string) | ||
* `ui_url` - (Computed) The URL to load for customized Add Clusters screen for this driver (string) | ||
* `whitelist_domains` - (Computed) Domains to whitelist for the ui (list) | ||
* `annotations` - (Computed) Annotations of the resource (map) | ||
* `labels` - (Computed) Labels of the resource (map) | ||
|
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,38 @@ | ||
--- | ||
layout: "rancher2" | ||
page_title: "Rancher2: rancher2_node_driver" | ||
sidebar_current: "docs-rancher2-resource-node_driver" | ||
description: |- | ||
Get information on a Rancher v2 Node Driver resource. | ||
--- | ||
|
||
# rancher2\_node\_driver | ||
|
||
Use this data source to retrieve information about a Rancher v2 Node Driver resource. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "rancher2_node_driver" "foo" { | ||
name = "foo" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Name of the node driver (string) | ||
* `url` - (Optional/Computed) The URL to download the machine driver binary for 64-bit Linux (string) | ||
|
||
## Attributes Reference | ||
|
||
* `id` - (Computed) The ID of the resource (string) | ||
* `active` - (Computed) Specify if the node driver state (bool) | ||
* `builtin` - (Computed) Specify wheter the node driver is an internal cluster driver or not (bool) | ||
* `checksum` - (Computed) Verify that the downloaded driver matches the expected checksum (string) | ||
* `description` - (Computed) Description of the node driver (string) | ||
* `external_id` - (Computed) External ID (string) | ||
* `ui_url` - (Computed) The URL to load for customized Add Node screen for this driver (string) | ||
* `whitelist_domains` - (Computed) Domains to whitelist for the ui (list) | ||
* `annotations` - (Computed) Annotations of the resource (map) | ||
* `labels` - (Computed) Labels of the resource (map) | ||
|
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