From 6234687f5830cc05e8678afd5e07aacdbdf026d1 Mon Sep 17 00:00:00 2001 From: Anuj Sharma Date: Thu, 25 Apr 2024 12:02:41 +0530 Subject: [PATCH] Update main.tf --- iam_terraform/main.tf | 101 +++++------------------------------------- 1 file changed, 10 insertions(+), 91 deletions(-) diff --git a/iam_terraform/main.tf b/iam_terraform/main.tf index 1ad4ac7..c7f7039 100644 --- a/iam_terraform/main.tf +++ b/iam_terraform/main.tf @@ -1,97 +1,16 @@ -#main.tf - -# VPC -resource "aws_vpc" "terra_vpc" { - cidr_block = var.vpc_cidr - tags = { - Name = "TerraVPC" - } -} - -# Internet Gateway -resource "aws_internet_gateway" "terra_igw" { - vpc_id = aws_vpc.terra_vpc.id - tags = { - Name = "main" - } -} - -# Subnets : public -resource "aws_subnet" "public" { - vpc_id = aws_vpc.terra_vpc.id - cidr_block = var.subnets_cidr - availability_zone = var.azs - map_public_ip_on_launch = true - tags = { - Name = "Subnet" - } -} - -# Route table: attach Internet Gateway -resource "aws_route_table" "public_rt" { - vpc_id = aws_vpc.terra_vpc.id - route { - cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.terra_igw.id - } - tags = { - Name = "publicRouteTable" - } -} - -# Route table association with public subnets -resource "aws_route_table_association" "a" { - subnet_id = aws_subnet.public.id - route_table_id = aws_route_table.public_rt.id +resource "aws_iam_user" "users" { + count = length(var.user_names) + name = var.user_names[count.index] } +Create a file outputs.tf with below content: -resource "aws_security_group" "jenkins_security_group" { - name = "sg_jenkins" - description = "jenkins security group." - vpc_id = aws_vpc.terra_vpc.id -} - -resource "aws_security_group_rule" "ssh_ingress_access" { - type = "ingress" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = [ "0.0.0.0/0" ] - security_group_id = "${aws_security_group.jenkins_security_group.id}" -} - -resource "aws_security_group_rule" "egress_access" { - type = "egress" - from_port = 0 - to_port = 65535 - protocol = "tcp" - cidr_blocks = [ "0.0.0.0/0" ] - security_group_id = "${aws_security_group.jenkins_security_group.id}" -} - -data "aws_ami" "latest-ubuntu" { -most_recent = true - - filter { - name = "name" - values = ["amzn2-ami-kernel-5.10-hvm-2.0.20230418.0-x86_64-gp2"] - } - - filter { - name = "virtualization-type" - values = ["hvm"] - } +output "Simon_arn" { + value = aws_iam_user.users[0].arn + description = "The ARN for user Paul Dirac" } -resource "aws_instance" "jenkins_instance" { - instance_type = "t2.micro" - vpc_security_group_ids = [ "${aws_security_group.jenkins_security_group.id}" ] - associate_public_ip_address = true - tags = { - Name = "jenkins-instance" - } - ami = "${data.aws_ami.latest-ubuntu.id}" - availability_zone = "${var.azs}" - subnet_id = "${aws_subnet.public.id}" +output "all_arns" { + value = aws_iam_user.users[*].arn + description = "The ARNs for all users" }