Giter Club home page Giter Club logo

terraform_instances_with_key's Introduction

terraform_instances_with_key

  1. Create instance with terraform features

  2. Create instance from UI and use the key next time

  3. Create instance use the public key inside the file

  4. Create an instances using: resource "aws_key_pair" "my_key" { key_name = "my_key" public_key = "" }

  5. Create an instance using the key_name = "${file("public_key"}"

  6. Create an instance with userdata

     user_data = "${file("user_data")}"
    
  7. Create an instance with vars inside the file like this

variable "ami" { default = "ami-oololol" } and use it inside the instance block

resource "aws_instance" "my-instance" { ami = "${var.ami}"

  1. Create a vars.tf file with the ami names from AWS variable "awsami" { default = "ami-slsldfldfld" }

variable "centos7" { default = "centos-ami-dlldldl" }

use it inside the file resource "aws_instance" "my-instance" { ami = "${var.ami}"

Create a variable with variable "micro" { default = "t2.micro" }

variable "awsami" { default = "ami-0b59bfac6be064b78" } variable "micro" { default = "t2.micro" } variable "dev" { default = "Dev_Environment" }

use it inside the file

  1. Use count option to create multiple instances on aws resource "aws_instance" "my-instance" { ami = "${var.ami}" instance_type = "t2.micro" key_name = "{var.my_key}" user_data = "${file("user_data")}" count = 4 }

  2. Use terraform provider file instead of same place. vim provider.tf

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

  1. Create count.tf file and add the following to that variable "instance_count" { default = 1 #10 } Inside the terraform.tf file add the following count = "${var.instance_count}"

This will create the default number of instance for us. Pay attention to tag

tags { ENVIRONMENT = "Dev-${count.index}" } This will create Dev-1 tag on the instances.


Terraform import

The reason: If the environment is created by terraform, but some user also creates an instance on the same region. If that same environment needs to be provisioned on new region, terraform skips the instance that user created from console. Because that instance is not managed by terraform. To avoid this, we have to import the instance to terraform.

Usage. Declare the instance on terraform file. resource "aws_instance" "name_of_the_instance" { ami = "" }

From the command line terraform import aws_instance.name_of_the_instance i-10dl10dl40dlsl

This command updates the terraform state file. Next time when the environment built it will create all the instance.

terraform_instances_with_key's People

Contributors

farrukh90 avatar

Watchers

 avatar  avatar

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.