LoginSignup
1
0

More than 5 years have passed since last update.

Terraformを利用して、AWS EC2を作成してみた

Posted at

概要

Terraformを利用してAWSのEC2を作成してみました。
terraformを実行するのはIAM Roleで権限を付与したインスタンスからになります。

ドキュメントを見るといろいろと出来そうですね。
https://www.terraform.io/docs/

コードは下記になります。
同じ階層のディレクトリに変数の設定を入れてあげてください。

ec2_dev.tf

provider "aws" {
  region = "${var.region}"
}

resource "aws_instance" "dev" {
    ami = "${var.ami_id}"
    instance_type = "${var.instance_type}"
    key_name = "${var.key_name}"
    iam_instance_profile = "${var.iam_role}"
    vpc_security_group_ids = [
        "${var.sg_id}"
    ]
    subnet_id = "${var.subnet_id}"
    associate_public_ip_address = "true"
    root_block_device {
        volume_type = "gp2"
        volume_size = "8"
        delete_on_termination = "true"
    }
    tags {
        Name = "${var.tag_name}"
        env = "${var.tag_env}"
    }
}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0