This repository was archived by the owner on Jul 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 11 files changed +149
-3
lines changed Expand file tree Collapse file tree 11 files changed +149
-3
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ variable "cidr_blocks" {
17
17
type = list (string )
18
18
}
19
19
20
+ variable "ipv6_cidr_blocks" {
21
+ description = " List of IPv6 CIDR block ranges that the SG allows ingress from"
22
+ type = list (string )
23
+ default = []
24
+ }
25
+
20
26
variable "description" {
21
27
description = " Use this string to add a description for the SG rule"
22
28
type = string
@@ -53,6 +59,7 @@ resource "aws_security_group_rule" "tcp_ingress" {
53
59
to_port = var. port
54
60
protocol = " tcp"
55
61
cidr_blocks = var. cidr_blocks
62
+ ipv6_cidr_blocks = var. ipv6_cidr_blocks
56
63
security_group_id = var. security_group_id
57
64
}
58
65
@@ -65,5 +72,6 @@ resource "aws_security_group_rule" "udp_ingress" {
65
72
to_port = var. port
66
73
protocol = " udp"
67
74
cidr_blocks = var. cidr_blocks
75
+ ipv6_cidr_blocks = var. ipv6_cidr_blocks
68
76
security_group_id = var. security_group_id
69
77
}
Original file line number Diff line number Diff line change
1
+ ## AWS Subnets
2
+
3
+ This module creates one or more subnets, interleaving them across a list of
4
+ availiability zones, supports ` extra_tags ` , and enabling/disabling public
5
+ IPs by default. Use this module multiple times to create different sets of
6
+ subnets for different purposes or characteristics.
Original file line number Diff line number Diff line change
1
+ /* *
2
+ * ## AWS Subnet IPv6
3
+ * Creates a single IPv6 ready subnet
4
+ *
5
+ */
6
+
7
+ resource "aws_subnet" "main" {
8
+ vpc_id = var. vpc_id
9
+ cidr_block = var. cidr_block
10
+ ipv6_cidr_block = cidrsubnet (var. vpc_ipv6_cidr_block , var. ipv6_newbits , var. ipv6_netsum )
11
+ availability_zone = var. az
12
+
13
+ tags = merge (
14
+ {
15
+ " Name" = " ${ var . name_prefix } -${ var . az } "
16
+ },
17
+ var. extra_tags ,
18
+ )
19
+
20
+ map_public_ip_on_launch = var. public
21
+ assign_ipv6_address_on_creation = true
22
+ }
Original file line number Diff line number Diff line change
1
+ output "id" {
2
+ description = " The subnet id"
3
+ value = aws_subnet. main . id
4
+ }
5
+
6
+ output "cidr_block" {
7
+ description = " The IPv4 CIDR block"
8
+ value = aws_subnet. main . cidr_block
9
+ }
10
+
11
+ output "ipv6_cidr_block" {
12
+ description = " The IPv6 CIDR block"
13
+ value = aws_subnet. main . ipv6_cidr_block
14
+ }
15
+
16
+ output "az" {
17
+ value = aws_subnet. main . availability_zone
18
+ description = " The availability zones of the subnet"
19
+ }
20
+
21
+ output "vpc_id" {
22
+ description = " ID of the VPC the subnet is in"
23
+ value = var. vpc_id
24
+ }
25
+
Original file line number Diff line number Diff line change
1
+ variable "name_prefix" {
2
+ description = " Name to prefix subnets with"
3
+ type = string
4
+ }
5
+
6
+ variable "vpc_id" {
7
+ description = " VPC ID where subnets will be created"
8
+ type = string
9
+ }
10
+
11
+ variable "cidr_block" {
12
+ description = " The IPv4 CIDR block for the subnet"
13
+ type = string
14
+ }
15
+
16
+ variable "az" {
17
+ description = " The Availaiblity Zones to create the subnet in"
18
+ type = string
19
+ }
20
+
21
+ variable "extra_tags" {
22
+ default = {}
23
+ description = " Extra tags that will be added to aws_subnet resources"
24
+ type = map (string )
25
+ }
26
+
27
+ # default to creating a public subnet
28
+ variable "public" {
29
+ default = true
30
+ description = " Boolean, maps to the map_public_ip_on_launch variable"
31
+ type = bool
32
+ }
33
+
34
+ variable "vpc_ipv6_cidr_block" {
35
+ description = " The IPv6 cidr block for the vpc"
36
+ type = string
37
+ }
38
+
39
+ variable "ipv6_newbits" {
40
+ description = " The number of additional bits with which to extend the prefix"
41
+ type = number
42
+ default = 8
43
+ }
44
+
45
+ variable "ipv6_netsum" {
46
+ description = " a whole number that can be represented as a binary integer with no more than newbits binary digits"
47
+ type = number
48
+ default = 162
49
+ }
Original file line number Diff line number Diff line change
1
+
2
+ terraform {
3
+ required_version = " >= 0.12"
4
+ }
Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ resource "aws_subnet" "main" {
18
18
" Name" = " ${ var . name_prefix } -${ format (" %02d" , count. index + 1 )} -${ element (var. azs , count. index )} "
19
19
},
20
20
var. extra_tags ,
21
- )
21
+ )
22
22
map_public_ip_on_launch = var. public
23
23
}
24
-
Original file line number Diff line number Diff line change @@ -28,6 +28,23 @@ variable "extra_tags" {
28
28
variable "public" {
29
29
default = true
30
30
description = " Boolean, maps to the map_public_ip_on_launch variable"
31
- type = string # no boolean type...
31
+ type = bool
32
32
}
33
33
34
+ variable "assign_ipv6_address_on_creation" {
35
+ description = " Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false"
36
+ type = bool
37
+ default = false
38
+ }
39
+
40
+ variable "vpc_ipv6_cidr_block" {
41
+ description = " The possible ipv6 cidr block for the vpc"
42
+ type = string
43
+ default = " "
44
+ }
45
+
46
+ # variable "ipv6_cidr_blocks" {
47
+ # description = "The optional ipv6 cidr blocks for the subnet"
48
+ # type = list(string)
49
+ # default = []
50
+ # }
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ resource "aws_vpc" "main" {
16
16
enable_dns_hostnames = var. enable_dns_hostnames
17
17
enable_dns_support = var. enable_dns_support
18
18
19
+ assign_generated_ipv6_cidr_block = var. assign_generated_ipv6_cidr_block
20
+
19
21
tags = merge (
20
22
{
21
23
" Name" = var.name_prefix
Original file line number Diff line number Diff line change @@ -13,3 +13,10 @@ output "dhcp_options_id" {
13
13
description = " ID of the DHCP options resource"
14
14
}
15
15
16
+ # It would be great if Terraform had an Option or Maybe type
17
+ # Otherwise this will output an empty default value if the IPv6 option is not
18
+ # set to true
19
+ output "ipv6_cidr_block" {
20
+ value = (var. assign_generated_ipv6_cidr_block ? aws_vpc. main . ipv6_cidr_block : " " )
21
+ description = " Optional IPv6 CIDR block output for the VPC"
22
+ }
You can’t perform that action at this time.
0 commit comments