Skip to content

Commit 8073027

Browse files
committed
Add new rancher2_config_map_v2 resource and datasoruce. Go and docs files
1 parent af912c9 commit 8073027

12 files changed

Lines changed: 880 additions & 0 deletions

docs/data-sources/config_map_v2.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
page_title: "rancher2_config_map_v2 Datasource"
3+
---
4+
5+
# rancher2\_config\_map\_v2 Datasource
6+
7+
Use this data source to retrieve information about a Rancher2 configMap v2. ConfigMap v2 resource is available at Rancher v2.5.x and above.
8+
9+
## Example Usage
10+
11+
```hcl
12+
data "rancher2_config_map_v2" "foo" {
13+
cluster_id = <CLUSTER_ID>
14+
name = <CONFIG_MAP_V2_NAME>
15+
namespace = <CONFIG_MAP_V2_NAMESPACE>
16+
}
17+
```
18+
19+
## Argument Reference
20+
21+
The following arguments are supported:
22+
23+
* `cluster_id` - (Required) The cluster id of the configMap V2 (string)
24+
* `name` - (Required) The name of the configMap v2 (string)
25+
* `namespace` - (Optional) The namespaces of the configMap v2. Default: `default` (string)
26+
27+
28+
## Attributes Reference
29+
30+
The following attributes are exported:
31+
32+
* `id` - (Computed) The ID of the resource (string)
33+
* `resource_version` - (Computed) The k8s resource version (string)
34+
* `data` - (Computed) The data of the configMap v2 (map)
35+
* `immutable` - (Computed) If set to true, any configMap update will remove and recreate the configMap. This is a beta field enabled by k8s `ImmutableEphemeralVolumes` feature gate (bool)
36+
* `annotations` - (Computed) Annotations for the configMap v2 (map)
37+
* `labels` - (Computed) Labels for the configMap v2 (map)

docs/resources/config_map_v2.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
page_title: "Rancher2: rancher2_config_map_v2 Resource"
3+
---
4+
5+
# rancher2\_config\_map\_v2 Resource
6+
7+
Provides a Rancher ConfigMap v2 resource. This can be used to create k8s configMaps for Rancher v2 environments and retrieve their information. ConfigMap v2 resource is available at Rancher v2.5.x and above.
8+
9+
## Example Usage
10+
11+
```hcl
12+
# Create a new Rancher2 ConfigMap V2
13+
resource "rancher2_config_map_v2" "foo" {
14+
cluster_id = <CLUSTER_ID>
15+
name = "foo"
16+
data = {
17+
mydata1 = "<data1>"
18+
mydata2 = "<data2>"
19+
mydata3 = "<data3>"
20+
}
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `cluster_id` - (Required/ForceNew) The cluster id of the configMap V2 (string)
29+
* `data` - (Required) The data of the configMap v2 (map)
30+
* `name` - (Required/ForceNew) The name of the configMap v2 (string)
31+
* `namespace` - (Optional/ForceNew) The namespaces of the configMap v2. Default: `default` (string)
32+
* `immutable` - (Optional) If set to true, any configMap update will remove and recreate the configMap. This is a beta field enabled by k8s `ImmutableEphemeralVolumes` feature gate. Default: `false` (bool)
33+
* `annotations` - (Optional/Computed) Annotations for the configMap v2 (map)
34+
* `labels` - (Optional/Computed) Labels for the configMap v2 (map)
35+
36+
## Attributes Reference
37+
38+
The following attributes are exported:
39+
40+
* `id` - (Computed) The ID of the resource (string)
41+
* `resource_version` - (Computed) The k8s resource version (string)
42+
43+
## Timeouts
44+
45+
`rancher2_configMap` provides the following
46+
[Timeouts](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) configuration options:
47+
48+
- `create` - (Default `10 minutes`) Used for creating v2 configMaps.
49+
- `update` - (Default `10 minutes`) Used for v2 configMap modifications.
50+
- `delete` - (Default `10 minutes`) Used for deleting v2 configMaps.
51+
52+
## Import
53+
54+
V2 configMaps can be imported using the Rancher cluster ID, ConfigMap V2 namespace and name.
55+
56+
```
57+
$ terraform import rancher2_config_map_v2.foo &lt;CLUSTER_ID&gt;.&lt;SECRET_V2_NAMESPACE&gt;/&lt;SECRET_V2_NAME&gt;
58+
```

rancher2/0_provider_upgrade_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ provider "rancher2" {
222222
` + testAccRancher2ClusterAlertRule + `
223223
` + testAccRancher2ClusterDriver + `
224224
` + testAccRancher2ClusterLoggingSyslog + `
225+
` + testAccRancher2ConfigMapV2 + `
225226
` + testAccRancher2User + `
226227
` + testAccRancher2ClusterRoleTemplateBinding + `
227228
` + testAccRancher2ClusterTemplateConfig + `
@@ -283,6 +284,7 @@ provider "rancher2" {
283284
` + testAccRancher2ClusterDriver + `
284285
` + testAccRancher2ClusterLoggingSyslog + `
285286
` + testAccRancher2ClusterV2 + `
287+
` + testAccRancher2ConfigMapV2 + `
286288
` + testAccRancher2User + `
287289
` + testAccRancher2ClusterRoleTemplateBinding + `
288290
` + testAccRancher2ClusterTemplateConfig + `
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package rancher2
2+
3+
import (
4+
"log"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
)
8+
9+
func dataSourceRancher2ConfigMapV2() *schema.Resource {
10+
return &schema.Resource{
11+
Read: dataSourceRancher2ConfigMapV2Read,
12+
13+
Schema: map[string]*schema.Schema{
14+
"cluster_id": {
15+
Type: schema.TypeString,
16+
Required: true,
17+
},
18+
"name": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
},
22+
"namespace": {
23+
Type: schema.TypeString,
24+
Optional: true,
25+
Default: "default",
26+
},
27+
"immutable": {
28+
Type: schema.TypeBool,
29+
Computed: true,
30+
},
31+
"data": {
32+
Type: schema.TypeMap,
33+
Computed: true,
34+
},
35+
"resource_version": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
},
39+
"annotations": {
40+
Type: schema.TypeMap,
41+
Computed: true,
42+
},
43+
"labels": {
44+
Type: schema.TypeMap,
45+
Computed: true,
46+
},
47+
},
48+
}
49+
}
50+
51+
func dataSourceRancher2ConfigMapV2Read(d *schema.ResourceData, meta interface{}) error {
52+
clusterID := d.Get("cluster_id").(string)
53+
name := d.Get("name").(string)
54+
namespace := d.Get("namespace").(string)
55+
rancherID := namespace + "/" + name
56+
d.SetId(clusterID + configMapV2ClusterIDsep + rancherID)
57+
58+
configMap, err := getConfigMapV2ByID(meta.(*Config), clusterID, rancherID)
59+
if err != nil {
60+
if IsNotFound(err) || IsForbidden(err) {
61+
log.Printf("[INFO] ConfigMap V2 %s not found at cluster %s", rancherID, clusterID)
62+
d.SetId("")
63+
return nil
64+
}
65+
return err
66+
}
67+
68+
return flattenConfigMapV2(d, configMap)
69+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package rancher2
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccRancher2ConfigMapV2DataSource_Cluster(t *testing.T) {
10+
testAccCheckRancher2ConfigMapV2ClusterDataSourceConfig := testAccRancher2ConfigMapV2Config + `
11+
data "` + testAccRancher2ConfigMapV2Type + `" "foo" {
12+
cluster_id = rancher2_cluster_sync.testacc.cluster_id
13+
name = rancher2_config_map_v2.foo.name
14+
namespace = rancher2_config_map_v2.foo.namespace
15+
}
16+
`
17+
name := "data." + testAccRancher2ConfigMapV2Type + ".foo"
18+
resource.Test(t, resource.TestCase{
19+
PreCheck: func() { testAccPreCheck(t) },
20+
Providers: testAccProviders,
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testAccCheckRancher2ConfigMapV2ClusterDataSourceConfig,
24+
Check: resource.ComposeTestCheckFunc(
25+
resource.TestCheckResourceAttr(name, "name", "foo"),
26+
resource.TestCheckResourceAttr(name, "namespace", "default"),
27+
resource.TestCheckResourceAttr(name, "data.param1", "true"),
28+
resource.TestCheckResourceAttr(name, "data.param2", "40000"),
29+
),
30+
},
31+
},
32+
})
33+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package rancher2
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
)
6+
7+
func resourceRancher2ConfigMapV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
8+
clusterID, name := splitID(d.Id())
9+
d.Set("cluster_id", clusterID)
10+
d.Set("name", name)
11+
12+
err := resourceRancher2ConfigMapV2Read(d, meta)
13+
if err != nil || d.Id() == "" {
14+
return []*schema.ResourceData{}, err
15+
}
16+
17+
return []*schema.ResourceData{d}, nil
18+
}

rancher2/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func Provider() terraform.ResourceProvider {
132132
"rancher2_cluster_role_template_binding": resourceRancher2ClusterRoleTemplateBinding(),
133133
"rancher2_cluster_sync": resourceRancher2ClusterSync(),
134134
"rancher2_cluster_template": resourceRancher2ClusterTemplate(),
135+
"rancher2_config_map_v2": resourceRancher2ConfigMapV2(),
135136
"rancher2_etcd_backup": resourceRancher2EtcdBackup(),
136137
"rancher2_feature": resourceRancher2Feature(),
137138
"rancher2_global_dns": resourceRancher2GlobalDNS(),
@@ -176,6 +177,7 @@ func Provider() terraform.ResourceProvider {
176177
"rancher2_cluster_role_template_binding": dataSourceRancher2ClusterRoleTemplateBinding(),
177178
"rancher2_cluster_scan": dataSourceRancher2ClusterScan(),
178179
"rancher2_cluster_template": dataSourceRancher2ClusterTemplate(),
180+
"rancher2_config_map_v2": dataSourceRancher2ConfigMapV2(),
179181
"rancher2_etcd_backup": dataSourceRancher2EtcdBackup(),
180182
"rancher2_global_dns_provider": dataSourceRancher2GlobalDNSProvider(),
181183
"rancher2_global_role": dataSourceRancher2GlobalRole(),

0 commit comments

Comments
 (0)