Skip to content

Instantly share code, notes, and snippets.

@anneakin
anneakin / packer_provisioners.json
Created May 23, 2020 01:36
Provisioners section of Packer file
"provisioners": [
{
"type": "shell",
"inline": [
"sleep 30",
"sudo yum update -y",
"sudo amazon-linux-extras install epel -y",
"sudo yum install s3fs-fuse -y"
]
}
@anneakin
anneakin / packer_builders.json
Created May 23, 2020 01:34
Builders section of Packer JSON
"builders": [
{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "amzn2-ami-hvm-2.0.20200207.1-x86_64-gp2",
@anneakin
anneakin / packer_variables.json
Last active May 23, 2020 01:33
Variables section of Packer file
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
@anneakin
anneakin / outputs.tf
Created May 23, 2020 01:22
Terraform sandbox outputs file
output "ec2_public_ip" {
value = "${aws_instance.user_ec2_instance.public_ip}"
}
output "ec2_private_ip" {
value = "${aws_instance.user_ec2_instance.private_ip}"
}
@anneakin
anneakin / main.tf
Created May 23, 2020 01:20
Terraform resources for sandbox
provider "aws" {
profile = "default"
region = "us-east-1"
}
resource "aws_s3_bucket" "user_s3_bucket" {
bucket = "${var.username}-s3-bucket"
}
resource "aws_iam_role" "ec2_iam_role" {
@anneakin
anneakin / variables.tf
Created May 23, 2020 01:19
Terraform sandbox variables
variable "username" {}
variable "user_key" {}
variable "subnet_id" {}
@anneakin
anneakin / aws_cfn_ec2_userdata.yml
Created May 23, 2020 01:11
EC2 Instance resource with User Data
UserEc2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
IamInstanceProfile: !Ref EC2IamInstanceProfile
ImageId: ami-0a887e401f7654935
KeyName: !Ref UserKey
SubnetId: !Ref Subnet
Tags:
-
@anneakin
anneakin / aws_cfn_sandbox_policy.yml
Created May 23, 2020 01:07
Policy document for EC2 IAM role
PolicyName: DestinationBucketAccessPolicy
PolicyDocument:
Version: '2012–10–17'
Statement:
- Effect: Allow
Action:
- s3:ListBucket
- s3:DeleteObject
- s3:GetObject
- s3:PutObject
@anneakin
anneakin / aws_cfn_sandbox_outputs.yml
Created May 23, 2020 00:49
AWS CloudFormation Outputs
Outputs:
EC2PrivateIp:
Description: Private IP address of EC2 instance created in stack.
Value: !GetAtt UserEc2Instance.PrivateIp
EC2PublicIp:
Description: Public IP address of EC2 instance created in stack.
Value: !GetAtt UserEc2Instance.PublicIp
@anneakin
anneakin / aws_cfn_sandbox_resources.yml
Last active May 23, 2020 01:12
AWS CloudFormation Resources
Resources:
UserS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Join [ '-', [ !Ref Username, 's3-bucket' ] ]
EC2IamRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join [ '-', [ !Ref Username, 'ec2-iam-role' ] ]