Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data source for K8s storage class #33

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions kubernetes/data_source_kubernetes_storage_class.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kubernetes

import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceKubernetesStorageClass() *schema.Resource {
return &schema.Resource{
Read: dataSourceKubernetesStorageClassRead,
Schema: map[string]*schema.Schema{
"metadata": metadataSchema("storage class", false),
"parameters": {
Type: schema.TypeMap,
Description: "The parameters for the provisioner that should create volumes of this storage class",
Computed: true,
},
"storage_provisioner": {
Type: schema.TypeString,
Description: "Indicates the type of the provisioner",
Computed: true,
},
},
}
}

func dataSourceKubernetesStorageClassRead(d *schema.ResourceData, meta interface{}) error {
name := d.Get("metadata.0.name").(string)
d.SetId(name)
return resourceKubernetesStorageClassRead(d, meta)
}
49 changes: 49 additions & 0 deletions kubernetes/data_source_kubernetes_storage_class_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package kubernetes

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccKubernetesDataSourceStorageClass_basic(t *testing.T) {
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccKubernetesDataSourceStorageClassConfig_basic(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.name", name),
resource.TestCheckResourceAttrSet("data.kubernetes_storage_class.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("data.kubernetes_storage_class.test", "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet("data.kubernetes_storage_class.test", "metadata.0.self_link"),
resource.TestCheckResourceAttrSet("data.kubernetes_storage_class.test", "metadata.0.uid"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.annotations.%", "2"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.annotations.TestAnnotationOne", "one"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.annotations.TestAnnotationTwo", "two"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.labels.TestLabelOne", "one"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.labels.TestLabelTwo", "two"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "metadata.0.labels.TestLabelThree", "three"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "storage_provisioner", "kubernetes.io/gce-pd"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "parameters.%", "1"),
resource.TestCheckResourceAttr("data.kubernetes_storage_class.test", "parameters.type", "pd-ssd"),
),
},
},
})
}

func testAccKubernetesDataSourceStorageClassConfig_basic(name string) string {
return testAccKubernetesStorageClassConfig_basic(name) + `
data "kubernetes_storage_class" "test" {
metadata {
name = "${kubernetes_storage_class.test.metadata.0.name}"
}
}
`
}
3 changes: 2 additions & 1 deletion kubernetes/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func Provider() terraform.ResourceProvider {
},

DataSourcesMap: map[string]*schema.Resource{
"kubernetes_service": dataSourceKubernetesService(),
"kubernetes_service": dataSourceKubernetesService(),
"kubernetes_storage_class": dataSourceKubernetesStorageClass(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
55 changes: 55 additions & 0 deletions website/docs/d/storage_class.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
layout: "kubernetes"
page_title: "Kubernetes: kubernetes_storage_class"
sidebar_current: "docs-kubernetes-data-source-storage-class"
description: |-
Storage class is the foundation of dynamic provisioning, allowing cluster administrators to define abstractions for the underlying storage platform.
---

# kubernetes_storage_class

Storage class is the foundation of dynamic provisioning, allowing cluster administrators to define abstractions for the underlying storage platform.

Read more at http://blog.kubernetes.io/2017/03/dynamic-provisioning-and-storage-classes-kubernetes.html

## Example Usage

```
data "kubernetes_storage_class" "example" {
metadata {
name = "terraform-example"
}
}
```

## Argument Reference

The following arguments are supported:

* `metadata` - (Required) Standard storage class's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata


## Nested Blocks

### `metadata`

#### Arguments

* `name` - (Required) Name of the storage class, must be unique. More info: http://kubernetes.io/docs/user-guide/identifiers#names

#### Attributes


* `generation` - A sequence number representing a specific generation of the desired state.
* `resource_version` - An opaque value that represents the internal version of this storage class that can be used by clients to determine when storage class has changed. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#concurrency-control-and-consistency
* `self_link` - A URL representing this storage class.
* `uid` - The unique in time and space value for this storage class. More info: http://kubernetes.io/docs/user-guide/identifiers#uids


## Argument Reference

The following attributes are exported:

* `parameters` - The parameters for the provisioner that creates volume of this storage class.
Read more about [available parameters](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#parameters).
* `storage_provisioner` - Indicates the type of the provisioner this storage class represents
3 changes: 3 additions & 0 deletions website/kubernetes.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<li<%= sidebar_current("docs-kubernetes-data-source-service") %>>
<a href="/docs/providers/kubernetes/d/service.html">kubernetes_service</a>
</li>
<li<%= sidebar_current("docs-kubernetes-data-source-storage-class") %>>
<a href="/docs/providers/kubernetes/d/storage_class.html">kubernetes_storage_class</a>
</li>
</ul>
</li>

Expand Down