IaC IL - Terraform Ansible Pulumi
270 subscribers
2 photos
25 links
Download Telegram
Pulumi and Terraform are two popular infrastructure as code (IaC) tools that are widely used for managing cloud infrastructure. Both tools allow developers to define and manage their infrastructure using code, making it easier to automate and version control their infrastructure.
One of the main differences between Pulumi and Terraform is the programming language they use. Pulumi is written in modern programming languages such as JavaScript, TypeScript, and Python, while Terraform is written in its own domain-specific language (DSL) called HashiCorp Configuration Language (HCL). This can be a pro or a con depending on the team's proficiency with different languages.
Another difference is that Pulumi has a more object-oriented approach to infrastructure management, while Terraform uses a declarative approach. In Pulumi, you create, update, and delete resources using classes and objects, while in Terraform, you define the desired state of your resources and the tool takes care of creating, updating, or deleting them.
Pulumi also supports more cloud providers than Terraform. Pulumi supports many popular cloud providers such as AWS, Azure, GCP, and Kubernetes, while Terraform supports a wide range of providers, but not as many as Pulumi.
In terms of ease of use, Terraform is considered to be easier to learn and use compared to Pulumi, especially for users who are new to IaC. Terraform's HCL is simple and easy to understand. Pulumi, on the other hand, has a steeper learning curve, but its object-oriented approach allows for better code reuse and abstraction.
Here is an example of how to create an S3 bucket using Pulumi and Terraform:

Pulumi:
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("my-bucket", {});

Terraform:
resource "aws_s3_bucket" "my_bucket" {
bucket = "my-bucket"
}

In conclusion, both Pulumi and Terraform have their pros and cons. Pulumi's support for multiple programming languages and its object-oriented approach

Certainly, here is an example of how to create an Amazon EKS cluster with the necessary dependencies, including a new VPC and relevant resources that allow access to the Internet using both Pulumi and Terraform:

Pulumi(typescript):
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const vpc = new aws.ec2.Vpc("my-vpc", {
cidrBlock: "10.0.0.0/16",
});

const igw = new aws.ec2.InternetGateway("my-igw", {
vpcId: vpc.id,
});

const subnet = new aws.ec2.Subnet("my-subnet", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
availabilityZone: "us-west-2a",
mapPublicIpOnLaunch: true,
});

const securityGroup = new aws.ec2.SecurityGroup("my-security-group", {
vpcId: vpc.id,
ingress: [{
fromPort: 22,
toPort: 22,
protocol: "tcp",
cidrBlocks: ["0.0.0.0/0"],
}],
egress: [{
fromPort: 0,
toPort: 0,
protocol: "-1",
cidrBlocks: ["0.0.0.0/0"],
}],
});

const clusterRole = new aws.iam.Role("eks-cluster-role", {
assumeRolePolicy: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
,
});

const clusterRolePolicyAttachment = new aws.iam.RolePolicyAttachment("eks-cluster-policy-attachment", {
role: clusterRole.name,
policyArn: "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
});

const serviceRolePolicyAttachment = new aws.iam.RolePolicyAttachment("eks-service-policy-attachment", {
role: clusterRole.name,
policyArn: "arn:aws:iam::aws:policy/AmazonEKSServicePolicy",
});

const eksCluster = new aws.eks.Cluster("my-cluster", {
roleArn: clusterRole.arn,
vpcConfig: {
subnetIds: [subnet.id],
securityGroupIds: [securityGroup.id],
},
});

Pulumi (python):
import pulumi
import pulumi_aws as aws

vpc = aws.ec2.Vpc("my-vpc",
cidr_block="10.0.0.0/16")

igw = aws.ec2.InternetGateway("my-igw",
vpc_id=vpc.id)
subnet = aws.ec2.Subnet("my-subnet",
vpc_id=vpc.id,
cidr_block="10.0.1.0/24",
availability_zone="us-west-2a",
map_public_ip_on_launch=True)

security_group = aws.ec2.SecurityGroup("my-security-group",
vpc_id=vpc.id,
ingress=[{
"from_port": 22,
"to_port": 22,
"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"]
}])

cluster_role = aws.iam.Role("eks-cluster-role",
assume_role_policy='''{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}''')

cluster_role_policy_attachment = aws.iam.RolePolicyAttachment("eks-cluster-policy-attachment",
role=cluster_role.name,
policy_arn="arn:aws:iam::aws:policy/AmazonEKSClusterPolicy")

service_role_policy_attachment = aws.iam.RolePolicyAttachment("eks-service-policy-attachment",
role=cluster_role.name,
policy_arn="arn:aws:iam::aws:policy/AmazonEKSServicePolicy")

eks_cluster = aws.eks.Cluster("my-cluster",
role_arn=cluster_role.arn,
vpc_config={
"subnet_ids": [subnet.id],
"security_group_ids": [security_group.id]
})


Terraform:
provider "aws" {
region = "us-west-2"
}

resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}

resource "aws_internet_gateway" "example" {

resource "aws_internet_gateway" "example" {
vpc_id = aws_vpc.example.id
}

resource "aws_subnet" "example" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-west-2a"
map_public_ip_on_launch = true
}

resource "aws_security_group" "example" {
vpc_id = aws_vpc.example.id

ingress {
from_port = 22
to_port = 22
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_iam_role" "eks_cluster_role" {
name = "eks-cluster-role"

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Princ


resource "aws_iam_role" "eks_cluster_role" {
name = "eks-cluster-role"

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}

resource "aws_iam_role_policy_attachment" "eks_cluster_policy_attachment" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}
resource "aws_iam_role_policy_attachment" "eks_service_policy_attachment" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
}

resource "aws_eks_cluster" "example" {
name = "my-cluster"
role_arn = aws_iam_role.eks_cluster_role.arn

vpc_config {
security_group_ids = [aws_security_group.example.id]
subnet_ids = [aws_subnet.example.id]
}
}



https://t.me/IAC1L/12
בוקר טוב, שימו לב שיש מחר הדרכה מעשית ומעמיקה (workshop) על HashiCorp Vault ו- Zero Trust Security , ותהיה התייחסות גם ל- Kubernetes. הנחתי שיעניין כאן רבים, לכן מניח כאן.
מיועד למתחילים (ולא רק).
הכניסה חופשית (כמות המקומות מוגבלת) וזה יהיה באנגלית (יש גם הקלטה של הדרכה דומה בעברית). פרטים והרשמה כאן:
https://bit.ly/3xBremL

https://t.me/myeasylinux/1440
Channel name was changed to «IaC IL - Terraform Ansible Pulumi»
היי חברים שבוע טוב.

כתבתי מאמר על הכרות עם tftest שזו בעצם דרך להריץ טסטים על terrafom/terragrunt בעזרת פייתון וpytest.

https://medium.com/saas-infra/terraform-testing-made-easy-with-python-exploring-tftest-925bb207eabd

המאמר הבא כבר בדרך שבו אבחן איך ניתן לעשות e2e tests לכמה מודולים ולבדוק שהכל עובד יפה :)

תודה לאיסר על המאמר 💪
https://t.me/IAC1L/24
עוד מאמר של איסר🔥

אנחנו לקראת סוף השבוע ואף אחד לא רוצה נפילות לקראת הסופש, הפעם אני בוחן end to end testing עם pytest וtftest.

https://medium.com/@isar-nasimov/put-your-terraform-to-the-test-e2e-testing-with-python-and-tftest-73deff4c468a

https://t.me/IAC1L/25
סופש אליפות לכולנו
הפעם החלטתי לכתוב על crossplane, זה חלק ראשון מכמה בלוגים שאני מתכנן לכתוב, את רובן אני אכתוב מפרספקטיבה של אדם שיודע terraform.

אז הנה הבלוג הראשון שלי בנושא, להבין את הטרמינולוגיה של crossplane בעיניים של terraform engineer

https://isar-nasimov.medium.com/crossplane-101-a-terraform-enthusiasts-first-encounter-part-1-4e1637221639
תודה לאיסר
https://t.me/IAC1L/32
👍1