DevOps Classroom Series – 20/Jan/2020


  • For creating ec2 machine, we need to provide

    • subnet-id
    • security group
    • key value pair
  • One approach create every thing and use the attributes.

  • If we want to use existing subnet-id, security group and key-value pair, we need to know ids, for this terraform has data sources which can query the information from providers.

  • Every provider gives various data sources much like resources.

  • Lets create a simple data source to pull the information of default subnet and create a new subnet

data "aws_vpc" "default" {
    default = true

resource "aws_subnet" "extra" {
    cidr_block = ""
    vpc_id = "${}"

Terraform provisioning

  • Execution of scripts/ansible/chef after creation of Virtual Machines is supported by terraform provisioners. Refer


  • Two tf developers have same terraform script and they have applied terraform, it creates two different resources, as the state file is stored on individual developers laptop Preview
  • Now, if we want to restrict these two developers in such a way, whenever they execute terraform it should not create two different but one resource.
  • Terraform supports backends, to store state remotely and terraform also supports locking feature to avoid simultaneous access to terraform state. Preview
  • Refer

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner