Skip to content

Commit

Permalink
Merge pull request #614 from rawmind0/secretv2
Browse files Browse the repository at this point in the history
New rancher2_secret_v2 resource and datausource
  • Loading branch information
rawmind0 authored Mar 31, 2021
2 parents d11f627 + 605c100 commit 1b39891
Show file tree
Hide file tree
Showing 17 changed files with 1,030 additions and 96 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.13.0 (Unreleased)
## 1.13.0 (March 31, 2021)

FEATURES:

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

ENHANCEMENTS:

Expand Down
12 changes: 7 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build-rancher: validate-rancher

validate-rancher: validate test

validate: fmtcheck vet lint
validate: fmtcheck lint vet

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

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

lint:
Expand Down
38 changes: 38 additions & 0 deletions docs/data-sources/secret_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
page_title: "rancher2_secret_v2 Datasource"
---

# rancher2\_secret\_v2 Datasource

Use this data source to retrieve information about a Rancher2 secret v2.

## Example Usage

```hcl
data "rancher2_secret_v2" "foo" {
cluster_id = <CLUSTER_ID>
name = <SECRET_V2_NAME>
namespace = <SECRET_V2_NAMESPACE>
}
```

## Argument Reference

The following arguments are supported:

* `cluster_id` - (Required) The cluster id of the secret V2 (string)
* `name` - (Required) The name of the secret v2 (string)
* `namespace` - (Optional) The namespaces of the secret v2. Default: `default` (string)


## Attributes Reference

The following attributes are exported:

* `id` - (Computed) The ID of the resource (string)
* `resource_version` - (Computed) The k8s resource version (string)
* `data` - (Computed/Sensitive) The data of the secret v2 (map)
* `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)
* `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)
* `annotations` - (Computed) Annotations for the secret v2 (map)
* `labels` - (Computed) Labels for the secret v2 (map)
70 changes: 70 additions & 0 deletions docs/resources/secret_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
page_title: "Rancher2: rancher2_secret_v2 Resource"
---

# rancher2\_secret\_v2 Resource

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.

## Example Usage

```hcl
# Create a new Rancher2 Secret V2
resource "rancher2_secret_v2" "foo" {
cluster_id = <CLUSTER_ID>
name = "foo"
data = {
mydata1 = "<data1>"
mydata2 = "<data2>"
mydata3 = "<data3>"
}
}
# Create a new Rancher2 Secret V2 basic-auth
resource "rancher2_secret_v2" "foo" {
cluster_id = <CLUSTER_ID>
name = "foo"
namespace = "<mynamespace>"
type = "kubernetes.io/basic-auth"
data = {
password = "<mysecret>"
username = "<myuser>"
}
}
```

## Argument Reference

The following arguments are supported:

* `cluster_id` - (Required/ForceNew) The cluster id of the secret V2 (string)
* `data` - (Required/Sensitive) The data of the secret v2 (map)
* `name` - (Required) The name of the secret v2 (string)
* `namespace` - (Optional/ForceNew) The namespaces of the secret v2. Default: `default` (string)
* `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)
* `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)
* `annotations` - (Optional/Computed) Annotations for the secret v2 (map)
* `labels` - (Optional/Computed) Labels for the secret v2 (map)

## Attributes Reference

The following attributes are exported:

* `id` - (Computed) The ID of the resource (string)
* `resource_version` - (Computed) The k8s resource version (string)

## Timeouts

`rancher2_secret` provides the following
[Timeouts](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) configuration options:

- `create` - (Default `10 minutes`) Used for creating v2 secrets.
- `update` - (Default `10 minutes`) Used for v2 secret modifications.
- `delete` - (Default `10 minutes`) Used for deleting v2 secrets.

## Import

V2 secrets can be imported using the Rancher cluster ID, Secret V2 namespace and name.

```
$ terraform import rancher2_secret_v2.foo &lt;CLUSTER_ID&gt;.&lt;SECRET_V2_NAMESPACE&gt;/&lt;SECRET_V2_NAME&gt;
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/apiserver v0.20.0
)
Expand Down
1 change: 1 addition & 0 deletions rancher2/0_provider_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ provider "rancher2" {
` + testAccRancher2Registry + `
` + testAccRancher2RoleTemplateConfig + `
` + testAccRancher2Secret + `
` + testAccRancher2SecretV2 + `
` + testAccRancher2SecretNs + `
` + testAccRancher2SettingConfig + `
` + testAccRancher2Token + `
Expand Down
Loading

0 comments on commit 1b39891

Please sign in to comment.