LoginSignup
5
5

More than 1 year has passed since last update.

【Terraform】Terraformの設定(terraform, providerブロック, dataブロック, outputブロック)

Posted at

はじめに

udemyを使ってTerraformの勉強をしたので、terraformブロック、providerブロック、dataブロック、outputブロックについての学習備忘録です。

terraformブロック

Terraform全体に関わる設定ができる

  • required_version : Terraformのバージョン設定
  • required_providers: providerのバージョン設定
terraform {
  required_version = ">=0.13"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0" # 4.0以上, マイナーバージョンを気にしない
    }
  }
}

providerブロック

  • profile: AWSへアクセスするためのプロファイル
  • region : デフォルトリージョン
provider "aws" {
  profile = "terraform"
  region  = "ap-northeast-1"
}

dataブロック

管理対象外のリソースの取り込みができる

data "DATA_TYPE" "DATA_NAME" {
}

outputブロック

作成したリソースを外部参照できるようにする

output "OUTPUT_NAME" {
...
}
# 例
resource "aws_instance" "hello-world" {
  ami           = "ami-0ce107ae7af2e92b5"
  instance_type = "t2.micro"
  tags = {
    Name = "${var.name}"
  }
}

output "ec2_instance_id" {
  # 参照時に指定する名前
  value = aws_instance.hello-world.id
}
5
5
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
5
5