terraform aws_instance code example

Example 1: aws instance creation using terraform

resource "aws_instance" "myec2" {
  ami                    = ""
  instance_type          = "t2.micro"
  vpc_security_group_ids = ["SECURITY-GROUP-ID"]
  key_name               = ""
  subnet_id              = ""
  iam_instance_profile = ""

  tags = {
    Name = ""
  }
}

Example 2: how to define provider in resource block

# default configuration
provider "google" {
  region = "us-central1"
}

# alternate configuration, whose alias is "europe"
provider "google" {
  alias  = "europe"
  region = "europe-west1"
}

resource "google_compute_instance" "example" {
  # This "provider" meta-argument selects the google provider
  # configuration whose alias is "europe", rather than the
  # default configuration.
  provider = google.europe

  # ...
}

Tags:

Misc Example