Skip to content

Commit

Permalink
fix: added versions.tf and updated vpc tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mamrajyadav committed Jun 6, 2023
1 parent 514723c commit b045221
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 114 deletions.
26 changes: 6 additions & 20 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,27 @@ on:
types: [labeled]

jobs:
terraform:
name: 'Terraform'
Terratest:
name: 'terratest'
runs-on: ubuntu-latest
steps:

- name: 'Checkout'
uses: actions/checkout@master
uses: actions/checkout@v2.3.4

- name: Configure AWS Credentials
- name: 'Configure AWS Credentials'
uses: clouddrove/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }}
aws-region: us-east-2

- name: 'Terratest'
if: ${{ github.event.label.name == 'terratest' }}
- name: 'terratest'
uses: 'clouddrove/github-actions@v9.0.2'
with:
actions_subcommand: 'terratest'
if: ${{ github.event.label.name == 'terratest' }}
tf_actions_working_dir: '_test'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 'Slack Notification'
uses: clouddrove/action-slack@v2
with:
status: ${{ job.status }}
fields: repo,author
author_name: 'CloudDrove'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required
if: always()


- name: 'Slack Notification'
uses: clouddrove/action-slack@v2
Expand Down
15 changes: 9 additions & 6 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ usage: |-
```hcl
module "vpn" {
source = "clouddrove/vpn/aws"
version = "1.0.1"
name = "vpn"
environment = "test"
label_order = ["environment", "name"]
vpc_id = "vpc-xxxxxxxxxx"
customer_ip_address = "115.160.246.74"
version = "1.0.4"
name = "vpn"
environment = "Dev"
label_order = ["environment", "name"]
vpc_id = module.vpc.vpc_id
customer_ip_address = "115.160.246.74"
local_ipv4_network_cidr = "0.0.0.0/0"
remote_ipv4_network_cidr = "0.0.0.0/0"
}
```
17 changes: 14 additions & 3 deletions _example/example.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
##----------------------------------------------------------------------------------
## Provider block added, Use the Amazon Web Services (AWS) provider to interact with the many resources supported by AWS.
##----------------------------------------------------------------------------------
provider "aws" {
region = "eu-west-1"
}

##-----------------------------------------------------------------------------
## A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
##-----------------------------------------------------------------------------
module "vpc" {
source = "clouddrove/vpc/aws"
version = "1.3.0"
source = "clouddrove/vpc/aws"
version = "1.3.1"
name = "vpc"
environment = "Dev"
label_order = ["name", "environment"]

cidr_block = "172.16.0.0/16"
}

##-----------------------------------------------------
## A subnet is a range of IP addresses in your VPC.
##-----------------------------------------------------
module "public_subnets" {
source = "clouddrove/subnet/aws"
version = "1.3.0"
Expand All @@ -28,7 +37,9 @@ module "public_subnets" {
ipv6_cidr_block = module.vpc.ipv6_cidr_block
}


##-----------------------------------------------------------------------------
## vpn module call.
##-----------------------------------------------------------------------------
module "vpn" {
source = "./../"

Expand Down
79 changes: 39 additions & 40 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Managed By : CloudDrove
# Description : This Script is used to create VPN, CUSTOMER GATEWAY, and VPN GATEWAY.
# Copyright @ CloudDrove. All Right Reserved.


#Module : labels
#Description : This terraform module is designed to generate consistent labels names and
# tags for resources. You can use terraform-labels to implement a strict
# naming convention.
##-----------------------------------------------------------------------------
## Labels module callled that will be used for naming and tags.
##-----------------------------------------------------------------------------
module "labels" {
source = "clouddrove/labels/aws"
version = "1.3.0"
Expand All @@ -17,6 +11,7 @@ module "labels" {
managedby = var.managedby
}


locals {
preshared_key_provided = length(var.tunnel1_preshared_key) > 0 && length(var.tunnel2_preshared_key) > 0
preshared_key_not_provided = false == local.preshared_key_provided
Expand All @@ -28,59 +23,62 @@ locals {
enable_tunner_with_preshared_key_only = local.internal_cidr_not_provided && local.preshared_key_provided
}

#Module VPN Connection
#Description: Manages an EC2 VPN connection. These objects can be connected to customer gateways,
# and allow you to establish tunnels between your network and Amazon
##-----------------------------------------------------------------------------
## aws_vpn_connection. Manages a Site-to-Site VPN connection.
##-----------------------------------------------------------------------------
resource "aws_vpn_connection" "default" {
count = var.enable_vpn_connection && local.tunnel_details_not_specified ? 1 : 0

vpn_gateway_id = join("", aws_vpn_gateway.vpn.*.id)
customer_gateway_id = join("", aws_customer_gateway.main.*.id)
type = "ipsec.1"
static_routes_only = var.vpn_connection_static_routes_only
local_ipv4_network_cidr = var.local_ipv4_network_cidr
remote_ipv4_network_cidr = var.remote_ipv4_network_cidr
tunnel1_dpd_timeout_action = var.tunnel1_dpd_timeout_action
tunnel1_preshared_key = var.tunnel1_preshared_key
tunnel1_startup_action = var.tunnel1_startup_action
vpn_gateway_id = join("", aws_vpn_gateway.vpn.*.id)
customer_gateway_id = join("", aws_customer_gateway.main.*.id)
type = "ipsec.1"
static_routes_only = var.vpn_connection_static_routes_only
local_ipv4_network_cidr = var.local_ipv4_network_cidr
remote_ipv4_network_cidr = var.remote_ipv4_network_cidr
tunnel1_dpd_timeout_action = var.tunnel1_dpd_timeout_action
tunnel1_preshared_key = var.tunnel1_preshared_key
tunnel1_startup_action = var.tunnel1_startup_action
tunnel1_phase1_encryption_algorithms = var.tunnel1_phase1_encryption_algorithms
tunnel1_phase2_encryption_algorithms = var.tunnel1_phase2_encryption_algorithms
tunnel1_phase1_integrity_algorithms = var.tunnel1_phase1_integrity_algorithms
tunnel1_phase2_integrity_algorithms = var.tunnel1_phase2_integrity_algorithms
tunnel1_phase1_dh_group_numbers = var.tunnel1_phase1_dh_group_numbers
tunnel1_phase2_dh_group_numbers = var.tunnel1_phase2_dh_group_numbers
tunnel1_ike_versions = var.tunnel1_ike_versions
tunnel1_inside_cidr = var.tunnel1_inside_cidr
tags = module.labels.tags
tunnel1_phase2_encryption_algorithms = var.tunnel1_phase2_encryption_algorithms
tunnel1_phase1_integrity_algorithms = var.tunnel1_phase1_integrity_algorithms
tunnel1_phase2_integrity_algorithms = var.tunnel1_phase2_integrity_algorithms
tunnel1_phase1_dh_group_numbers = var.tunnel1_phase1_dh_group_numbers
tunnel1_phase2_dh_group_numbers = var.tunnel1_phase2_dh_group_numbers
tunnel1_ike_versions = var.tunnel1_ike_versions
# tunnel1_inside_cidr = var.tunnel1_inside_cidr
tags = module.labels.tags
}

#Module Gateway Attachment
#Description: Provides a Virtual Private Gateway attachment resource,
# allowing for an existing hardware VPN gateway to be attached and/or detached from a VPC.
##-----------------------------------------------------------------------------
## Provides a Virtual Private Gateway attachment resource, allowing for an existing hardware VPN gateway to be attached and/or detached from a VPC
##-----------------------------------------------------------------------------
resource "aws_vpn_gateway_attachment" "default" {
count = var.enable_vpn_connection && var.enable_vpn_gateway_attachment ? 1 : 0
vpc_id = var.vpc_id
vpn_gateway_id = join("", aws_vpn_gateway.vpn.*.id)
}

#Module Gateway Route Propagation
#Description: Requests automatic route propagation between a VPN gateway and a route table.
##-----------------------------------------------------------------------------
## Requests automatic route propagation between a VPN gateway and a route table.
##-----------------------------------------------------------------------------
resource "aws_vpn_gateway_route_propagation" "private_subnets_vpn_routing" {
count = var.enable_vpn_connection ? var.vpc_subnet_route_table_count : 0
vpn_gateway_id = join("", aws_vpn_gateway.vpn.*.id)
route_table_id = element(var.vpc_subnet_route_table_ids, count.index)
}

#Module Connection Route
#Description: Provides a static route between a VPN connection and a customer gateway.
##-----------------------------------------------------------------------------
## Provides a static route between a VPN connection and a customer gateway.
##-----------------------------------------------------------------------------
resource "aws_vpn_connection_route" "default" {
count = var.enable_vpn_connection ? var.vpn_connection_static_routes_only ? length(var.vpn_connection_static_routes_destinations) : 0 : 0
vpn_connection_id = element(split("", join("", aws_vpn_connection.default.*.id)), 0)
destination_cidr_block = element(var.vpn_connection_static_routes_destinations, count.index)
}

#Module Aws Customer Gateway
#Description: Provides a customer gateway inside a VPC
##-----------------------------------------------------------------------------
## Provides a customer gateway inside a VPC. These objects can be connected to VPN gateways via VPN connections, and allow you to establish tunnels between your network and the VPC.
##-----------------------------------------------------------------------------
resource "aws_customer_gateway" "main" {
count = var.enable_vpn_connection && var.enable_vpn_gateway_attachment ? 1 : 0
bgp_asn = 65000
Expand All @@ -95,8 +93,9 @@ resource "aws_customer_gateway" "main" {
)
}

#Module AWS VPN Gateway
#Description: Provides a resource to enable a VPC VPN Gateway.
##-----------------------------------------------------------------------------
## VPN gateways provide secure connectivity between multiple sites, such as on-premises data centers, Google Cloud Virtual Private Cloud (VPC) networks, and Google Cloud VMware Engine private clouds.
##-----------------------------------------------------------------------------
resource "aws_vpn_gateway" "vpn" {
count = var.enable_vpn_connection && var.enable_vpn_gateway_attachment ? 1 : 0
tags = merge(
Expand Down
Loading

0 comments on commit b045221

Please sign in to comment.