visit
provider "aws" {
region = "us-east-1"
}
Create an EKS cluster
resource "aws_eks_cluster" "eks_cluster" {
name = "my-eks-cluster"
role_arn = aws_iam_role.eks_cluster_role.arn
}
Create an IAM role for the EKS cluster
Attach the AmazonEKSClusterPolicy policy to the EKS cluster role
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"
}
Create an Amazon Elastic Block Store (EBS) volume for the Kubernetes etcd data
resource "aws_ebs_volume" "eks_etcd_volume" {
availability_zone = aws_instance.eks_control_plane.availability_zone
size = 20
type = "gp2"
}
Create an Amazon Elastic Compute Cloud (EC2) instance for the Kubernetes control plane
resource "aws_instance" "eks_control_plane" {
ami = "ami-0ac019f4fcb7cb7e6"
instance_type = "t3.medium"
subnet_id = aws_subnet.eks_control_plane_subnet.id
iam_instance_profile = aws_iam_instance_profile.eks_control_plane_instance_profile.name
key_name = "my-ssh-key"
root_block_device {
volume_type = "gp2"
volume_size = 20
delete_on_termination = true
}
tags = {
Name = "eks-control-plane"
}
}
Create an IAM instance profile for the Kubernetes control plane EC2 instance
resource "aws_iam_instance_profile" "eks_control_plane_instance_profile" {
name = "eks-control-plane-instance-profile"
role = aws_iam_role.eks_control_plane_role.name
}
Create an IAM role for the Kubernetes control plane EC2 instance
resource "aws_iam_role" "eks_control_plane_role" {
name = "eks-control-plane-role"
assume_role_policy = <<POL
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/sns"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create an S3 bucket.
bucket, err := s3.NewBucket(ctx, "my-bucket", &s3.BucketArgs{
// Add other bucket configuration options here.
})
if err != nil {
return err
}
// Create an SNS topic for notifications.
topic, err := sns.NewTopic(ctx, "my-topic", &sns.TopicArgs{
// Add other topic configuration options here.
})
if err != nil {
return err
}
// Add an SNS topic subscription for the bucket.
_, err = s3.NewBucketNotification(ctx, "bucket-notification", &s3.BucketNotificationArgs{
Bucket: bucket.ID(),
TopicConfigurations: s3.BucketNotificationTopicConfigurationArray{
s3.BucketNotificationTopicConfigurationArgs{
TopicArn: topic.Arn,
// Add other topic configuration options here.
},
},
})
if err != nil {
return err
}
return nil
})
}
What you can see in this code, is that it uses the AWS Go SDK and the Pulumi AWS package to create an S3 bucket and an SNS topic. It then adds a subscription to the SNS topic using the s3.NewBucketNotification
function. An added step that is important and wasn’t directly requested. Impressive.
node {
stage("Clone repository") {
git url: "//github.com/<username>/<repository>.git"
}
stage("Scan code with trivy") {
sh "trivy --exit-code 1 --severity CRITICAL <repository>"
}
stage("Run infracost") {
sh "infracost --no-color"
}
stage("Plan infrastructure with terraform") {
sh "terraform plan"
}
stage("Apply infrastructure with terraform") {
sh "terraform apply"
}
}
name: Terraform
on: [push]
jobs:
terraform:
name: Apply Terraform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Apply Terraform
uses: hashicorp/[email protected]
with:
tf_actions_version: 0.12.29
tf_actions_subcommand: apply
tf_actions_working_dir: .
- name: Send Slack notification
uses: shivammathur/slack-notify-action@v1
with:
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
message: Terraform apply complete