Skip to content

Instantly share code, notes, and snippets.

@dixler

dixler/index.ts Secret

Created November 3, 2022 14:59
Show Gist options
  • Save dixler/d54883b399d31d934188a36f08ae9e77 to your computer and use it in GitHub Desktop.
Save dixler/d54883b399d31d934188a36f08ae9e77 to your computer and use it in GitHub Desktop.
Deploying comparable classes of AWS and GCP resources
// index.ts
// aws resources
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const aws_bucket = new aws.s3.Bucket("my-bucket");
new aws.s3.BucketObject("my-bucket-object", {
bucket: aws_bucket.bucket,
content: "hello world"
});
const ubuntu = aws.ec2.getAmi({
mostRecent: true,
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
},
{
name: "virtualization-type",
values: ["hvm"],
},
],
owners: ["099720109477"],
});
new aws.ec2.Instance("web", {
ami: ubuntu.then(ubuntu => ubuntu.id),
instanceType: "t3.micro",
tags: {
Name: "HelloWorld",
},
});
const aws_iam_role_example = new aws.iam.Role("example", {assumeRolePolicy: `{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
`});
const example_AmazonEKSClusterPolicy = new aws.iam.RolePolicyAttachment("example-AmazonEKSClusterPolicy", {
policyArn: "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
role: aws_iam_role_example.name,
});
// Optionally, enable Security Groups for Pods
// Reference: https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html
const example_AmazonEKSVPCResourceController = new aws.iam.RolePolicyAttachment("example-AmazonEKSVPCResourceController", {
policyArn: "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController",
role: aws_iam_role_example.name,
});
const mainVpc = new aws.ec2.Vpc("main", {
cidrBlock: "10.0.0.0/16",
});
const subnet1 = new aws.ec2.Subnet("subnet1", {
vpcId: mainVpc.id,
cidrBlock: "10.0.3.0/24",
tags: {
Name: "Main",
},
availabilityZone: "us-east-1a",
});
const subnet2 = new aws.ec2.Subnet("subnet2", {
vpcId: mainVpc.id,
cidrBlock: "10.0.2.0/24",
tags: {
Name: "Main",
},
availabilityZone: "us-east-1b",
});
// eks Cluster
new aws.eks.Cluster("example", {
roleArn: aws_iam_role_example.arn,
vpcConfig: {
subnetIds: [
subnet1.id,
subnet2.id,
],
},
}, {
dependsOn: [
example_AmazonEKSClusterPolicy,
example_AmazonEKSVPCResourceController,
],
});
// gcp resources
import * as gcp from "@pulumi/gcp";
const gcp_bucket = new gcp.storage.Bucket("static-site", {
forceDestroy: true,
location: "us-central1",
});
new gcp.storage.BucketObject("picture", {
bucket: gcp_bucket.id,
content: "hello world"
});
new gcp.compute.Instance("default-instance", {
machineType: "e2-micro",
zone: "us-central1-a",
tags: [
"foo",
"bar",
],
bootDisk: {
initializeParams: {
image: "debian-cloud/debian-11",
labels: {
my_label: "value",
},
},
},
networkInterfaces: [{
network: "default",
accessConfigs: [{}],
}],
});
const name = "helloworld";
const config = new pulumi.Config();
const masterVersion = config.get("masterVersion") ||
gcp.container.getEngineVersions().then(it => it.latestMasterVersion);
// Create a GKE cluster
new gcp.container.Cluster(name, {
// We can't create a cluster with no node pool defined, but we want to only use
// separately managed node pools. So we create the smallest possible default
// node pool and immediately delete it.
initialNodeCount: 1,
minMasterVersion: masterVersion,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment