Skip to content

Commit

Permalink
Feature: Terraform CI (#4)
Browse files Browse the repository at this point in the history
* add tf workflow

* update ci

* update exit command

* update return code

* update exit code

* fmt

* update readme
  • Loading branch information
guyzsarun authored Dec 17, 2023
1 parent fa4a899 commit 89c4946
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 26 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: terraform

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
workflow_dispatch:

jobs:
terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Init
run: terraform init

- name: Linting
run: |
if ! terraform fmt -recursive -check; then
echo 'Please run "terraform fmt -recursive" '
exit 1
fi
- name: Validate
run: terraform validate
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# terraform-aws
# terraform-aws
[![terraform](https://github.com/guyzsarun/terraform-aws/actions/workflows/main.yml/badge.svg)](https://github.com/guyzsarun/terraform-aws/actions/workflows/main.yml)
2 changes: 1 addition & 1 deletion bastion.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resource "aws_instance" "bastion-vm" {

subnet_id = aws_subnet.main-vpc-subnet-public[0].id

user_data = "${file("helper/init.sh")}"
user_data = file("helper/init.sh")

vpc_security_group_ids = [
aws_security_group.allow_ssh.id,
Expand Down
26 changes: 13 additions & 13 deletions eks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module "eks" {
cluster_version = var.eks-config.version

vpc_id = aws_vpc.main-vpc.id
subnet_ids = [ for i in aws_subnet.main-vpc-subnet-private : i.id]
subnet_ids = [for i in aws_subnet.main-vpc-subnet-private : i.id]

cluster_endpoint_public_access = true
eks_managed_node_groups = {
Expand Down Expand Up @@ -53,19 +53,19 @@ locals {
name = "terraform"
user = {
exec = {
apiVersion = "client.authentication.k8s.io/v1beta1"
command= "aws"
interactiveMode= "IfAvailable"
provideClusterInfo= false
apiVersion = "client.authentication.k8s.io/v1beta1"
command = "aws"
interactiveMode = "IfAvailable"
provideClusterInfo = false
args = [
"--region",
split(":",module.eks.cluster_arn)[3],
"eks",
"get-token",
"--cluster-name",
"${module.eks.cluster_name}",
"--output",
"json"
"--region",
split(":", module.eks.cluster_arn)[3],
"eks",
"get-token",
"--cluster-name",
"${module.eks.cluster_name}",
"--output",
"json"
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ output "private-vm" {

output "nat-gateway" {
value = {
public_ip = aws_nat_gateway.nat-gw.public_ip
public_ip = aws_nat_gateway.nat-gw.public_ip
private_ip = aws_nat_gateway.nat-gw.private_ip
}
}

output "eks"{
output "eks" {
value = {
cluster_name = module.eks.cluster_name
cluster_endpoint = module.eks.cluster_endpoint
cluster_name = module.eks.cluster_name
cluster_endpoint = module.eks.cluster_endpoint
get_kubeconfig_command = "aws eks update-kubeconfig --name ${module.eks.cluster_name}"
}
}
6 changes: 3 additions & 3 deletions security_group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ resource "aws_vpc_security_group_egress_rule" "allow_egress_rule_ipv6" {
}

resource "aws_network_acl" "main-vpc-nacl-public" {
vpc_id = aws_vpc.main-vpc.id
subnet_ids =[for i in aws_subnet.main-vpc-subnet-public : i.id]
vpc_id = aws_vpc.main-vpc.id
subnet_ids = [for i in aws_subnet.main-vpc-subnet-public : i.id]

egress {
protocol = -1
Expand All @@ -95,7 +95,7 @@ resource "aws_network_acl" "main-vpc-nacl-public" {
}

resource "aws_network_acl" "main-vpc-nacl-private" {
vpc_id = aws_vpc.main-vpc.id
vpc_id = aws_vpc.main-vpc.id
subnet_ids = [for i in aws_subnet.main-vpc-subnet-private : i.id]

egress {
Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ variable "ssh_key_pair" {

variable "eks-config" {
type = object({
name = string
version = string
name = string
version = string
min_node = number
max_node = number
})
Expand Down
4 changes: 2 additions & 2 deletions vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ resource "aws_route_table" "main-vpc-private-routetable" {
vpc_id = aws_vpc.main-vpc.id

route {
cidr_block = "0.0.0.0/0"
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat-gw.id
}

Expand Down Expand Up @@ -91,7 +91,7 @@ resource "aws_internet_gateway" "gw" {
}

resource "aws_eip" "nat" {
domain = "vpc"
domain = "vpc"
tags = {
Name = "nat"
}
Expand Down

0 comments on commit 89c4946

Please sign in to comment.