Creating an IAM user involves multiple steps. First, you create the IAM user, and then you may want to add the user to a group, attach a policy, and create access keys. Here’s how you can do it using Terraform:

Note : This is will only Workout when your Access key and Security key has Configured through AWS CLI.

Using Terraform:

1.Install Terraform: If you haven’t installed Terraform yet, download and install it from the official Terraform website.

https://developer.hashicorp.com/terraform/downloads?product_intent=terraform it is only for Windows you download as per your choice through above link.

2.Configure AWS CLI: Configure AWS CLI as mentioned in the previous response. Terraform will use the credentials configured in the AWS CLI.

3.Create Terraform Configuration: Create a file named main.tf with the following content:

provider "aws" {
region = "eu-north-1" # Change to your preferred region
} 
resource "aws_iam_user" "test123" {
name = "Rushi_infotech123"
} 

This configuration will create an IAM user named Rushi_infotech123 and an access key for that user.

4.Initialize Terraform: Run "terraform init” in the same directory as your main.tf file.

5.Apply Configuration: Run terraform apply and confirm the changes.

6.Store Credentials: The access key ID and secret access key will be displayed as outputs. Make sure to store them securely.

This method will create an IAM user with the necessary access key. Remember to store the access key ID and secret access key securely. Do not share them with anyone or store them in a public repository. It is also recommended to use IAM roles and policies to grant the necessary permissions to your IAM user.

Destroy the IAM User :

1.We can destroy the IAM User through terraform by running the command

terraform destroy -target aws_iam_user.test123

It has taken from the above example.

2.Here is the result that the user has destroyed .

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *