Skip to content

Commit 1b39891

Browse files
authored
Merge pull request #614 from rawmind0/secretv2
New rancher2_secret_v2 resource and datausource
2 parents d11f627 + 605c100 commit 1b39891

17 files changed

Lines changed: 1030 additions & 96 deletions

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 1.13.0 (Unreleased)
1+
## 1.13.0 (March 31, 2021)
22

33
FEATURES:
44

@@ -15,6 +15,8 @@ FEATURES:
1515
* **New Argument:** `rancher2_cluster_sync.wait_catalogs` - (Optional) Wait until all catalogs are downloaded and active. Default: `false` (bool)
1616
* **New Attribute:** `rancher2_cluster.eks_config_v2.node_groups.version` - (Computed) The EKS node group version (string)
1717
* **New Attribute:** `rancher2_app_v2.system_default_registry` - (Computed) The system default registry of the app (string)
18+
* **New Data Source:** `rancher2_secret_v2` - Provides a Rancher V2 Secret V2 data source
19+
* **New Resource:** `rancher2_secret_v2` - Provides a Rancher V2 Secret V2 resource
1820

1921
ENHANCEMENTS:
2022

GNUmakefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ build-rancher: validate-rancher
1616

1717
validate-rancher: validate test
1818

19-
validate: fmtcheck vet lint
19+
validate: fmtcheck lint vet
2020

2121
package-rancher:
2222
@sh -c "'$(CURDIR)/scripts/gopackage.sh'"
@@ -38,11 +38,13 @@ upgrade-rancher:
3838

3939
vet:
4040
@echo "==> Checking that code complies with go vet requirements..."
41-
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -gt 0 ]; then \
41+
@go vet $$(go list ./... | grep -v vendor/); if [ $$? -gt 0 ]; then \
4242
echo ""; \
43-
echo "Vet found suspicious constructs. Please check the reported constructs"; \
44-
echo "and fix them if necessary before submitting the code for review."; \
45-
exit 1; \
43+
echo "WARNING!! Expected vet reported construct:"; \
44+
echo "rancher2/schema_secret_v2.go:20:2: struct field Type repeats json tag \"type\" also at ../../../../github.com/rancher/norman@v0.0.0-20210225010917-c7fd1e24145b/types/types.go:66"; \
45+
echo "";\
46+
echo "If vet reported more suspicious constructs, please check and"; \
47+
echo "fix them if necessary, before submitting the code for review."; \
4648
fi
4749

4850
lint:

docs/data-sources/secret_v2.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
page_title: "rancher2_secret_v2 Datasource"
3+
---
4+
5+
# rancher2\_secret\_v2 Datasource
6+
7+
Use this data source to retrieve information about a Rancher2 secret v2.
8+
9+
## Example Usage
10+
11+
```hcl
12+
data "rancher2_secret_v2" "foo" {
13+
cluster_id = <CLUSTER_ID>
14+
name = <SECRET_V2_NAME>
15+
namespace = <SECRET_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 secret V2 (string)
24+
* `name` - (Required) The name of the secret v2 (string)
25+
* `namespace` - (Optional) The namespaces of the secret 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/Sensitive) The data of the secret v2 (map)
35+
* `type` - (Computed) The type of the k8s secret, used to facilitate programmatic handling of secret data, [More info](https://github.com/kubernetes/api/blob/release-1.20/core/v1/types.go#L5772) about k8s secret types and expected format (string)
36+
* `immutable` - (Computed) If set to true, any secret update will remove and recreate the secret. This is a beta field enabled by k8s `ImmutableEphemeralVolumes` feature gate (bool)
37+
* `annotations` - (Computed) Annotations for the secret v2 (map)
38+
* `labels` - (Computed) Labels for the secret v2 (map)

docs/resources/secret_v2.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
page_title: "Rancher2: rancher2_secret_v2 Resource"
3+
---
4+
5+
# rancher2\_secret\_v2 Resource
6+
7+
Provides a Rancher Secret v2 resource. This can be used to create k8s secrets for Rancher v2 environments and retrieve their information. Secret v2 resource is available at Rancher v2.5.x and above.
8+
9+
## Example Usage
10+
11+
```hcl
12+
# Create a new Rancher2 Secret V2
13+
resource "rancher2_secret_v2" "foo" {
14+
cluster_id = <CLUSTER_ID>
15+
name = "foo"
16+
data = {
17+
mydata1 = "<data1>"
18+
mydata2 = "<data2>"
19+
mydata3 = "<data3>"
20+
}
21+
}
22+
# Create a new Rancher2 Secret V2 basic-auth
23+
resource "rancher2_secret_v2" "foo" {
24+
cluster_id = <CLUSTER_ID>
25+
name = "foo"
26+
namespace = "<mynamespace>"
27+
type = "kubernetes.io/basic-auth"
28+
data = {
29+
password = "<mysecret>"
30+
username = "<myuser>"
31+
}
32+
}
33+
```
34+
35+
## Argument Reference
36+
37+
The following arguments are supported:
38+
39+
* `cluster_id` - (Required/ForceNew) The cluster id of the secret V2 (string)
40+
* `data` - (Required/Sensitive) The data of the secret v2 (map)
41+
* `name` - (Required) The name of the secret v2 (string)
42+
* `namespace` - (Optional/ForceNew) The namespaces of the secret v2. Default: `default` (string)
43+
* `type` - (Optional) The type of the k8s secret, used to facilitate programmatic handling of secret data, [More info](https://github.com/kubernetes/api/blob/release-1.20/core/v1/types.go#L5772) about k8s secret types and expected format. Default: `Opaque` (string)
44+
* `immutable` - (Optional) If set to true, any secret update will remove and recreate the secret. This is a beta field enabled by k8s `ImmutableEphemeralVolumes` feature gate. Default: `false` (bool)
45+
* `annotations` - (Optional/Computed) Annotations for the secret v2 (map)
46+
* `labels` - (Optional/Computed) Labels for the secret v2 (map)
47+
48+
## Attributes Reference
49+
50+
The following attributes are exported:
51+
52+
* `id` - (Computed) The ID of the resource (string)
53+
* `resource_version` - (Computed) The k8s resource version (string)
54+
55+
## Timeouts
56+
57+
`rancher2_secret` provides the following
58+
[Timeouts](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) configuration options:
59+
60+
- `create` - (Default `10 minutes`) Used for creating v2 secrets.
61+
- `update` - (Default `10 minutes`) Used for v2 secret modifications.
62+
- `delete` - (Default `10 minutes`) Used for deleting v2 secrets.
63+
64+
## Import
65+
66+
V2 secrets can be imported using the Rancher cluster ID, Secret V2 namespace and name.
67+
68+
```
69+
$ terraform import rancher2_secret_v2.foo &lt;CLUSTER_ID&gt;.&lt;SECRET_V2_NAMESPACE&gt;/&lt;SECRET_V2_NAME&gt;
70+
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
1414
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
1515
gopkg.in/yaml.v2 v2.3.0
16+
k8s.io/api v0.20.0
1617
k8s.io/apimachinery v0.20.0
1718
k8s.io/apiserver v0.20.0
1819
)

rancher2/0_provider_upgrade_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ provider "rancher2" {
226226
` + testAccRancher2Registry + `
227227
` + testAccRancher2RoleTemplateConfig + `
228228
` + testAccRancher2Secret + `
229+
` + testAccRancher2SecretV2 + `
229230
` + testAccRancher2SecretNs + `
230231
` + testAccRancher2SettingConfig + `
231232
` + testAccRancher2Token + `

0 commit comments

Comments
 (0)