Skip to content

Commit e4ae4b2

Browse files
authored
feat(anthos-attached-clusters/kind): add outputs (#705)
1 parent 66ded37 commit e4ae4b2

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

anthos-attached-clusters/kind/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ The other examples and module limit dependancies to terraform core providers, bu
2525
```
2626
Terraform may give a warning along the lines of `Warning: Content-Type is not recognized as a text type, got "application/jwk-set+json"` but this is ok and just a side effect of the `http` provider we're using and the content type the cluster returns for the `jwks` content.
2727
1. The process should take about a few short minutes to complete.
28-
1. Set some variables based on the terraform porjects values and use them to generate RBAC for the cluster and credentials to login:
28+
1. Set some variables based on the terraform projects values and use them to generate RBAC for the cluster and credentials to login:
2929
```bash
3030
31-
PROJECT=$(echo google_container_attached_cluster.primary.project | terraform console | tr -d '"')
32-
CLUSTER=$(echo google_container_attached_cluster.primary.name | terraform console | tr -d '"')
33-
KUBECONFIG=$(echo kind_cluster.cluster.kubeconfig_path | terraform console | tr -d '"')
31+
PROJECT=$(terraform output PROJECT)
32+
CLUSTER=$(terraform output CLUSTER)
33+
KUBECONFIG=$(terraform output KUBECONFIG)
34+
CONTEXT=$(terraform output CONTEXT)
3435
3536
# set this to whomever you'd like to grant access
3637
3738
# set this whatever role you intend
3839
ROLE=clusterrole/cluster-admin
3940

4041
gcloud container fleet memberships generate-gateway-rbac --apply \
41-
--kubeconfig ${KUBECONFIG} --context=kind-${CLUSTER} \
42+
--kubeconfig ${KUBECONFIG} --context=${CONTEXT} \
4243
--project=${PROJECT} \
4344
--membership=${CLUSTER} \
4445
--role=${ROLE} \

anthos-attached-clusters/kind/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
// This is an example of how you might use the attached module with a local kind cluster
1919

2020
locals {
21-
cluster_name = "${var.name_prefix}-cluster"
21+
cluster_name = "${var.name_prefix}-cluster"
22+
cluster_context = jsondecode(jsonencode(yamldecode(kind_cluster.cluster.kubeconfig).contexts))[0].name
2223
}
2324

2425
resource "kind_cluster" "cluster" {
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "PROJECT" {
18+
description = "cluster project"
19+
value = google_container_attached_cluster.primary.project
20+
}
21+
22+
output "CLUSTER" {
23+
description = "cluster name"
24+
value = google_container_attached_cluster.primary.name
25+
}
26+
27+
output "KUBECONFIG" {
28+
description = "cluster kubeconfig"
29+
value = kind_cluster.cluster.kubeconfig_path
30+
}
31+
32+
output "CONTEXT" {
33+
description = "cluster context"
34+
value = local.cluster_context
35+
}

0 commit comments

Comments
 (0)