Skip to content

Commit 52f4dc8

Browse files
author
Budi Darmawan
committed
Rebase from openshift-installer: allow multiple CIDR, allow dynamic endpoint URL, change to terraform community provider
1 parent c83c018 commit 52f4dc8

File tree

19 files changed

+588
-342
lines changed

19 files changed

+588
-342
lines changed

.terraform.lock.hcl

Lines changed: 110 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/main.tf

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@ locals {
22
public_endpoints = var.publish_strategy == "External" ? true : false
33
}
44

5+
terraform {
6+
required_providers {
7+
ignition = {
8+
source = "community-terraform-providers/ignition"
9+
version = "2.1.2"
10+
}
11+
}
12+
}
13+
14+
provider "ignition" {
15+
# Configuration options
16+
}
17+
18+
data "aws_partition" "current" {}
19+
20+
data "aws_ebs_default_kms_key" "current" {}
21+
522
resource "aws_s3_bucket" "ignition" {
23+
bucket = var.ignition_bucket
624
acl = "private"
725

826
tags = merge(
@@ -60,7 +78,7 @@ resource "aws_iam_role" "bootstrap" {
6078
{
6179
"Action": "sts:AssumeRole",
6280
"Principal": {
63-
"Service": "ec2.amazonaws.com"
81+
"Service": "ec2.${data.aws_partition.current.dns_suffix}"
6482
},
6583
"Effect": "Allow",
6684
"Sid": ""
@@ -119,8 +137,7 @@ resource "aws_instance" "bootstrap" {
119137
iam_instance_profile = aws_iam_instance_profile.bootstrap.name
120138
instance_type = var.instance_type
121139
subnet_id = var.subnet_id
122-
user_data = replace(data.ignition_config.redirect.rendered, "2.1.0", "3.1.0")
123-
# data.ignition_config.redirect.rendered
140+
user_data = data.ignition_config.redirect.rendered
124141
vpc_security_group_ids = flatten([var.vpc_security_group_ids, aws_security_group.bootstrap.id])
125142
associate_public_ip_address = local.public_endpoints
126143

@@ -141,6 +158,8 @@ resource "aws_instance" "bootstrap" {
141158
volume_type = var.volume_type
142159
volume_size = var.volume_size
143160
iops = var.volume_type == "io1" ? var.volume_iops : 0
161+
encrypted = true
162+
kms_key_id = var.volume_kms_key_id == "" ? data.aws_ebs_default_kms_key.current.key_arn : var.volume_kms_key_id
144163
}
145164

146165
volume_tags = merge(

bootstrap/variables.tf

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,38 @@ variable "ignition" {
1313
description = "The content of the bootstrap ignition file."
1414
}
1515

16-
variable "instance_type" {
16+
variable "ignition_bucket" {
17+
type = string
18+
description = "The S3 bucket where the ignition configuration is stored"
19+
}
20+
21+
variable "ignition_stub" {
1722
type = string
23+
description = <<EOF
24+
The stub Ignition config that should be used to boot the bootstrap instance. This already points to the presigned URL for the s3 bucket
25+
specified in ignition_bucket.
26+
EOF
27+
}
28+
29+
variable "instance_type" {
30+
type = string
1831
description = "The instance type of the bootstrap node."
1932
}
2033

2134
variable "subnet_id" {
22-
type = string
35+
type = string
2336
description = "The subnet ID for the bootstrap node."
2437
}
2538

2639
variable "tags" {
27-
type = map(string)
28-
default = {}
40+
type = map(string)
41+
default = {}
2942
description = "AWS tags to be applied to created resources."
3043
}
3144

3245
variable "target_group_arns" {
33-
type = list(string)
34-
default = []
46+
type = list(string)
47+
default = []
3548
description = "The list of target group ARNs for the load balancer."
3649
}
3750

@@ -40,41 +53,46 @@ variable "target_group_arns_length" {
4053
}
4154

4255
variable "volume_iops" {
43-
type = string
44-
default = "100"
56+
type = string
57+
default = "100"
4558
description = "The amount of IOPS to provision for the disk."
4659
}
4760

4861
variable "volume_size" {
49-
type = string
50-
default = "30"
62+
type = string
63+
default = "30"
5164
description = "The volume size (in gibibytes) for the bootstrap node's root volume."
5265
}
5366

5467
variable "volume_type" {
55-
type = string
56-
default = "gp2"
68+
type = string
69+
default = "gp2"
5770
description = "The volume type for the bootstrap node's root volume."
5871
}
5972

73+
variable "volume_kms_key_id" {
74+
type = string
75+
description = "The KMS key id that should be used to encrypt the bootstrap node's root block device."
76+
}
77+
6078
variable "vpc_id" {
61-
type = string
79+
type = string
6280
description = "VPC ID is used to create resources like security group rules for bootstrap machine."
6381
}
6482

6583
variable "vpc_cidrs" {
66-
type = list(string)
67-
default = []
84+
type = list(string)
85+
default = []
6886
description = "VPC CIDR blocks."
6987
}
7088

7189
variable "vpc_security_group_ids" {
72-
type = list(string)
73-
default = []
90+
type = list(string)
91+
default = []
7492
description = "VPC security group IDs for the bootstrap node."
7593
}
7694

7795
variable "publish_strategy" {
78-
type = string
96+
type = string
7997
description = "The publishing strategy for endpoints like load balancers"
8098
}

config.tf

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
variable "openshift_pull_secret" {
2-
type = string
3-
default = "./openshift_pull_secret.json"
4-
}
5-
6-
variable "openshift_installer_url" {
7-
type = string
8-
description = <<EOF
9-
The URL to download OpenShift installer.
10-
11-
default is "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest"
12-
To install a specific version, use https://mirror.openshift.com/pub/openshift-v4/clients/ocp/<version>
13-
EOF
14-
default = "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest"
15-
}
16-
17-
variable "aws_access_key_id" {
18-
type = string
19-
description = "AWS access key"
20-
}
21-
22-
variable "aws_secret_access_key" {
23-
type = string
24-
description = "AWS Secret"
25-
}
26-
271
terraform {
282
required_version = ">= 0.12"
293
}
@@ -38,6 +12,9 @@ EOF
3812
default = "10.0.0.0/16"
3913
}
4014

15+
16+
17+
4118
variable "base_domain" {
4219
type = string
4320

@@ -53,18 +30,19 @@ EOF
5330

5431
}
5532

56-
variable "clustername" {
33+
variable "cluster_domain" {
5734
type = string
5835

5936
description = <<EOF
60-
The name of the cluster. It must NOT contain a trailing period. Some
37+
The domain of the cluster. It must NOT contain a trailing period. Some
6138
DNS providers will automatically add this if necessary.
6239
40+
All the records for the cluster are created under this domain.
41+
6342
Note: This field MUST be set manually prior to creating the cluster.
6443
EOF
6544

6645
}
67-
6846
// This variable is generated by OpenShift internally. Do not modify
6947
variable "cluster_id" {
7048
type = string
@@ -88,9 +66,35 @@ EOF
8866

8967
variable "use_ipv6" {
9068
type = bool
69+
description = <<EOF
70+
Should the cluster be created with ipv6 networking.
71+
EOF
72+
9173
default = false
74+
}
75+
76+
variable "openshift_pull_secret" {
77+
type = string
78+
default = "./openshift_pull_secret.json"
79+
}
80+
81+
variable "openshift_installer_url" {
82+
type = string
9283
description = <<EOF
93-
Should the cluster be created with ipv6 networking. (default = false)
84+
The URL to download OpenShift installer.
85+
86+
default is "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest"
87+
To install a specific version, use https://mirror.openshift.com/pub/openshift-v4/clients/ocp/<version>
9488
EOF
89+
default = "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest"
90+
}
91+
92+
variable "aws_access_key_id" {
93+
type = string
94+
description = "AWS access key"
95+
}
9596

97+
variable "aws_secret_access_key" {
98+
type = string
99+
description = "AWS Secret"
96100
}

iam/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ locals {
22
arn = "aws"
33
}
44

5+
data "aws_partition" "current" {}
6+
57
resource "aws_iam_instance_profile" "worker" {
68
name = "${var.cluster_id}-worker-profile"
79

@@ -19,7 +21,7 @@ resource "aws_iam_role" "worker_role" {
1921
{
2022
"Action": "sts:AssumeRole",
2123
"Principal": {
22-
"Service": "ec2.amazonaws.com"
24+
"Service": "ec2.${data.aws_partition.current.dns_suffix}"
2325
},
2426
"Effect": "Allow",
2527
"Sid": ""
@@ -46,7 +48,10 @@ resource "aws_iam_role_policy" "worker_policy" {
4648
"Statement": [
4749
{
4850
"Effect": "Allow",
49-
"Action": "ec2:Describe*",
51+
"Action": [
52+
"ec2:DescribeInstances",
53+
"ec2:DescribeRegions"
54+
],
5055
"Resource": "*"
5156
}
5257
]

0 commit comments

Comments
 (0)