Bootstrap FreeKB - Amazon Web Services (AWS) - List Elastic File Systems (EFS) using Terraform
Amazon Web Services (AWS) - List Elastic File Systems (EFS) using Terraform


Let's say you have the following files on your Terraform server.

├ required_providers.tf
├ efs (directory)
├── access_points.tf
├── elastic_file_systems.tf
├── mount_targets.tf
├── outputs.tf
├── provider.tf

 

required_providers.tf will almost always have this.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
    }
  }
}

 

Let's say provider.tf has the following. In this example, the "default" profile in /home/username/.aws/config and /home/username/.aws/credentials is being used. This assumes you have setup Terraform as described in Amazon Web Services (AWS) - Getting Started with Terraform.

provider "aws" {
  alias   = "default"
  profile = "default"
  region  = "default"
}

 

And let's say data.tf contains the following, to get the details of the Elastic File System that has ID fs-123456789abcdefg.

data "aws_efs_file_system" "my-efs" {
  file_system_id = "fs-123456789abcdefg"
}

 

And outputs.tf could then have something like this.

output "my_efs" {
  value = data.aws_efs_file_system.my-efs
}

 

You may need to issue the terraform init command.

terraform init

 

And then the terraform refresh command should return something like this.

]$ terraform refresh

my_efs = {
  "arn" = "arn:aws:elasticfilesystem:us-east-1:123456789012:file-system/fs-123456789abcdefg"
  "availability_zone_id" = ""
  "availability_zone_name" = ""
  "creation_token" = "rosa-efs"
  "dns_name" = "fs-123456789abcdefg.efs.us-east-1.amazonaws.com"
  "encrypted" = true
  "file_system_id" = "fs-123456789abcdefg"
  "id" = "fs-123456789abcdefg"
  "kms_key_id" = "arn:aws:kms:us-east-1:123456789012:key/mrk-e295b8e34951413889916ed3e18c11db"
  "lifecycle_policy" = tolist([])
  "performance_mode" = "generalPurpose"
  "provisioned_throughput_in_mibps" = 0
  "size_in_bytes" = 24576
  "tags" = tomap({
    "Environment" = "Development"
  })
  "throughput_mode" = "bursting"
}

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 9f7bac in the box below so that we can be sure you are a human.