Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created February 9, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/e737668219a771ce71f47a20cf73618b to your computer and use it in GitHub Desktop.
Save ruanbekker/e737668219a771ce71f47a20cf73618b to your computer and use it in GitHub Desktop.
Output values with Terraform

provider.tf:

$ cat provider.tf
provider "aws" {
  version = "~> 2.0"
  region  = "eu-west-1"
  profile = "dev"
  shared_credentials_file = "~/.aws/credentials"
}

vpc.tf:

$ cat vpc.tf
data "aws_vpc" "default" {
  default = true
}

data "aws_subnet_ids" "private" {
  vpc_id = data.aws_vpc.default.id

  tags = {
    Tier = "private"
  }
}

output.tf:

$ cat output.tf
output "vpc_id" {
  description = "The Default VPC ID"
  value       = data.aws_vpc.default.id
}

Run:

$ terraform init
$ terraform apply
data.aws_vpc.default: Refreshing state...
data.aws_subnet_ids.private: Refreshing state...

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

vpc_id = vpc-xxxxxxxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment