Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After tfc #81

Open
wants to merge 39 commits into
base: after-tfc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
58d1b6f
Note about `after` and `after-byoaws` branches
topfunky Jan 24, 2018
124054e
Ensure that webapp starts on reboot
topfunky Jan 25, 2018
96d0046
Code for GCP Getting Started track on learn.hashicorp.com
topfunky Apr 19, 2019
1ca1422
Basic GCP example
topfunky Jun 15, 2019
26bbd54
Adds snippets for full tutorial
topfunky Jun 18, 2019
acd347f
Notes for reseting demo code and checking out after
topfunky Jun 18, 2019
0455c12
Reset GCP example to starting point
topfunky Jun 18, 2019
4b3b0be
Notes about switching to final GCP code branch
topfunky Jun 18, 2019
b3a87d0
Changes title of GCP tutorial
topfunky Jun 18, 2019
63a2688
Rename GCP demo to 'terraform-project'
topfunky Jun 18, 2019
c754ec6
Remove commands that use locally unzipped terraform executable
topfunky Jun 21, 2019
cd5e7c3
Beginning code for Terraform on Azure
topfunky Aug 19, 2019
6c8ddac
Update initial GCP example code
robin-norwood Aug 21, 2019
b848753
Correct version of main.tf
robin-norwood Aug 21, 2019
2276c7e
Add empty variables.tf
robin-norwood Aug 21, 2019
e46de3c
Add terraform.tfvars
robin-norwood Aug 21, 2019
9e88126
Add outputs.tf
robin-norwood Aug 21, 2019
39bc3dc
Ignore terraform.tfvars
topfunky Aug 21, 2019
6cce7c3
Merge pull request #31 from hashicorp/rn-update-gcp-example-master
topfunky Aug 21, 2019
0dbbdc2
Simple project for use with Terraform Cloud
topfunky Dec 4, 2019
dc91f22
Comment out Terraform config as starting point
topfunky Dec 4, 2019
b82af99
initial commit
Sep 8, 2021
f49e0d9
fixed typo
Sep 8, 2021
cacaf53
removed extra output
Sep 8, 2021
73eb71a
Merge branch 'before-tfc' into after-tfc
Sep 13, 2021
d35ace3
Update main.tf
matthewswwm Sep 13, 2021
27ac5f6
Update main.tf
matthewswwm Sep 13, 2021
ca69685
Merge pull request #2 from ecsd-matthew-song/ecsd-matthew-song-patch-1
matthewswwm Sep 13, 2021
7920df5
Update main.tf
matthewswwm Sep 14, 2021
1bcf4fc
cleanup
Sep 14, 2021
0463d3e
Fixed ami issue
Sep 14, 2021
7c2512e
Merge branch 'after-tfc' of github.com:ecsd-matthew-song/demo-terrafo…
Sep 14, 2021
664ab70
Added support for ipv6 from GitHubwq
Sep 16, 2021
0cb9aa8
Update main.tf
matthewswwm Jul 1, 2022
147163b
Update variables.tf
matthewswwm Jul 1, 2022
e6cfa8a
Update variables.tf
matthewswwm Jul 1, 2022
9606cf9
Update variables.tf
matthewswwm Jul 1, 2022
98e5f96
Update main.tf
matthewswwm Jul 5, 2022
dc8c9a9
Update main.tf
matthewswwm Jul 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions 05_multi-provider/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ provider "aws" {
data "github_ip_ranges" "test" {
}

data "aws_ami" "ubuntu_16_04" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}

owners = ["099720109477"]
}

resource "aws_security_group" "training" {
name_prefix = var.namespace

Expand All @@ -40,7 +51,8 @@ resource "aws_security_group" "training" {
protocol = "-1"

cidr_blocks = ["0.0.0.0/0"]
#cidr_blocks = data.github_ip_ranges.test.pages
#cidr_blocks = slice (data.github_ip_ranges.test.pages, 0, 5)
#ipv6_cidr_blocks = slice (data.github_ip_ranges.test.pages, 6, length(data.github_ip_ranges.test.pages))
}
}

Expand All @@ -50,7 +62,7 @@ resource "aws_key_pair" "training" {
}

resource "aws_instance" "example" {
ami = var.ami
ami = data.aws_ami.ubuntu_16_04.image_id
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.training.id]

Expand Down
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@

Before and after code for a _Terraform Introduction_ class.

## Terraform Cloud
## Branches

This branch is for use with a student's own AWS credentials and is intended to run on Terraform Cloud (but can also run locally).
See the `after` branch for the completed code from the class.

Major changes:

- A security group is created for SSH and HTTP
- The configuration only uses resources built by the configuration itself
- `public_key` and `private_key` should be provided as contents rather than a path to a file.
- AWS credentials should be provided as environment variables.

export AWS_ACCESS_KEY_ID="AAAA"
export AWS_SECRET_ACCESS_KEY="AAAA"
export AWS_DEFAULT_REGION="us-west-2"
See the `after-byoaws` branch for the completed code that can be run on a student's own AWS account (instead of on the instructor-created AWS account).
9 changes: 9 additions & 0 deletions getting-started/azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Getting Started with Terraform on Azure

This code accompanies the [Getting Started](https://learn.hashicorp.com/terraform/azure/intro_az) guide on [learn.hashicorp.com](https://learn.hashicorp.com/).

Check out the `after` branch for the final code.

```
$ git checkout after
```
4 changes: 4 additions & 0 deletions getting-started/azure/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Configure the provider
provider "azurerm" {
version = "=1.20.0"
}
3 changes: 3 additions & 0 deletions getting-started/gcp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform.tfvars
.terraform

9 changes: 9 additions & 0 deletions getting-started/gcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Getting Started with Terraform on Google Cloud Platform

This code accompanies the [Getting Started](https://learn.hashicorp.com/terraform/gcp/intro) guide on [learn.hashicorp.com](https://learn.hashicorp.com/).

Check out the `after` branch for the final code:

```shell
git checkout after
```
11 changes: 11 additions & 0 deletions getting-started/gcp/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider "google" {
credentials = file("<NAME>.json")

project = "<PROJECT_ID>"
region = "us-central1"
zone = "us-central1-c"
}

resource "google_compute_network" "vpc_network" {
name = "terraform-network"
}
1 change: 1 addition & 0 deletions getting-started/gcp/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Output definitions go here
1 change: 1 addition & 0 deletions getting-started/gcp/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Variable value assignments go here
1 change: 1 addition & 0 deletions getting-started/gcp/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Variable definitions go here
4 changes: 4 additions & 0 deletions getting-started/gcp/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
23 changes: 23 additions & 0 deletions getting-started/tfc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// terraform {
// backend "remote" {
// organization = "my-organization"
// workspaces {
// name = "random-pet-demo"
// }
// }
// }

variable "stage" {
default = "production"
}

resource "random_pet" "server" {
keepers = {
# Generate a new pet name each time we switch to a new stage
stage = "${var.stage}"
}
}

output "random_server_id" {
value = random_pet.server.id
}
15 changes: 14 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ terraform {
}

provider "aws" {
# MODIFY this line to look for 2.27.0 or greater
version = ">= 2.22.0"
}

data "aws_ami" "ubuntu_16_04" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}

owners = ["099720109477"]
}

module "server" {
source = "./server"

num_webs = var.num_webs
identity = var.identity
ami = var.ami
ami = data.aws_ami.ubuntu_16_04.image_id
ingress_cidr = var.ingress_cidr
public_key = var.public_key
private_key = var.private_key
Expand Down
1 change: 0 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ output "public_ip" {
output "public_dns" {
value = module.server.public_dns
}

23 changes: 9 additions & 14 deletions server/main.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
resource "aws_key_pair" "default" {
key_name = "${var.identity}-key"
public_key = var.public_key
#public_key = var.public_key
public_key = file("~/.ssh/id_rsa.pub")
}

resource "aws_security_group" "default" {
name_prefix = var.identity

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [var.ingress_cidr]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [var.ingress_cidr]
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
Expand Down Expand Up @@ -50,8 +44,10 @@ resource "aws_instance" "web" {
connection {
type = "ssh"
user = "ubuntu"
private_key = var.private_key
#private_key = var.private_key
private_key = file("~/.ssh/id_rsa")
host = self.public_ip
timeout = "1m"
}

provisioner "file" {
Expand All @@ -65,4 +61,3 @@ resource "aws_instance" "web" {
]
}
}

1 change: 0 additions & 1 deletion server/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ output "public_ip" {
output "public_dns" {
value = [aws_instance.web.*.public_dns]
}

1 change: 0 additions & 1 deletion server/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ variable "public_key" {
variable "private_key" {
description = "Contents of the private key used to connect to this instance"
}

18 changes: 7 additions & 11 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ variable "identity" {
description = "A unique name for your resources"
}

variable "ami" {
description = "The Amazon Machine Image for new instances."
default = "ami-c62eaabe"
}

variable "ingress_cidr" {
default = "0.0.0.0/0"
description = "IP block from which connections to this instance will be made"
}

variable "public_key" {
description = "Contents of the public key used to connect to this instance"
default = ""
}

variable "private_key" {
description = "Contents of the private key used to connect to this instance"
default = ""
}

variable "ingress_cidr" {
description = "IP block from which connections to this instance will be made"
default = "0.0.0.0/0"
}

variable "num_webs" {
description = "The number of servers to run"
default = "1"
}