@@ -22,7 +22,7 @@ provider "kubernetes" {
22
22
module "tiller_namespace" {
23
23
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
24
24
# to a specific version of the modules, such as the following example:
25
- # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-namespace?ref=v0.1 .0"
25
+ # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-namespace?ref=v0.3 .0"
26
26
source = " ./modules/k8s-namespace"
27
27
28
28
name = " ${ var . tiller_namespace } "
@@ -31,7 +31,7 @@ module "tiller_namespace" {
31
31
module "resource_namespace" {
32
32
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
33
33
# to a specific version of the modules, such as the following example:
34
- # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-namespace?ref=v0.1 .0"
34
+ # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-namespace?ref=v0.3 .0"
35
35
source = " ./modules/k8s-namespace"
36
36
37
37
name = " ${ var . resource_namespace } "
@@ -40,7 +40,7 @@ module "resource_namespace" {
40
40
module "tiller_service_account" {
41
41
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
42
42
# to a specific version of the modules, such as the following example:
43
- # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-service-account?ref=v0.1 .0"
43
+ # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-service-account?ref=v0.3 .0"
44
44
source = " ./modules/k8s-service-account"
45
45
46
46
name = " ${ var . service_account_name } "
@@ -64,24 +64,31 @@ module "tiller_service_account" {
64
64
}
65
65
66
66
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67
- # DEPLOY TILLER
67
+ # GENERATE TLS CERTIFICATES FOR USE WITH TILLER
68
+ # This will use kubergrunt to generate TLS certificates, and upload them as Kubernetes Secrets that can then be used by
69
+ # Tiller.
68
70
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69
71
70
- resource "null_resource" "tiller_tls_ca_certs" {
71
- provisioner "local-exec" {
72
- command = " kubergrunt tls gen --ca --namespace kube-system --secret-name ${ local . tls_ca_secret_name } --secret-label gruntwork.io/tiller-namespace=${ var . tiller_namespace } --secret-label gruntwork.io/tiller-credentials=true --secret-label gruntwork.io/tiller-credentials-type=ca --tls-subject-json '${ jsonencode (var. tls_subject )} ' --tls-private-key-algorithm ${ var . private_key_algorithm } ${ local . tls_algorithm_config } ${ local . kubectl_config_options } "
73
- }
74
- }
75
-
76
72
resource "null_resource" "tiller_tls_certs" {
77
73
provisioner "local-exec" {
78
- command = " kubergrunt tls gen --namespace ${ module . tiller_namespace . name } --ca-secret-name ${ local . tls_ca_secret_name } --ca-namespace kube-system --secret-name ${ local . tls_secret_name } --secret-label gruntwork.io/tiller-namespace=${ var . tiller_namespace } --secret-label gruntwork.io/tiller-credentials=true --secret-label gruntwork.io/tiller-credentials-type=server --tls-subject-json '${ jsonencode (var. tls_subject )} ' --tls-private-key-algorithm ${ var . private_key_algorithm } ${ local . tls_algorithm_config } ${ local . kubectl_config_options } "
79
- }
74
+ command = <<- EOF
75
+ # Generate CA TLS certs
76
+ kubergrunt tls gen --ca --namespace kube-system --secret-name ${ local . tls_ca_secret_name } --secret-label gruntwork.io/tiller-namespace=${ var . tiller_namespace } --secret-label gruntwork.io/tiller-credentials=true --secret-label gruntwork.io/tiller-credentials-type=ca --tls-subject-json '${ jsonencode (var. tls_subject )} ' --tls-private-key-algorithm ${ var . private_key_algorithm } ${ local . tls_algorithm_config } ${ local . kubectl_config_options }
80
77
81
- depends_on = [" null_resource.tiller_tls_ca_certs" ]
78
+ # Then use that CA to generate server TLS certs
79
+ kubergrunt tls gen --namespace ${ module . tiller_namespace . name } --ca-secret-name ${ local . tls_ca_secret_name } --ca-namespace kube-system --secret-name ${ local . tls_secret_name } --secret-label gruntwork.io/tiller-namespace=${ var . tiller_namespace } --secret-label gruntwork.io/tiller-credentials=true --secret-label gruntwork.io/tiller-credentials-type=server --tls-subject-json '${ jsonencode (var. tls_subject )} ' --tls-private-key-algorithm ${ var . private_key_algorithm } ${ local . tls_algorithm_config } ${ local . kubectl_config_options }
80
+ EOF
81
+ }
82
82
}
83
83
84
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85
+ # DEPLOY TILLER
86
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
+
84
88
module "tiller" {
89
+ # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
90
+ # to a specific version of the modules, such as the following example:
91
+ # source = "git::[email protected] :gruntwork-io/terraform-kubernetes-helm.git//modules/k8s-tiller?ref=v0.3.0"
85
92
source = " ./modules/k8s-tiller"
86
93
87
94
tiller_service_account_name = " ${ module . tiller_service_account . name } "
@@ -93,22 +100,50 @@ module "tiller" {
93
100
# Kubergrunt will store the private key under tls.pem
94
101
tiller_tls_key_file_name = " tls.pem"
95
102
96
- dependencies = [
97
- " ${ null_resource. tiller_tls_ca_certs . id } " ,
98
- " ${ null_resource. tiller_tls_certs . id } " ,
99
- ]
103
+ dependencies = [" ${ null_resource. tiller_tls_certs . id } " ]
100
104
}
101
105
102
- locals {
103
- helm_home_with_default = " ${ var . helm_home == " " ? pathexpand (" ~/.helm" ) : var . helm_home } "
106
+ # We use kubergrunt to wait for Tiller to be deployed. Any resources that depend on this can assume Tiller is
107
+ # successfully deployed and up at that point.
108
+ resource "null_resource" "wait_for_tiller" {
109
+ provisioner "local-exec" {
110
+ command = " kubergrunt helm wait-for-tiller --tiller-namespace ${ module . tiller_namespace . name } --tiller-deployment-name ${ module . tiller . deployment_name } --expected-tiller-version ${ var . tiller_version } "
111
+ }
112
+ }
113
+
114
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115
+ # CONFIGURE OPERATOR HELM CLIENT
116
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117
+
118
+ resource "null_resource" "grant_and_configure_helm" {
119
+ count = " ${ var . configure_helm } "
120
+
121
+ provisioner "local-exec" {
122
+ command = <<- EOF
123
+ kubergrunt helm grant --tiller-namespace ${ module . tiller_namespace . name } ${ local . kubectl_config_options } --tls-subject-json '${ jsonencode (var. client_tls_subject )} ' ${ local . configure_args }
124
+
125
+ kubergrunt helm configure --helm-home ${ local . helm_home_with_default } --tiller-namespace ${ module . tiller_namespace . name } --resource-namespace ${ module . resource_namespace . name } ${ local . kubectl_config_options } ${ local . configure_args }
126
+ EOF
127
+ }
104
128
129
+ depends_on = [" null_resource.wait_for_tiller" ]
130
+ }
131
+
132
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133
+ # COMPUTATIONS
134
+ # These locals compute various useful information used throughout this Terraform module.
135
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
+
137
+ locals {
105
138
kubectl_config_options = " ${ var . kubectl_config_context_name != " " ? " --kubectl-context-name ${ var . kubectl_config_context_name } " : " " } ${ var . kubectl_config_path != " " ? " --kubeconfig ${ var . kubectl_config_path } " : " " } "
106
139
107
140
tls_ca_secret_name = " ${ var . tiller_namespace } -namespace-tiller-ca-certs"
108
141
tls_secret_name = " tiller-certs"
109
142
110
143
tls_algorithm_config = " ${ var . private_key_algorithm == " ECDSA" ? " --tls-private-key-ecdsa-curve ${ var . private_key_ecdsa_curve } " : " --tls-private-key-rsa-bits ${ var . private_key_rsa_bits } " } "
111
144
145
+ helm_home_with_default = " ${ var . helm_home == " " ? pathexpand (" ~/.helm" ) : var . helm_home } "
146
+
112
147
configure_args = " ${
113
148
var . helm_client_rbac_user != " " ? " --rbac-user ${ var . helm_client_rbac_user } "
114
149
: var . helm_client_rbac_group != " " ? " --rbac-group ${ var . helm_client_rbac_group } "
0 commit comments