Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review of AWS modules and subsequent correction of RKE/RKE2/K3S recipes #145

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2e010ef
Reviewed AWS modules and rewrote AWS EC2 x RKE recipe
Jun 25, 2024
ac24390
Reviewed tests for AWS EC2 and AWS EC2 x RKE x Rancher
Jun 25, 2024
dd88caf
Fixed code in path recipes/rke/split-roles/aws + Optimization of code…
Jun 26, 2024
691613d
Reviewed tests for AWS EC2 and AWS EC2 x RKE2 x Rancher
Jun 27, 2024
03c6a34
Fixed code in path recipes/rke/split-roles/aws - Added Rancher deploy…
Jun 28, 2024
feebbd5
Fixed AWS x RKE2 instances count
Jul 1, 2024
9364d50
Rewrote AWS EC2 x K3S recipe
Jul 2, 2024
f90b4e9
Fixed conflicts
Jul 2, 2024
71f2748
Merge branch 'main' into fix/review-aws-modules
glovecchi0 Jul 2, 2024
ea7c741
Reviewed tests for AWS EC2 x RKE (split-roles)
Jul 2, 2024
4c91761
Fixed AWS x K3S README.md file
Jul 2, 2024
066cdaf
Fixed AWS x K3S README.md file
Jul 3, 2024
70ba27d
Fixed copy/paste issue
Jul 12, 2024
8802ead
Fixed ssh key mngt
Jul 15, 2024
62b3416
Shortened the deploy commands
Jul 15, 2024
7f5bb08
Fixed all the AWS recipes
Jul 15, 2024
f43baff
Fixed RKE split-roles recipe
Jul 15, 2024
fde8372
One-destroy command - GKE x RKE,RKE2,K3s
Jul 25, 2024
0dd6d5b
Revised standalone RKE module for AWS
Jul 25, 2024
053ff3e
Fixed conflicts
Jul 26, 2024
7884538
Fixed recipes/standalone/aws/rke/README.md file
Jul 26, 2024
0f244db
Rebase
Jul 30, 2024
65beba8
Reviewed tests for AWS EC2 and AWS EC2 x RKE x Rancher
Jun 25, 2024
990b1ba
Rebase
Jul 30, 2024
5b51d4c
Reviewed tests for AWS EC2 and AWS EC2 x RKE2 x Rancher
Jun 27, 2024
307a94f
Fixed code in path recipes/rke/split-roles/aws - Added Rancher deploy…
Jun 28, 2024
00d0e76
Fixed AWS x RKE2 instances count
Jul 1, 2024
92a3d1f
Rewrote AWS EC2 x K3S recipe
Jul 2, 2024
a2e0576
Reviewed tests for AWS EC2 x RKE (split-roles)
Jul 2, 2024
e73ffd1
Fixed AWS x K3S README.md file
Jul 2, 2024
5590842
Fixed AWS x K3S README.md file
Jul 3, 2024
9e4b658
Fixed copy/paste issue
Jul 12, 2024
203c579
Rebase
Jul 30, 2024
d618979
Fixed all the AWS recipes
Jul 15, 2024
9223f88
Fixed RKE split-roles recipe
Jul 15, 2024
35f7106
One-destroy command - GKE x RKE,RKE2,K3s
Jul 25, 2024
fdfa383
Merge branch 'fix/review-aws-modules' of github.com:rancher/tf-ranche…
Jul 30, 2024
6670f1e
Rebase
Jul 30, 2024
3d309fc
Merge branch 'fix/review-aws-modules' of github.com:rancher/tf-ranche…
Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 66 additions & 36 deletions modules/infra/aws/README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,79 @@
# Terraform | AWS Infrastructure
# Terraform | AWS - Preparatory steps

Terraform module to provide AWS nodes prepared for creating a kubernetes cluster.
In order for Terraform to run operations on your behalf, you must [install and configure the AWS CLI tool](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html#getting-started-install-instructions).

Basic infrastructure options are provided to be coupled with other modules for example environments.
## Example

Documentation can be found [here](./docs.md).
#### macOS installation and setup for all users

## Examples
```console
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
```

```console
sudo installer -pkg AWSCLIV2.pkg -target /
```

#### Verify installation

```console
$ which aws
/usr/local/bin/aws
```

```console
$ aws --version
aws-cli/2.13.33 Python/3.11.6 Darwin/23.1.0 exe/x86_64 prompt/off
```

#### Launch a single instance, create a keypair
#### Setup credentials and configuration

```terraform
module "upstream_cluster" {
source = "git::https://github.com/rancherlabs/tf-rancher-up.git//modules/infra/aws"
aws_region = "us-east-1"
prefix = "example-rancher"
instance_count = 1
create_ssh_key_pair = true
user_data = |
echo "hello world"
}
##### Option 1 - AWS CLI

```console
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=
export AWS_DEFAULT_OUTPUT=text
```

#### Provide an existing SSH key and Security Group
##### Option 2 - Manually creating credential files

```terraform
module "upstream_cluster" {
source = "git::https://github.com/rancherlabs/tf-rancher-up.git//modules/infra/aws"
aws_region = "us-east-1"
prefix = "example-rancher"
instance_count = 1
ssh_key_pair_name = "rancher-ssh"
instance_security_group = "sg-xxxxx"
}
```console
mkdir ~/.aws
```

#### Provide an existing VPC and Subnet
```console
cd ~/.aws
```

```console
cat > credentials << EOL
[default]
aws_access_key_id = <YOUR_ACCESS_KEY>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
EOL
```

```console
cat > config << EOL
[default]
region = <REGION>
output = text
EOL
```

##### Option 3 - IAM Identity Center credentials

```console
aws configure sso
```

```console
export AWS_PROFILE=<YOUR_CONFIG_PROFILE>
```

```terraform
module "upstream_cluster" {
source = "git::https://github.com/rancherlabs/tf-rancher-up.git//modules/infra/aws"
aws_region = "us-east-1"
prefix = "example-rancher"
instance_count = 1
vpc_id = "vpc-xxxxx"
subnet_id = "subnet-xxxxxx"
}
##### Verify credentials
```console
aws sts get-caller-identity
```
217 changes: 217 additions & 0 deletions modules/infra/aws/ec2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# Terraform | AWS EC2

Terraform modules to provide VM instances - AWS EC2.

Documentation can be found [here](./docs.md).

## Example

#### Launch three identical VM instances

```terraform
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.53.0"
}

ssh = {
source = "loafoe/ssh"
version = "2.6.0"
}

kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.0"
}

helm = {
source = "hashicorp/helm"
version = ">= 2.10.1"
}
}

required_version = ">= 0.14"
}

provider "aws" {
region = var.aws_region
}

variable "prefix" {}

variable "aws_region" {
type = string
description = "AWS region used for all resources"
default = "us-east-1"

validation {
condition = contains([
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ap-south-1",
"ap-northeast-3",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"ca-west-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-south-2",
"eu-north-1",
"eu-central-2",
"il-central-1",
"me-south-1",
"me-central-1",
"sa-east-1",
], var.aws_region)
error_message = "Invalid Region specified!"
}
}

variable "ssh_private_key_path" {
description = "The full path where is present the pre-generated SSH PRIVATE key (not generated by Terraform); if `create_ssh_key_pair = false` this variable must be set"
default = null
}

variable "vpc_id" {}

variable "subnet_id" {}

variable "instance_count" {}

variable "ssh_username" {}

module "aws-ec2-upstream-cluster" {
source = "git::https://github.com/rancher/tf-rancher-up.git//modules/infra/aws/ec2"
prefix = var.prefix
aws_region = var.aws_region
vpc_id = var.vpc_id
subnet_id = var.subnet_id
instance_count = var.instance_count
ssh_username = var.ssh_username
}

output "instances_public_ip" {
value = module.aws-ec2-upstream-cluster.instances_public_ip
}

output "instances_private_ip" {
value = module.aws-ec2-upstream-cluster.instances_private_ip
}
```

#### Launch two identical VM instances and a dedicated new VPC/Subnet

```terraform
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.53.0"
}

ssh = {
source = "loafoe/ssh"
version = "2.6.0"
}

kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.0"
}

helm = {
source = "hashicorp/helm"
version = ">= 2.10.1"
}
}

required_version = ">= 0.14"
}

provider "aws" {
region = var.aws_region
}

variable "prefix" {}

variable "aws_region" {
type = string
description = "AWS region used for all resources"
default = "us-east-1"

validation {
condition = contains([
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ap-south-1",
"ap-northeast-3",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"ca-west-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-south-2",
"eu-north-1",
"eu-central-2",
"il-central-1",
"me-south-1",
"me-central-1",
"sa-east-1",
], var.aws_region)
error_message = "Invalid Region specified!"
}
}

variable "ssh_private_key_path" {
description = "The full path where is present the pre-generated SSH PRIVATE key (not generated by Terraform); if `create_ssh_key_pair = false` this variable must be set"
default = null
}

variable "instance_count" {}

variable "ssh_username" {}

module "aws-ec2-upstream-cluster" {
source = "git::https://github.com/rancher/tf-rancher-up.git//modules/infra/aws/ec2"
prefix = var.prefix
aws_region = var.aws_region
instance_count = var.instance_count
ssh_username = var.ssh_username
}

output "instances_public_ip" {
value = module.aws-ec2-upstream-cluster.instances_public_ip
}

output "instances_private_ip" {
value = module.aws-ec2-upstream-cluster.instances_private_ip
}
```
2 changes: 2 additions & 0 deletions modules/infra/aws/data.tf → modules/infra/aws/ec2/data.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data "aws_availability_zones" "available" {}

# TODO: Make the Ubuntu OS version configurable
# TODO: Add support for ARM architecture
data "aws_ami" "ubuntu" {
Expand Down
Loading