@@ -54,12 +54,30 @@ resource "aws_security_group" "kubernetes" {
5454 }
5555}
5656
57- resource "aws_security_group_rule" "allow_all" {
57+ resource "aws_security_group_rule" "allow_ssh" {
58+ type = " ingress"
59+ from_port = 22
60+ to_port = 22
61+ protocol = " tcp"
62+ cidr_blocks = [" 0.0.0.0/0" ]
63+ security_group_id = " ${ aws_security_group . kubernetes . id } "
64+ }
65+
66+ resource "aws_security_group_rule" "allow_kube_api" {
67+ type = " ingress"
68+ from_port = 6443
69+ to_port = 6443
70+ protocol = " tcp"
71+ cidr_blocks = [" 0.0.0.0/0" ]
72+ security_group_id = " ${ aws_security_group . kubernetes . id } "
73+ }
74+
75+ resource "aws_security_group_rule" "allow_all_cluster" {
5876 type = " ingress"
5977 from_port = 0
6078 to_port = 65535
6179 protocol = " -1"
62- cidr_blocks = [ " 0.0.0.0/0 " ]
80+ source_security_group_id = " ${ aws_security_group . kubernetes . id } "
6381 security_group_id = " ${ aws_security_group . kubernetes . id } "
6482}
6583
@@ -76,13 +94,20 @@ resource "template_file" "kubernetes" {
7694 filename = " templates/kubernetes.sh"
7795
7896 vars = {
79- etcd_dicovery_url = " ${ replace (file (" etcd_discovery_url.txt" ), " /\n * /" , " " )} "
97+ etcd_dicovery_url = " ${ replace (file (" etcd_discovery_url.txt" ), " /\n /" , " " )} "
8098 containers_cidr = " ${ var . containers_cidr } "
8199 kubernetes_version = " ${ var . kubernetes_version } "
82100 portal_net = " ${ var . portal_net } "
83101 }
84102}
85103
104+ resource "template_file" "tokens" {
105+ filename = " templates/tokens.csv"
106+
107+ vars = {
108+ token = " ${ replace (file (" kube_token.txt" ), " /\n /" , " " )} "
109+ }
110+ }
86111
87112resource "aws_instance" "etcd" {
88113 ami = " ${ var . ami } "
@@ -147,6 +172,9 @@ resource "aws_instance" "master" {
147172
148173 provisioner "remote-exec" {
149174 inline = [
175+ " cat <<'EOF' > /tmp/tokens.csv\n ${ template_file . tokens . rendered } \n EOF" ,
176+ " sudo mkdir -p mkdir /etc/kubernetes" ,
177+ " sudo mv /tmp/tokens.csv /etc/kubernetes/tokens.csv" ,
150178 " echo 'PRIVATE_IP=${ self . private_ip } ' > /tmp/network.env" ,
151179 " echo 'PUBLIC_IP=${ self . public_ip } ' >> /tmp/network.env" ,
152180 " sudo mv /tmp/network.env /etc/network.env" ,
@@ -172,7 +200,7 @@ resource "aws_instance" "worker" {
172200 }
173201
174202 tags {
175- Name = " kubernetes-${ var . cluster_name } -master "
203+ Name = " kubernetes-${ var . cluster_name } -worker "
176204 Cluster = " ${ var . cluster_name } "
177205 Role = " worker"
178206 }
@@ -195,7 +223,17 @@ resource "aws_instance" "worker" {
195223 }
196224}
197225
226+ resource "template_file" "kubectl-config" {
227+ filename = " templates/kubectl-config.sh"
228+ vars = {
229+ cluster_name = " ${ var . cluster_name } "
230+ token = " ${ replace (file (" kube_token.txt" ), " /\n /" , " " )} "
231+ server = " ${ aws_instance . master . public_ip } "
232+ }
233+ }
198234
199235output "kubernetes-api-server" {
200- value = " http:// ${ aws_instance . master . public_ip } :8080 "
236+ value = " ${ template_file . kubectl-config . rendered } "
201237}
238+
239+
0 commit comments