Terraform
Usage
terraform {
required_version = ">= 1.5"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">=5.0"
}
}
backend "s3" {
key = "prod/aws_ec2_keypair/terraform.tfstate"
}
}
provider "aws" {
region = var.aws_region
profile = var.aws_profile
}
resource "aws_key_pair" "keypair" {
key_name = "prod"
public_key = "ssh-rsa JIPOJDFIOPSJMDVUIERUIOHEWFDSJNJLKNLDSDFERW"
}
#Fetch remote data
data "aws_vpc" "vpc" {
id = "akakaf"
}
#Fetch remote data about other terraform files like vpc
data "terraform_remote_state" "vpc" {
backend = "s3"
config = {
bucket = "optix-terraform"
key="prod/aws_vpc/terraform.tfstate"
region = var.aws_region
profile = var.aws_profile
}
}
locals {
vpn_arc = data.aws_vpc.vpc.arn
}
#Reuse terraform code, like declarative function call
module "bastion_instance" {
#source of code
source = "../../../modules/aws_opensearch_cluster"
#pass variables to that module
aws_account = ...
}
resource "hi" {
}File structure
Usage of Specific Setup
New
Existing
Last updated