Skip to content

Instantly share code, notes, and snippets.

@chalfant
Created December 9, 2015 01:37
Show Gist options
  • Save chalfant/3317cda18aace01bead5 to your computer and use it in GitHub Desktop.
Save chalfant/3317cda18aace01bead5 to your computer and use it in GitHub Desktop.
Use this CloudFormation to setup a new AWS account for CloudTrail, billing reports, and cross-account delegated IAM access
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Creates resources for brand new aws account",
"Parameters": {
"AccountName": {
"Description": "Name for AWS account",
"Type": "String"
},
"AccountId": {
"Description": "Numeric AWS Account ID of new account",
"Type": "String"
},
"DelegateAccountId": {
"Description": "Numeric AWS Account ID of existing account to which you are granting access",
"Type": "String"
}
},
"Resources": {
"BillingBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"BucketName": {
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"billing"
]
]
}
}
},
"BillingBucketPolicy": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "BillingBucket"
},
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::386209384616:root"
},
"Action": [
"s3:GetBucketAcl",
"s3:GetBucketPolicy"
],
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"billing"
]
]
}
]
]
}
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::386209384616:root"
},
"Action": [
"s3:PutObject"
],
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"billing"
]
]
},
"/*"
]
]
}
}
]
}
}
},
"CloudTrailBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"BucketName": {
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"cloudtrail"
]
]
}
}
},
"CloudTrailBucketPolicy": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "CloudTrailBucket"
},
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"cloudtrail"
]
]
}
]
]
}
},
{
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"cloudtrail"
]
]
},
"/*"
]
]
}
]
}
]
}
}
},
"CloudTrailSetup": {
"Type": "AWS::CloudTrail::Trail",
"DeletionPolicy": "Retain",
"Properties": {
"IncludeGlobalServiceEvents": true,
"IsLogging": true,
"S3BucketName": {
"Ref": "CloudTrailBucket"
}
}
},
"DevOpsBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": {
"Fn::Join": [
"-",
[
{
"Ref": "AccountName"
},
"devops"
]
]
}
}
},
"CrossAccountAccessRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": {
"Fn::Join": [
"",
[
"arn:aws:iam::",
{
"Ref": "DelegateAccountId"
},
":root"
]
]
}
},
"Action": "sts:AssumeRole"
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/AdministratorAccess"
]
}
}
}
}
@felipe1982
Copy link

how does this configure billing reports? the word report appears nowhere in this template.

@sysboss
Copy link

sysboss commented Dec 7, 2018

Not sure it is possible to enable billing reports via CloudFormation template.

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