38.User Variable Setup Using Terraform

Published: (February 2, 2026 at 04:30 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Lab Information

The Nautilus DevOps team is automating IAM user creation using Terraform for better identity management.
Create an AWS IAM user with the following requirements:

  • The IAM user name iamuser_mark should be stored in a variable named KKE_user.
  • Configuration values should be stored in a variables.tf file.
  • The Terraform script should be structured with a main.tf file referencing variables.tf.
  • Working directory: /home/bob/terraform.

variables.tf

# Define variable for IAM user name
variable "KKE_user" {
  description = "The name of the IAM user to create"
  type        = string
  default     = "iamuser_mark"
}

main.tf

# Create AWS IAM User with variable reference
resource "aws_iam_user" "this" {
  name = var.KKE_user

  tags = {
    Name = var.KKE_user
  }
}

Terraform Commands

cd /home/bob/terraform
terraform init

Output (excerpt):

Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "5.91.0"...
- Installing hashicorp/aws v5.91.0...
- Installed hashicorp/aws v5.91.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider selections.
Terraform has been successfully initialized!
terraform plan

Output (excerpt):

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  + create

# aws_iam_user.this will be created
+ resource "aws_iam_user" "this" {
    + arn           = (known after apply)
    + force_destroy = false
    + id            = (known after apply)
    + name          = "iamuser_mark"
    + path          = "/"
    + tags          = {
        + "Name" = "iamuser_mark"
      }
    + tags_all      = {
        + "Name" = "iamuser_mark"
      }
    + unique_id     = (known after apply)
  }

Plan: 1 to add, 0 to change, 0 to destroy.
terraform apply

When prompted, type yes to confirm.

Output (excerpt):

aws_iam_user.this: Creating...
aws_iam_user.this: Creation complete after 0s [id=iamuser_mark]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Back to Blog

Related posts

Read more »

34.Copy Data to S3 Using Terraform

Lab Information The Nautilus DevOps team is currently performing data migrations, moving data from on‑premise storage systems to AWS S3 buckets. They have rece...

30.Delete EC2 Instance Using Terraform

markdown !Cover image for 30.Delete EC2 Instance Using Terraformhttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/htt...