-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some Terraform native examples (#325)
- AWS s3 exmples - Backend examples Signed-off-by: Zheng Xi Zhou <[email protected]>
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
resource "aws_s3_bucket" "bucket-acl" { | ||
bucket = var.bucket | ||
acl = var.acl | ||
} | ||
|
||
output "RESOURCE_IDENTIFIER" { | ||
description = "The identifier of the resource" | ||
value = aws_s3_bucket.bucket-acl.bucket_domain_name | ||
} | ||
|
||
output "BUCKET_NAME" { | ||
value = aws_s3_bucket.bucket-acl.bucket_domain_name | ||
description = "The name of the S3 bucket" | ||
} | ||
|
||
variable "bucket" { | ||
description = "S3 bucket name" | ||
default = "vela-website-2022-0614" | ||
type = string | ||
} | ||
|
||
variable "acl" { | ||
description = "S3 bucket ACL" | ||
default = "private" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#vAWS VPC | ||
|
||
Based on the Terraform template in https://github.com/terraform-aws-modules/terraform-aws-vpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
resource "aws_vpc" "this" { | ||
count = var.create_vpc ? 1 : 0 | ||
|
||
cidr_block = var.cidr | ||
instance_tenancy = var.instance_tenancy | ||
enable_dns_hostnames = var.enable_dns_hostnames | ||
enable_dns_support = var.enable_dns_support | ||
enable_classiclink = var.enable_classiclink | ||
enable_classiclink_dns_support = var.enable_classiclink_dns_support | ||
assign_generated_ipv6_cidr_block = var.enable_ipv6 | ||
|
||
tags = merge( | ||
{ "Name" = var.name }, | ||
var.tags, | ||
var.vpc_tags, | ||
) | ||
} | ||
|
||
output "vpc_id" { | ||
description = "The ID of the VPC" | ||
value = try(aws_vpc.this[0].id, "") | ||
} | ||
|
||
output "vpc_arn" { | ||
description = "The ARN of the VPC" | ||
value = try(aws_vpc.this[0].arn, "") | ||
} | ||
|
||
output "vpc_cidr_block" { | ||
description = "The CIDR block of the VPC" | ||
value = try(aws_vpc.this[0].cidr_block, "") | ||
} | ||
|
||
output "default_security_group_id" { | ||
description = "The ID of the security group created by default on VPC creation" | ||
value = try(aws_vpc.this[0].default_security_group_id, "") | ||
} | ||
|
||
output "default_network_acl_id" { | ||
description = "The ID of the default network ACL" | ||
value = try(aws_vpc.this[0].default_network_acl_id, "") | ||
} | ||
|
||
output "default_route_table_id" { | ||
description = "The ID of the default route table" | ||
value = try(aws_vpc.this[0].default_route_table_id, "") | ||
} | ||
|
||
output "vpc_instance_tenancy" { | ||
description = "Tenancy of instances spin up within VPC" | ||
value = try(aws_vpc.this[0].instance_tenancy, "") | ||
} | ||
|
||
output "vpc_enable_dns_support" { | ||
description = "Whether or not the VPC has DNS support" | ||
value = try(aws_vpc.this[0].enable_dns_support, "") | ||
} | ||
|
||
output "vpc_enable_dns_hostnames" { | ||
description = "Whether or not the VPC has DNS hostname support" | ||
value = try(aws_vpc.this[0].enable_dns_hostnames, "") | ||
} | ||
|
||
output "vpc_main_route_table_id" { | ||
description = "The ID of the main route table associated with this VPC" | ||
value = try(aws_vpc.this[0].main_route_table_id, "") | ||
} | ||
|
||
output "vpc_ipv6_association_id" { | ||
description = "The association ID for the IPv6 CIDR block" | ||
value = try(aws_vpc.this[0].ipv6_association_id, "") | ||
} | ||
|
||
output "vpc_ipv6_cidr_block" { | ||
description = "The IPv6 CIDR block" | ||
value = try(aws_vpc.this[0].ipv6_cidr_block, "") | ||
} | ||
|
||
output "vpc_owner_id" { | ||
description = "The ID of the AWS account that owns the VPC" | ||
value = try(aws_vpc.this[0].owner_id, "") | ||
} | ||
|
||
|
||
output "name" { | ||
description = "The name of the VPC specified as argument to this module" | ||
value = var.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
variable "create_vpc" { | ||
description = "Controls if VPC should be created (it affects almost all resources)" | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "name" { | ||
description = "Name to be used on all the resources as identifier" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "cidr" { | ||
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden" | ||
type = string | ||
default = "10.0.0.0/16" | ||
} | ||
|
||
variable "enable_ipv6" { | ||
description = "Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block." | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "instance_tenancy" { | ||
description = "A tenancy option for instances launched into the VPC" | ||
type = string | ||
default = "default" | ||
} | ||
|
||
variable "enable_dns_hostnames" { | ||
description = "Should be true to enable DNS hostnames in the VPC" | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "enable_dns_support" { | ||
description = "Should be true to enable DNS support in the VPC" | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "enable_classiclink" { | ||
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic." | ||
type = bool | ||
default = null | ||
} | ||
|
||
variable "enable_classiclink_dns_support" { | ||
description = "Should be true to enable ClassicLink DNS Support for the VPC. Only valid in regions and accounts that support EC2 Classic." | ||
type = bool | ||
default = null | ||
} | ||
|
||
variable "tags" { | ||
description = "A map of tags to add to all resources" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "vpc_tags" { | ||
description = "Additional tags for the VPC" | ||
type = map(string) | ||
default = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
terraform { | ||
backend "s3" { | ||
bucket = "tf-state-poc-0608" | ||
key = "sss" | ||
region = "us-east-1" | ||
} | ||
} | ||
|
||
|
||
resource "random_id" "server" { | ||
byte_length = 8 | ||
} | ||
|
||
output "random_id" { | ||
value = random_id.server.hex | ||
} |