Coder Social home page Coder Social logo

wardviaene / terraform-course Goto Github PK

View Code? Open in Web Editor NEW
1.6K 125.0 4.0K 202 KB

Course files for my Udemy course about Terraform

Home Page: https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/?couponCode=TERRAFORM_GIT

HCL 93.14% Shell 5.48% Smarty 0.42% Go 0.96%

terraform-course's Introduction

terraform-course

Compatibility

  • This is the >=terraform-0.12 branch. For compatibility with older versions, use the terraform-0.11 branch.

Demo overview

Demo Directory Description
first-steps First steps
demo-1 First steps: Launching an EC2 instance
demo-2 Using provisioner
demo-2b Using provisioner on a Windows instance
demo-3 Executing script locally
demo-4 Outputting
demo-5 Data Source
demo-6 Modules
demo-7 AWS VPC
demo-8 EC2 instance within VPC with securitygroup
demo-9 EC2 instance with EBS volumes
demo-10 Userdata and cloudinit
demo-11 Route53 (DNS)
demo-12 RDS
demo-13 IAM
demo-14 IAM Roles with S3 bucket
demo-15 Autoscaling
demo-16 Autoscaling with ELB (Elastic Load Balancer)
demo-17 Elastic Beanstalk PHP 7 stack with RDS
demo-18 Interpolations, VPC module
demo-18b Project structure, best practices
packer-demo Build AMIs with Packer
jenkins-packer-demo Demo with jenkins and Packer
docker-demo-1 Using ECR - The EC2 Container Registry
docker-demo-2 Using ECS - The EC2 Container Service
docker-demo-3 Using ECR/ECS with Jenkins in a complete workflow
module-demo Using ECS + ALB in 4 modules to show how developing terraform modules work

terraform-course's People

Contributors

atatevyan avatar carlosacchi avatar hiteshsai avatar jaypan13 avatar jornjambers avatar jsauni avatar kewalaka avatar refayathaque avatar tmravic avatar wardviaene avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-course's Issues

I can't see node groups under eks console UI

I have used eks-demo but Not able to see node groups under eks>compute section, Please can anyone suggest what should I do to see node groups under compute tab/section just by running terraform.

image

I am getting this issue while dong demo-2: Warning: Interpolation-only expressions are deprecated

I am getting Warning: Interpolation-only expressions are deprecated issue whle implementing the demp-2. It sounds it provisioned the ec2, but can not login. it complaint not finding the private key file.

This is what is in vars file

variable "PATH_TO_PRIVATE_KEY" {
default = "mykey"
}

There is a file called mykey in the same folder

in instance config file,
connection {
host = coalesce(self.public_ip, self.private_ip)
type = "ssh"
user = var.INSTANCE_USERNAME
private_key =file(var.PATH_TO_PRIVATE_KEY)
}

I also tried
connection {
host = coalesce(self.public_ip, self.private_ip)
type = "ssh"
user = var.INSTANCE_USERNAME
private_key = "${file(var.PATH_TO_PRIVATE_KEY)}"
}

But when I use same ppk and login from putty, it works. so not ppk issue. not sure why it does not find the file.

Error while using public and private keys to connect to AWS

I am seeing following error, when terraform is trying to use private key to connect to instances in AWS. Please advise.

$ terraform plan

Error: aws_instance.example: 1 error(s) occurred:

  • aws_instance.example: file: open MyKey: no such file or directory in:

${file("${var.path_to_private_key}")}

Here is the snippet from instance.tf which is executing:
resource "aws_key_pair" "mykey" {
key_name = "MyKey"
public_key = "${file("${var.path_to_public_key}")}"
}

resource "aws_instance" "example" {
ami = "${lookup(var.amis,var.region)}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.mykey.key_name}"
tags {
Name = "${var.instance_tag}"
}
provisioner "file" {
source = "script.sh"
destination = "/tmp/script.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/script.sh",
"sudo /tmp/script.sh"
]
}
connection {
user = "${var.instance_username}"
private_key = "${file("${var.path_to_private_key}")}"
}
}

And variables.tf:
variable "path_to_public_key" {
description = "Path to public key"
default = "MyKey.pub"
}

variable "path_to_private_key" {
description = "Path to private key"
default = "MyKey"
}

demo-2 issue

Helllo,

I am going through your udemy course and and geeting below error for demo-2. Can you please suggest.

I am installing amazon linux.

aws_key_pair.mykey: Creating...
aws_key_pair.mykey: Creation complete after 1s [id=mykey]
aws_instance.example: Creating...
aws_instance.example: Still creating... [10s elapsed]
aws_instance.example: Still creating... [20s elapsed]
aws_instance.example: Still creating... [30s elapsed]

Error: Error in function call: Call to function "file" failed: no file exists at mykey.

ERROR executing Demo-1

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_instance.example will be created
  + resource "aws_instance" "example" {
      + ami                          = "ami-06b94666"
      + arn                          = (known after apply)
      + associate_public_ip_address  = (known after apply)
      + availability_zone            = (known after apply)
      + cpu_core_count               = (known after apply)
      + cpu_threads_per_core         = (known after apply)
      + get_password_data            = false
      + host_id                      = (known after apply)
      + id                           = (known after apply)
      + instance_state               = (known after apply)
      + instance_type                = "t2.micro"
      + ipv6_address_count           = (known after apply)
      + ipv6_addresses               = (known after apply)
      + key_name                     = (known after apply)
      + network_interface_id         = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      + primary_network_interface_id = (known after apply)
      + private_dns                  = (known after apply)
      + private_ip                   = (known after apply)
      + public_dns                   = (known after apply)
      + public_ip                    = (known after apply)
      + security_groups              = (known after apply)
      + source_dest_check            = true
      + subnet_id                    = (known after apply)
      + tenancy                      = (known after apply)
      + volume_tags                  = (known after apply)
      + vpc_security_group_ids       = (known after apply)

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }

      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)
        }

      + root_block_device {
          + delete_on_termination = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_instance.example: Creating...

Error: Error launching source instance: UnauthorizedOperation: You are not authorized to perform this operation. Encoded authorization failure message: aksjfhalsfncalkshjasjdfalsdhfaljsdflsisomerandomshit

status code: 403, request id: da12aa68-9933-4705-9915-5a0db00ae25a

  on instance.tf line 1, in resource "aws_instance" "example":
   1: resource "aws_instance" "example" {

the user i am using has Administrator access. Still, i am getting this error. What's the issue?

eks-demo

Hi Edward,

eks-demo encountering bellow errors when I am trying to run terraform apply. Kindly take a look into it.

[root@linux01 eks-demo]# terraform apply

Error: Unsupported block type

on securitygroups.tf line 13, in resource "aws_security_group" "demo-cluster":
13: tags {

Blocks of type "tags" are not expected here. Did you mean to define argument
"tags"? If so, use the equals sign to assign it a value.

Error: Missing resource instance key

on .terraform/modules/vpc/terraform-aws-modules-terraform-aws-vpc-d723605/main.tf line 31, in resource "aws_vpc_ipv4_cidr_block_association" "this":
31: vpc_id = "${aws_vpc.this.id}"

Because aws_vpc.this has "count" set, its attributes must be accessed on
specific instances.

For example, to correlate with indices of a referring resource, use:
aws_vpc.this[count.index]

Error: Unsupported argument

on .terraform/modules/vpc/terraform-aws-modules-terraform-aws-vpc-d723605/main.tf line 295, in resource "aws_default_network_acl" "this":
295: ingress = "${var.default_network_acl_ingress}"

An argument named "ingress" is not expected here. Did you mean to define a
block of type "ingress"?

Error: Unsupported argument

on .terraform/modules/vpc/terraform-aws-modules-terraform-aws-vpc-d723605/main.tf line 296, in resource "aws_default_network_acl" "this":
296: egress = "${var.default_network_acl_egress}"

An argument named "egress" is not expected here. Did you mean to define a
block of type "egress"?

[root@linux01 eks-demo]#

Regards,
Nagaraju
-Student of your Udemy Course

All demos have hard-coded region

I copied over my vars.tf and my terraform.tfvars file and yet demo-8 (probably others) still tried to apply to us-west-1 despite my settings as us-east-1

Provision files via ssh connection : no such file or directory

I have this on my connection. The goal is to copy a file to this server on ec2.

connection {
    type     = "ssh"
    host     = aws_instance.example[0].public_ip
    user     = "ec2-user"
    private_key ="${file(var.ssh_key_file_path)}"
  }

However terraform does not accept the content of the file as in the documentation. It tries to read the file content as if it were a file itself. Passing the file name also results in invalid key.

connection {
    type     = "ssh"
    host     = aws_instance.example[0].public_ip
    user     = "ec2-user"
    private_key =var.ssh_key_file_path
  }

The documentation says

private_key - The contents of an SSH key to use for the connection. These can be loaded from a file on disk using the file function. This takes preference over the password if provided.

Output:
Error: stat -----BEGIN PRIVATE KEY-----
.
.
.
-----END PRIVATE KEY-----
: no such file or directory

Question
Has this behavior been modified? Or Am I missing something

Unable to launch EC2 instance

Trying to create the ec2 instance following the steps in Udemy course.

install.tf

provider "aws" {
  access_key = ""
  secret_key = ""
  region     = "us-east-2"
}

resource "aws_instance" "example" {
  ami           = "ami-0bb2a062146998209"
  instance_type = "t2.micro"
}

Getting below error -

Error: Error launching source instance: Unsupported: The requested configuration is currently not supported. Please check the documentation for supported configurations.
	status code: 400, request id: 9115509c-2381-465c-b279-f2c409b65dc1

  on instance.tf line 7, in resource "aws_instance" "example":
   7: resource "aws_instance" "example" {

Using https://cloud-images.ubuntu.com/locator/ec2/ to get the AMI ID

Demo-5: Error authorizing security group ingress rules: RulesPerSecurityGroupLimitExceeded: The maximum number of rules per security group has been reached

I watched 22. Demo: Data sources and created securitygroup.tf with the next content on terraform 0.12.7

data "aws_ip_ranges" "european_ec2" {
  regions = ["eu-central-1", "eu-west-1"]
  services = ["ec2"]
}

resource "aws_security_group" "from_europe" {
  name = "from_europe"
  
  ingress {
    from_port = "443"
    to_port = "443"
    protocol = "tcp"
    cidr_blocks = data.aws_ip_ranges.european_ec2.cidr_blocks
  }
  tags = {
   CreateDate = data.aws_ip_ranges.european_ec2.create_date
   SyncToken = data.aws_ip_ranges.european_ec2.sync_token
  }
}

but when I run terraform apply I get the next error

Error: Error authorizing security group ingress rules: RulesPerSecurityGroupLimitExceeded: The maximum number of rules per security group has been reached.
	status code: 400, request id: 2ce9706d-3bd7-4694-ad18-5213da3123cf

  on securitygroup.tf line 6, in resource "aws_security_group" "from_europe":
   6: resource "aws_security_group" "from_europe" {

My AWS account is new with only default configuration. There is something wrong with my configuration?

Question about 2B

This is about lesson 2B

When I run "terraform apply" the instance are created and the powershell scripts runs without any errors.
but the fileupload are failing:

provisioner "file" {
source = "test.txt"
destination = "C:/test.txt"
}

  • aws_instance.win-example: 1 error(s) occurred:
  • unknown error Post http://54.229.229.22:5985/wsman: dial tcp 54.229.229.22:5985: getsockopt: operation timed out

But its not a timeout problem, have tried to increase timeout but it's not helping.
Is there a way that I can debug the problem? is it better to use packer? In the end I am going to create a win server with sitecore on it.

All development are made on OS X or ubuntu

Add Access & Secret key variables for demo-6

Hi,

I noticed that the Access and Secret keys were missing in demo-6 so I added them for the demo to work. These are my updates:

vagrant@ubuntu-xenial:~/test/terraform-course/demo-6$ git diff --name-only master
demo-6/provider.tf
demo-6/vars.tf
vagrant@ubuntu-xenial:~/test/terraform-course/demo-6$ git diff  master
diff --git a/demo-6/provider.tf b/demo-6/provider.tf
index ded6d8c..a49b1d8 100644
--- a/demo-6/provider.tf
+++ b/demo-6/provider.tf
@@ -1,3 +1,5 @@
 provider "aws" {
+    access_key = "${var.AWS_ACCESS_KEY}"
+    secret_key = "${var.AWS_SECRET_KEY}"
     region = "${var.AWS_REGION}"
 }
diff --git a/demo-6/vars.tf b/demo-6/vars.tf
index ce2e56b..d9defcd 100644
--- a/demo-6/vars.tf
+++ b/demo-6/vars.tf
@@ -1,3 +1,5 @@
+variable "AWS_ACCESS_KEY" {}
+variable "AWS_SECRET_KEY" {}
 variable "AWS_REGION" {
   default = "eu-west-1"
 }
vagrant@ubuntu-xenial:~/test/terraform-course/demo-6$

You don't need to add them or anything.

Thanks

Dennis

terraform demo-5

Hi Edward,

I am getting this below error when i tried to create a security group.

  **Error: Incorrect attribute value type

  on securitygroup.tf line 13, in resource "aws_security_group" "from_europe":
  13:     cidr_blocks = [ "${data.aws_ip_ranges.european_ec2.cidr_blocks}" ]

   Inappropriate value for attribute "cidr_blocks": element 0: string required.**

my current version:

Terraform v0.12.6

  • provider.aws v2.23.0

terraform demo-5 : Datasource

I am getting error when i tried to use the terraform datasource (aws_ip_ranges) to get the avaliable ip address ranges for service "ec2".

provider "aws" {
   region = "${var.AWS_REGION}"
}
variable "AWS_REGION" {
   default = "ap-south-1"
}

data "aws_ip_ranges" "european_ec2" {
   regions = [ "eu-west-1", "eu-central-1" ]
   services = [ "ec2" ]
}
resource "aws_security_group" "from_europe" {
  name = "from_europe"
  ingress {
	from_port = "443"
	to_port = "443"
	protocol = "tcp"
	cidr_blocks = [ "${data.aws_ip_ranges.european_ec2.cidr_blocks}" ]
}
tags = {
  CreateDate = "${data.aws_ip_ranges.european_ec2.create_date}"
  SyncToken = "${data.aws_ip_ranges.european_ec2.sync_token}"
}
}

Getting this below error when executing "terraform apply"

 Error: Incorrect attribute value type

   on securitygroups.tf line 13, in resource "aws_security_group" 
 "from_europe":
  13:     cidr_blocks      = 
  ["${data.aws_ip_ranges.european_ec2.cidr_blocks}"]

  Inappropriate value for attribute "cidr_blocks": element 0: string 
  required.

version: Terraform v0.12.6 + provider.aws v2.23.0

Kindly help to resolve this.

Provider "cloudinit" not available for installation

terraform init

Initializing provider plugins...

  • Downloading plugin for provider "cloudinit"...

Provider "cloudinit" not available for installation.

A provider named "cloudinit" could not be found in the official repository.

This may result from mistyping the provider name, or the given provider may
be a third-party provider that cannot be installed automatically.

In the latter case, the plugin must be installed manually by locating and
downloading a suitable distribution package and placing the plugin's executable
file in the following directory:
terraform.d/plugins/linux_amd64

Terraform detects necessary plugins by inspecting the configuration and state.
To view the provider versions requested by each module, run
"terraform providers".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.