Bootstrap FreeKB - Amazon Web Services (AWS) - List IAM Profiles using Terraform
Amazon Web Services (AWS) - List IAM Profiles using Terraform


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

├── required_providers.tf
├── amazon_machine_images (directory)
│   ├── data.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 data.tf contains something like this to fetch an IAM Profile using the name of the profile.

data "aws_iam_instance_profile" "AmazonEC2ContainerServiceforEC2Role" {
  name = "AmazonEC2ContainerServiceforEC2Role"
}

 

The terraform refresh command should return something like this, the ID of the policy should be returned.

TBD

 




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 2f52ea in the box below so that we can be sure you are a human.