Created
April 13, 2018 21:23
-
-
Save tjsullivan1/5ed67d4043c23b10eec481767e35cb4d to your computer and use it in GitHub Desktop.
An example of tf-single-server
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
data "aws_vpc" "vpc_name" { | |
filter { | |
name = "tag:Name" | |
values = ["${var.vpc_level}-VPC"] | |
} | |
} | |
data "aws_subnet_ids" "selected" { | |
vpc_id = "${data.aws_vpc.vpc_name.id}" | |
tags { | |
Name = "*-${var.subnet_type}-*" | |
} | |
} | |
resource "random_shuffle" "subnet" { | |
input = ["${data.aws_subnet_ids.selected.ids}"] | |
result_count = 1 | |
} | |
resource "aws_instance" "instance" { | |
ami = "${var.ami}" | |
instance_type = "${var.instance_type}" | |
vpc_security_group_ids = ["${var.security_group_id}"] | |
key_name = "${var.key_name}" | |
associate_public_ip_address = "${var.assoc_public_ip}" | |
subnet_id = "${var.user_specified_subnet_id != "BadValue" ? var.user_specified_subnet_id : random_shuffle.subnet.result[0]}" | |
user_data = "${file("${var.user_data_script}")}" | |
iam_instance_profile = "${var.instance_role}" | |
tags { | |
"Name" = "${var.Name}" | |
"info:TaggingVersion" = "${var.infoTaggingVersion}" | |
"its:Provisioner" = "${var.itsProvisioner}" | |
"its:DataClassification" = "${var.itsDataClassification}" | |
"its:ServiceOwner" = "${var.itsServiceOwner}" | |
"its:SecurityReviewDate" = "${var.itsSecurityReviewDate}" | |
"its:SecurityReviewTicket" = "${var.itsSecurityReviewTicket}" | |
"CA001" = "${var.CA001}" | |
"CostCenter" = "${var.CostCenter}" | |
"Creator" = "${var.Creator}" | |
"Department" = "${var.Department}" | |
"Environment" = "${var.Environment}" | |
"Owner" = "${var.Owner}" | |
"Project" = "${var.Project}" | |
"Purpose" = "${var.Purpose}" | |
"Service" = "${var.Service}" | |
### Optional tags | |
"Application" = "${var.Application}" | |
"Company" = "${var.Company}" | |
"its:BackupSchedule" = "${var.itsBackupSchedule}" | |
"its:BuildID" = "${var.itsBuildID}" | |
"its:CmdbMapping" = "${var.itsCmdbMapping}" | |
"CA002" = "${var.CA002}" | |
"CA003" = "${var.CA003}" | |
"its:OperationalHours" = "${var.itsOperationalHours}" | |
"Role" = "${var.Role}" | |
"Status" = "${var.Status}" | |
"Use" = "${var.Use}" | |
} | |
} |
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
output "instance_id" { | |
value = "${aws_instance.instance.id}" | |
} | |
output "public_ip" { | |
value = "${aws_instance.instance.public_ip}" | |
} | |
output "private_ip" { | |
value = "${aws_instance.instance.private_ip}" | |
} |
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
variable "ami" { | |
description = "The AMI ID to use to build this instance" | |
} | |
variable "user_specified_subnet_id" { | |
description = "If the user wants to choose a specific subnet, they can use this in conjunction with the select_own_subnet boolean." | |
default = "BadValue" | |
} | |
variable "vpc_level" { | |
description = "Which VPC type should we be searching for?" | |
default = "Campus" | |
} | |
variable "subnet_type" { | |
description = "What type of subnet should this be (i.e., Public, Private, Campus)?" | |
} | |
variable "subnet_number" { | |
description = "The number for the subnet we want to place this resource in (1-3)" | |
default = "1" | |
} | |
variable "instance_type" { | |
description = "The type of EC2 Instances to run (e.g. t2.micro)" | |
default = "t2.micro" | |
} | |
variable "user_data_script" { | |
description = "The path to the file that contains our script for user data." | |
default = "user-data.sh" | |
} | |
variable "security_group_id" { | |
description = "The id of the security group to attach to this instance. Will accept a list..." | |
} | |
variable "key_name" { | |
description = "The name of the ssh key to use with this system." | |
} | |
variable "assoc_public_ip" { | |
description = "A boolean for whether or not to give this instance a public_ip" | |
} | |
variable "instance_role" { | |
description = "The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile." | |
default = "" | |
} | |
### TAGS | |
variable "infoTaggingVersion" { | |
# Example Value: v#.#.# | |
description = "Describes the version of this document to reference to understand tags." | |
default = "v2.0.0" | |
} | |
variable "itsBackupSchedule" { | |
# Example Value: Cron time, e.g. "0 20 * * MON-FRI" | |
description = "Future use: To be used for indicating when backup software should take a backup of this system or resource." | |
default = "" | |
} | |
variable "itsBuildID" { | |
# Example Value: v#.#.# | |
description = "Indicates the code version used to build the infrastructure." | |
default = "" | |
} | |
variable "itsCmdbMapping" { | |
# Example Value: URL of Twiki/SharePoint/etc. Documentation | |
description = "Points to documentation related to this resource/service" | |
default = "" | |
} | |
variable "itsProvisioner" { | |
# Example Value: Manual/Managed by %TOOL% | |
description = "Indicates where an admin can look for more information about how/where this was built." | |
default = "Managed by Terraform" | |
} | |
variable "itsOperationalHours" { | |
# Example Value: Cron time, e.g. "* * * * *" | |
description = "Future use: To be used for indicating auto on/off for this resource." | |
default = "" | |
} | |
variable "itsDataClassification" { | |
# Example Value: Red/Yellow/Green | |
description = "This indicates the level of security controls necessary around this resource" | |
} | |
variable "itsServiceOwner" { | |
# Example Value: The email address of the ITS Service Owner | |
description = "This is who an ITS admin can contact for questions re: the service" | |
} | |
variable "itsSecurityReviewDate" { | |
# Example Value: ISO 8601 Date, basic format, e.g., "20180206" | |
description = "This relates the most recent security review date for us to be able to automate security reviews" | |
default = "NEEDSTOBECONDUCTED" | |
} | |
variable "itsSecurityReviewTicket" { | |
# Example Value: WHD Ticket # | |
description = "This is the documented reference information for the security review" | |
default = "NEEDSTOBECONDUCTED" | |
} | |
variable "Application" { | |
# Example Value: The application that this resource runs | |
description = "Allows us to show in billing how much applications are costing us" | |
default = "" | |
} | |
variable "Company" { | |
# Example Value: The vendor of the application | |
description = "Allows us to show in billing how much certain vendors are costing us, as well as tracking which vendor resources are deployed to the cloud for compliance" | |
default = "" | |
} | |
variable "CA001" { | |
# Example Value: General ledger code specifying what type of use this is? Should be 5 digits. Likely 74166 (cloud hosting) | |
description = "The code that indicates to our budget people how this is billed." | |
default = "74166" | |
} | |
variable "CA002" { | |
# Example Value: Expiry date - i.e., date a resource can be deleted, ISO 8601 basic format formatted: 20160206T2345 | |
description = "For cleanup purposes." | |
default = "" | |
} | |
variable "CA003" { | |
# Example Value: Workload Criticality - High/Medium/Low | |
description = "Describes priority if major incident across multiple resources for bringing back online" | |
default = "" | |
} | |
variable "CostCenter" { | |
# Example Value: The departmental budget code for this resource. This should be 5 digits. | |
description = "This code indicates who is paying for this resource. Used for cost allocation at monthly billing meetings." | |
} | |
variable "Creator" { | |
# Example Value: The email address of the user who created this resource. | |
description = "This indicates who should know the purpose behind this resource. " | |
} | |
variable "Department" { | |
# Example Value: The business department friendly name. | |
description = "This is useful if the Business Owner switches departments and we are not notified of the new owner. We can then go back to that department for more info." | |
} | |
variable "Environment" { | |
# Example Value: DEV/TEST/PROD | |
description = "Clear indicator of which environment this resource is intended to be in." | |
} | |
variable "Name" { | |
# Example Value: Friendly System or Resource Name | |
description = "Admin friendly name to refer to a service (like scripthost1)" | |
} | |
variable "Owner" { | |
# Example Value: The email address of the non-ITS service owner | |
description = "This is who an ITS admin can contact for questions re: changes to this system or for a business decision." | |
} | |
variable "Project" { | |
# Example Value: WHD Ticket #, Project #, or RFC # for provisioning of this resource | |
description = "Indicates where someone can look for why this resource was built." | |
} | |
variable "Purpose" { | |
# Example Value: Why was this resource created? | |
description = "Can provide explanations for pieces of architecture" | |
} | |
variable "Role" { | |
# Example Value: Web, app, database, proxy | |
description = "Describes the roles of this system within the service ecosystem." | |
default = "" | |
} | |
variable "Service" { | |
# Example Value: The name of the service for which this resource is provisioned. | |
description = "This will help us to develop architectural, cost, and documentation models surroudning this service" | |
} | |
variable "Status" { | |
# Example Value: Pilot, Emerging Technology, In Production, Deprecated, Unsupported | |
description = "Describes the lifecycle phase of the resource." | |
default = "" | |
} | |
variable "Use" { | |
# Example Value: Faculty/Staff/Student/Courtesy/All UST/External | |
description = "Describes the users of this system " | |
default = "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment