Skip to content

Provision IAM user & attach policy using the terraform as IaC

Notifications You must be signed in to change notification settings

syamsankarlv/terraform_IAM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS IAM-user's Creation Using Terraform

Build Status

Using this Terraform code, we can provision AWS IAM users and attach policies to them.

Contents

Introduction

This Terraform configuration allows for the creation of IAM users in AWS and the attachment of a predefined policy to those users. IAM (Identity and Access Management) in AWS enables you to securely control access to AWS services and resources.

Prerequisites

Before using this Terraform configuration, ensure you have the following:

  • Passing IAM credentials through environment variables ensures that Terraform can securely access them without explicitly storing them in its configuration.

  • Terraform automatically fetches these credentials from the environment variables during its execution.

Usage

  • Update the variables.tf file to specify the usernames for the IAM users you want to create.
  • Initialize the Terraform configuration by running terraform init.
  • Review the execution plan by running terraform plan.
  • If the plan looks good, apply the changes by running terraform apply.
  • After applying the changes, Terraform will output the details of the created IAM users.

Explanation

IAM User Creation

The aws_iam_user resource block is responsible for creating IAM users in AWS. It iterates over the usernames specified in the var.username variable and creates a user for each.

Policy Creation and Attachment

The aws_iam_policy resource block defines a policy named ec2_policy, which allows describing EC2 instances. It grants the necessary permissions using a JSON-encoded policy document.

The aws_iam_policy_attachment resource block attaches the ec2_policy to the IAM users created earlier. It iterates over each IAM user and attaches the policy to them. The lifecycle block ensures that the attachment is created before any existing attachments are destroyed, to prevent downtime.

OUTPUT SNAPSHOTS

Screenshot_1 Screenshot_2 Screenshot_3 Screenshot_4

Resources

About

Provision IAM user & attach policy using the terraform as IaC

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages