Skip to content

Instantly share code, notes, and snippets.

View manavskohli's full-sized avatar

Manav Kohli manavskohli

  • San Francisco, CA
View GitHub Profile
@manavskohli
manavskohli / create_ec2_instance.tf
Last active February 12, 2019 00:42
Creates an EC2 Instance Using Terraform
# Docs: https://www.terraform.io/docs/providers/aws/r/s3_bucket.html
resource "aws_s3_bucket" "bucket-identifier" {
bucket = "my-test-bucket"
acl = "private"
tags = {
Name = "A test bucket"
}
}
$ terraform plan
...
+ aws_s3_bucket.bucket-identifier
id: <computed>
acceleration_status: <computed>
acl: "private"
arn: <computed>
bucket: "my-test-bucket"
bucket_domain_name: <computed>
bucket_regional_domain_name: <computed>
@manavskohli
manavskohli / resources_and_data_sources.tf
Created February 12, 2019 00:59
S3 bucket event notification
# resource
"${aws_s3_bucket.bucket-identifier}"
# data source
"${data.aws_s3_bucket.bucket-identifier}"
@manavskohli
manavskohli / data_source.tf
Created February 12, 2019 01:17
Terraform S3 data source
data "aws_s3_bucket" "bucket-identifier" {
bucket = "bucket-name"
}
/src
/.terraform
- archive.tf
- iam.tf
- lambda.tf
- main.tf
- push_to_bucket_1.py
- push_to_bucket_2.py
- s3.tf
- sns.tf
@manavskohli
manavskohli / main.tf
Created February 12, 2019 01:39
Main configuration file
provider "aws" {
version = "~> 1.26.0"
}
@manavskohli
manavskohli / .credentials
Last active February 12, 2019 02:39
Terraform Credentials
export AWS_ACCESS_KEY_ID="ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="SECRET"
export AWS_DEFAULT_REGION="REGION"
@manavskohli
manavskohli / s3.tf
Last active February 14, 2019 18:42
# S3 bucket names should not contain numbers or underscores
resource "aws_s3_bucket" "source-bucket" {
bucket = "source-bucket"
acl = "private"
tags = {
Name = "Source bucket"
}
}
@manavskohli
manavskohli / sns.tf
Last active February 14, 2019 18:41
data "aws_iam_policy_document" "sns_policy" {
statement {
effect = "Allow"
principals {
identifiers = ["*"]
type = "AWS"
}
actions = [
@manavskohli
manavskohli / s3.tf
Last active February 14, 2019 18:41
# ...
resource "aws_s3_bucket_notification" "object_create_sns" {
bucket = "${aws_s3_bucket.source-bucket.id}"
topic {
topic_arn = "${aws_sns_topic.s3_fanout.arn}"
events = ["s3:ObjectCreated:*"]
}
}