Skip to content

Instantly share code, notes, and snippets.

@ashwiniag
Last active November 24, 2019 06:57
Show Gist options
  • Select an option

  • Save ashwiniag/adbf3a5925cdd7c5d94f9a7175e5e170 to your computer and use it in GitHub Desktop.

Select an option

Save ashwiniag/adbf3a5925cdd7c5d94f9a7175e5e170 to your computer and use it in GitHub Desktop.
Create S3 bucket and ECR repo
#Use aws provider and IAM User "name"
provider "aws" {
profile = "name"
region = "eu-west-2"
}
//
##############################################################
# Create S3 input bucket for storing application in zip format.
##############################################################
resource "aws_s3_bucket" "input_bucket-test" {
bucket = "codebuild-eu-west-2-input-bucket-test"
acl = "private"
versioning {
enabled = true
}
tags = {
Name = "input_bucket_test"
}
}
##############################################################
# Create S3 output bucket for storing artifact produced from
#codebuild.
##############################################################
resource "aws_s3_bucket" "output_bucket-test" {
bucket = "codebuild-eu-west-2-output-bucket-test"
acl = "private"
versioning {
enabled = true
}
tags = {
Name = "output_bucket_test"
}
}
#############################################################
#Upload zipped code (object) into input bucket for codebuild
#to use it.
##############################################################
resource "aws_s3_bucket_object" "object" {
bucket = "${aws_s3_bucket.input_bucket-test.id}"
key = "filename.zip"
source = "/path/to/file/filename.zip"
}
##############################################################
# Create ECR repository to store Docker image build in codebuild
##############################################################
resource "aws_ecr_repository" "ecr_repo" {
name = "Repo_name"
}
@ashwiniag

Copy link
Copy Markdown
Author

https://ashwiniag.com for explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment