Amazon Web Services (AWS) - Create IAM Profile using Terraform

by
Jeremy Canfield |
Updated: August 31 2023
| Amazon Web Services (AWS) articles
Let's say you have the following files on your Terraform server.
├── required_providers.tf
├── iam (directory)
│ ├── provider.tf
│ ├── resources.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 resources.tf has the following to create a policy named my-policy.
resource "aws_iam_instance_profile" "my-profile" {
name = "my-profile"
role = "my-role"
}
The terraform plan command can be used to see what Terraform should do (create the IAM profile).
~]$ terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_iam_instance_profile.my-profile will be created
+ resource "aws_iam_instance_profile" "my-profile" {
+ arn = (known after apply)
+ create_date = (known after apply)
+ id = (known after apply)
+ name = "ecs-profile"
+ name_prefix = (known after apply)
+ path = "/"
+ role = "my-role"
+ tags_all = (known after apply)
+ unique_id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
The terraform apply command can be used to create the IAM profile.
terraform apply
Did you find this article helpful?
If so, consider buying me a coffee over at