User Tools

Site Tools


wiki:ai:bicep-terraform-comparison

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:ai:bicep-terraform-comparison [2025/06/11 14:21] ddehamerwiki:ai:bicep-terraform-comparison [2025/06/11 14:31] (current) ddehamer
Line 1: Line 1:
 ====== Bicep Terraform Comparison ====== ====== Bicep Terraform Comparison ======
 +
 +===== Conclusion =====
  
 I worked on two scripts, both doing the same thing, one in Bicep and one in Terraform. I worked on two scripts, both doing the same thing, one in Bicep and one in Terraform.
Line 17: Line 19:
 terraform apply terraform apply
 </code> </code>
 +
 +===== Bicep Code =====
  
 main.bicep main.bicep
Line 312: Line 316:
 } }
 </code> </code>
 +
 +===== Terraform Code =====
  
 main.tf main.tf
Line 498: Line 504:
 EOF EOF
   )   )
 +}
 +</code>
 +
 +===== AWS Comparison =====
 +
 +Bonus to show how similar AWS and Azure are with Terraform:
 +
 +==== AWS Terraform ====
 +
 +main_aws.tf
 +<code>
 +provider "aws" {
 +  region = "us-east-1"
 +}
 +
 +variable "vpc_cidr" {
 +  default = "10.0.0.0/16"
 +}
 +
 +variable "subnet1_cidr" {
 +  default = "10.0.0.0/24"
 +}
 +
 +variable "subnet2_cidr" {
 +  default = "10.0.1.0/24"
 +}
 +
 +resource "aws_vpc" "main" {
 +  cidr_block = var.vpc_cidr
 +  tags = {
 +    Name = "main-vpc"
 +  }
 +}
 +
 +resource "aws_subnet" "subnet1" {
 +  vpc_id     = aws_vpc.main.id
 +  cidr_block = var.subnet1_cidr
 +  availability_zone = "us-east-1a"
 +  tags = {
 +    Name = "subnet-1"
 +  }
 +}
 +
 +resource "aws_subnet" "subnet2" {
 +  vpc_id     = aws_vpc.main.id
 +  cidr_block = var.subnet2_cidr
 +  availability_zone = "us-east-1b"
 +  tags = {
 +    Name = "subnet-2"
 +  }
 +}
 +
 +resource "aws_internet_gateway" "gw" {
 +  vpc_id = aws_vpc.main.id
 +}
 +
 +resource "aws_route_table" "rt" {
 +  vpc_id = aws_vpc.main.id
 +
 +  route {
 +    cidr_block = "0.0.0.0/0"
 +    gateway_id = aws_internet_gateway.gw.id
 +  }
 +}
 +
 +resource "aws_route_table_association" "a1" {
 +  subnet_id      = aws_subnet.subnet1.id
 +  route_table_id = aws_route_table.rt.id
 +}
 +
 +resource "aws_route_table_association" "a2" {
 +  subnet_id      = aws_subnet.subnet2.id
 +  route_table_id = aws_route_table.rt.id
 +}
 +
 +resource "aws_security_group" "web_sg" {
 +  name        = "web-sg"
 +  description = "Allow SSH and HTTP"
 +  vpc_id      = aws_vpc.main.id
 +
 +  ingress {
 +    from_port   = 22
 +    to_port     = 22
 +    protocol    = "tcp"
 +    cidr_blocks = ["0.0.0.0/0"]
 +  }
 +
 +  ingress {
 +    from_port   = 80
 +    to_port     = 80
 +    protocol    = "tcp"
 +    cidr_blocks = ["0.0.0.0/0"]
 +  }
 +
 +  egress {
 +    from_port   = 0
 +    to_port     = 0
 +    protocol    = "-1"
 +    cidr_blocks = ["0.0.0.0/0"]
 +  }
 +}
 +
 +resource "aws_instance" "vm1" {
 +  ami                         = "ami-xxxxxxxxxxxxxxxxx" # Replace with valid Ubuntu AMI
 +  instance_type               = "t2.micro"
 +  subnet_id                   = aws_subnet.subnet1.id
 +  vpc_security_group_ids      = [aws_security_group.web_sg.id]
 +  key_name                    = "my-key" # Replace with your key pair name
 +  associate_public_ip_address = true
 +
 +  user_data = <<-EOF
 +              #!/bin/bash
 +              apt update
 +              apt install -y apache2
 +              systemctl enable apache2
 +              systemctl start apache2
 +              EOF
 +
 +  tags = {
 +    Name = "vm1"
 +  }
 +}
 +
 +resource "aws_instance" "vm2" {
 +  ami                         = "ami-xxxxxxxxxxxxxxxxx" # Replace with valid Ubuntu AMI
 +  instance_type               = "t2.micro"
 +  subnet_id                   = aws_subnet.subnet2.id
 +  vpc_security_group_ids      = [aws_security_group.web_sg.id]
 +  key_name                    = "my-key" # Replace with your key pair name
 +  associate_public_ip_address = true
 +
 +  user_data = <<-EOF
 +              #!/bin/bash
 +              apt update
 +              apt install -y apache2
 +              systemctl enable apache2
 +              systemctl start apache2
 +              EOF
 +
 +  tags = {
 +    Name = "vm2"
 +  }
 } }
 </code> </code>
wiki/ai/bicep-terraform-comparison.1749651680.txt.gz · Last modified: by ddehamer