Skip to content

Commit

Permalink
Upgrading to tf 1.0.0 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
thpang authored Jun 8, 2021
1 parent 6462005 commit b13e626
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
.terraform.lock.hcl

# Terraform tfvars file
terraform.tfvars
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG TERRAFORM_VERSION=0.13.6
ARG AWS_CLI_VERSION=2.1.20
ARG TERRAFORM_VERSION=1.0.0
ARG AWS_CLI_VERSION=2.1.29
FROM hashicorp/terraform:$TERRAFORM_VERSION as terraform

FROM amazon/aws-cli:$AWS_CLI_VERSION
ARG KUBECTL_VERSION=1.18.8
ARG KUBECTL_VERSION=1.19.9

WORKDIR /viya4-iac-aws

Expand All @@ -15,7 +15,7 @@ RUN yum -y install git openssh jq which \
&& chmod 755 ./kubectl /viya4-iac-aws/docker-entrypoint.sh \
&& mv ./kubectl /usr/local/bin/kubectl \
&& chmod g=u -R /etc/passwd /etc/group /viya4-iac-aws \
&& terraform init /viya4-iac-aws
&& chdir /viya4-iac-aws ; terraform init

ENV TF_VAR_iac_tooling=docker
ENTRYPOINT ["/viya4-iac-aws/docker-entrypoint.sh"]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Operational knowledge of:
### Required

- Access to **AWS account** with a user associated with the supplied [IAM Policy](./files/policies/devops-iac-eks-policy.json)
- Subscription to [Ubuntu 18.04 LTS - Bionic](https://aws.amazon.com/marketplace/pp/B07CQ33QKV/)
- Subscription to [Ubuntu 20.04 LTS - Focal](https://aws.amazon.com/marketplace/pp/prodview-iftkyuwv2sjxi)
- Terraform or Docker

- #### Terraform

- [Terraform](https://www.terraform.io/downloads.html) - v0.13.6
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - v1.18.8
- [Terraform](https://www.terraform.io/downloads.html) - v1.0.0
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - v1.19.9
- [jq](https://stedolan.github.io/jq/) - v1.6
- [AWS CLI v2.0](https://aws.amazon.com/cli) - (optional -useful as an alternative to the AWS Web Console) - v2.1.20
- [AWS CLI](https://aws.amazon.com/cli) - (optional - useful as an alternative to the AWS Web Console) - v2.1.29

- #### Docker

Expand All @@ -62,7 +62,7 @@ See [Authenticating Terraform to access AWS](./docs/user/TerraformAWSAuthentica

### Customize Input Values

Create a file named `terraform.tfvars` to customize any input variable value. For starters, you can copy one of the provided sample variable definition files in [examples](./examples) folder. For more details on the variables declared in [variables.tf](variables.tf) refer to [CONFIG-VARS.md](docs/CONFIG-VARS.md).
Create a file named `terraform.tfvars` to customize any input variable value documented in the [CONFIG-VARS.md](docs/CONFIG-VARS.md) file. For starters, you can copy one of the provided sample variable definition files in [examples](./examples) folder. For more details on the variables declared refer to the [CONFIG-VARS.md](docs/CONFIG-VARS.md) file.

**NOTE:** You will need to update the `cidr_blocks` in the [variables.tf](variables.tf) file to allow traffic from your current network. Without these rules, access to the cluster will only be allowed via the AWS Console.

Expand Down
4 changes: 2 additions & 2 deletions container-structure-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ commandTests:
- name: "terraform version"
command: "terraform"
args: ["--version"]
expectedOutput: ["Terraform v0.13.6"]
expectedOutput: ["Terraform v1.0.0"]
- name: "aws-cli version"
command: "sh"
args:
- -c
- |
aws --version
expectedOutput: ["aws-cli/2.1.20"]
expectedOutput: ["aws-cli/2.1.29"]

metadataTest:
workdir: "/viya4-iac-aws"
Expand Down
8 changes: 4 additions & 4 deletions examples/sample-input-byo.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# !NOTE! - These are only a subset of variables.tf provided for sample.
# Customize this file to add any variables from 'variables.tf' that you want
# to change their default values.
# !NOTE! - These are only a subset of CONFIG-VARS.md provided for sample.
# Customize this file to add any variables from 'CONFIG-VARS.md' that you want
# to change their default values.

# **************** REQUIRED VARIABLES ****************
# These required variables' values MUST be provided by the User
Expand Down Expand Up @@ -30,7 +30,7 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
tags = { } # e.g., { "key1" = "value1", "key2" = "value2" }

## Cluster config
kubernetes_version = "1.18"
kubernetes_version = "1.19"
default_nodepool_node_count = 2
default_nodepool_vm_type = "m5.2xlarge"
default_nodepool_custom_data = ""
Expand Down
8 changes: 4 additions & 4 deletions examples/sample-input-custom-data.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# !NOTE! - These are only a subset of variables.tf provided for sample.
# Customize this file to add any variables from 'variables.tf' that you want
# to change their default values.
# !NOTE! - These are only a subset of CONFIG-VARS.md provided for sample.
# Customize this file to add any variables from 'CONFIG-VARS.md' that you want
# to change their default values.

# **************** REQUIRED VARIABLES ****************
# These required variables' values MUST be provided by the User
Expand All @@ -20,7 +20,7 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
tags = { } # e.g., { "key1" = "value1", "key2" = "value2" }

## Cluster config
kubernetes_version = "1.18"
kubernetes_version = "1.19"
default_nodepool_node_count = 2
default_nodepool_vm_type = "m5.2xlarge"
default_nodepool_custom_data = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# !NOTE! - These are only a subset of variables.tf provided for sample.
# Customize this file to add any variables from 'variables.tf' that you want
# to change their default values.
# !NOTE! - These are only a subset of CONFIG-VARS.md provided for sample.
# Customize this file to add any variables from 'CONFIG-VARS.md' that you want
# to change their default values.

# **************** REQUIRED VARIABLES ****************
# These required variables' values MUST be provided by the User
Expand Down
8 changes: 4 additions & 4 deletions examples/sample-input-ha.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# !NOTE! - These are only a subset of variables.tf provided for sample.
# Customize this file to add any variables from 'variables.tf' that you want
# to change their default values.
# !NOTE! - These are only a subset of CONFIG-VARS.md provided for sample.
# Customize this file to add any variables from 'CONFIG-VARS.md' that you want
# to change their default values.

# **************** REQUIRED VARIABLES ****************
# These required variables' values MUST be provided by the User
Expand All @@ -23,7 +23,7 @@ tags = { } # e.g., { "key1" = "value1", "key2
ssh_public_key = "~/.ssh/id_rsa.pub"

## Cluster config
kubernetes_version = "1.18"
kubernetes_version = "1.19"
default_nodepool_node_count = 2
default_nodepool_vm_type = "m5.2xlarge"
default_nodepool_custom_data = ""
Expand Down
8 changes: 4 additions & 4 deletions examples/sample-input.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# !NOTE! - These are only a subset of variables.tf provided for sample.
# Customize this file to add any variables from 'variables.tf' that you want
# to change their default values.
# !NOTE! - These are only a subset of CONFIG-VARS.md provided for sample.
# Customize this file to add any variables from 'CONFIG-VARS.md' that you want
# to change their default values.

# **************** REQUIRED VARIABLES ****************
# These required variables' values MUST be provided by the User
Expand All @@ -20,7 +20,7 @@ default_public_access_cidrs = [] # e.g., ["123.45.6.89/32"]
tags = { } # e.g., { "key1" = "value1", "key2" = "value2" }

## Cluster config
kubernetes_version = "1.18"
kubernetes_version = "1.19"
default_nodepool_node_count = 2
default_nodepool_vm_type = "m5.2xlarge"
default_nodepool_custom_data = ""
Expand Down
43 changes: 5 additions & 38 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,6 @@
# Terraform Registry : https://registry.terraform.io/namespaces/terraform-aws-modules
# GitHub Repository : https://github.com/terraform-aws-modules
#
terraform {
required_version = ">= 0.13.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.42.0"
}
random = {
source = "hashicorp/random"
version = "3.0.1"
}
local = {
source = "hashicorp/local"
version = "2.0.0"
}
null = {
source = "hashicorp/null"
version = "3.0.0"
}
template = {
source = "hashicorp/template"
version = "2.2.0"
}
external = {
source = "hashicorp/external"
version = "2.0.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.0.2"
}
}
}

provider "aws" {
region = var.location
Expand Down Expand Up @@ -145,7 +112,7 @@ resource "aws_security_group" "sg" {
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge(var.tags, map("Name", "${var.prefix}-sg"))
tags = merge(var.tags, tomap({ Name: "${var.prefix}-sg" }))
}


Expand All @@ -154,7 +121,7 @@ resource "aws_efs_file_system" "efs-fs" {
count = var.storage_type == "ha" ? 1 : 0
creation_token = "${var.prefix}-efs"
performance_mode = var.efs_performance_mode
tags = merge(var.tags, map("Name", "${var.prefix}-efs"))
tags = merge(var.tags, tomap({ Name: "${var.prefix}-efs" }))
}

# EFS Mount Target - https://www.terraform.io/docs/providers/aws/r/efs_mount_target.html
Expand Down Expand Up @@ -291,7 +258,7 @@ module "nfs" {
# EBS CSI driver IAM Policy for EKS worker nodes - https://registry.terraform.io/modules/terraform-aws-modules/iam
module "iam_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = "3.8.0"
version = "4.1.0"

name = "${var.prefix}_ebs_csi_policy"
description = "EBS CSI driver IAM Policy"
Expand Down Expand Up @@ -361,7 +328,7 @@ locals {
additional_userdata = (np_value.custom_data != "" ? file(np_value.custom_data) : "")
metadata_http_endpoint = np_value.metadata_http_endpoint
metadata_http_tokens = np_value.metadata_http_tokens
metadata_http_put_response_hop_limit = np_value.metadata_http_put_response_hop_limit
metadata_http_put_response_hop_limit = np_value.metadata_http_put_response_hop_limit
}
]

Expand Down Expand Up @@ -415,7 +382,7 @@ module "kubeconfig" {
# Database Setup - https://github.com/terraform-aws-modules/terraform-aws-rds
module "db" {
source = "terraform-aws-modules/rds/aws"
version = "2.20.0"
version = "3.1.0"

identifier = (var.postgres_server_name == "" ? "${var.prefix}db" : var.postgres_server_name)

Expand Down
10 changes: 5 additions & 5 deletions modules/aws_vm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Hack for assigning disk in a vm based on an index value.
locals {
device_name = [
# "/dev/sdb", - NOTE: These are skipped, Ubuntu Server 18.04 LTS
# "/dev/sdb", - NOTE: These are skipped, Ubuntu Server 20.04 LTS
# "/dev/sdc", uses these for ephmeral storage.
"/dev/sdd",
"/dev/sde",
Expand Down Expand Up @@ -37,7 +37,7 @@ data "aws_ami" "ubuntu" {

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}

filter {
Expand Down Expand Up @@ -80,15 +80,15 @@ resource "aws_instance" "vm" {
iops = var.os_disk_iops
}

tags = merge(var.tags, map("Name", "${var.name}-vm"))
tags = merge(var.tags, tomap({ Name: "${var.name}-vm" }))

}

resource "aws_eip" "eip" {
count = (var.create_vm && var.create_public_ip) ? 1 : 0
vpc = true
instance = aws_instance.vm.0.id
tags = merge(var.tags, map("Name", "${var.name}-eip"))
tags = merge(var.tags, tomap({ Name: "${var.name}-eip" }))
}

resource "aws_volume_attachment" "data-volume-attachment" {
Expand All @@ -104,5 +104,5 @@ resource "aws_ebs_volume" "raid_disk" {
size = var.data_disk_size
type = var.data_disk_type
iops = var.data_disk_iops
tags = merge(var.tags, map("Name", "${var.name}-vm"))
tags = merge(var.tags, tomap({ Name: "${var.name}-vm" }))
}
11 changes: 6 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,25 @@ output "nfs_public_dns" {
}

output "postgres_fqdn" {
value = var.create_postgres ? module.db.this_db_instance_address : ""
value = var.create_postgres ? module.db.db_instance_address : ""
}

output "postgres_admin" {
value = var.create_postgres ? module.db.this_db_instance_username : ""
value = var.create_postgres ? module.db.db_instance_username : ""
sensitive = true
}

output "postgres_password" {
value = var.create_postgres ? module.db.this_db_instance_password : ""
value = var.create_postgres ? module.db.db_instance_password : ""
sensitive = true
}

output "postgres_server_name" {
value = var.create_postgres ? module.db.this_db_instance_id : ""
value = var.create_postgres ? module.db.db_instance_id : ""
}

output "postgres_server_port" {
value = var.create_postgres ? module.db.this_db_instance_port : ""
value = var.create_postgres ? module.db.db_instance_port : ""
}

output "nat_ip" {
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ variable efs_performance_mode {
## Kubernetes
variable "kubernetes_version" {
description = "The EKS cluster K8s version"
default = "1.18"
default = "1.19"
}

variable "tags" {
Expand Down
33 changes: 33 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.43.0"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
local = {
source = "hashicorp/local"
version = "2.1.0"
}
null = {
source = "hashicorp/null"
version = "3.1.0"
}
template = {
source = "hashicorp/template"
version = "2.2.0"
}
external = {
source = "hashicorp/external"
version = "2.1.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.2.0"
}
}
}

0 comments on commit b13e626

Please sign in to comment.