Created
December 9, 2015 01:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
] | |
} | |
} | |
} | |
} |
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
how does this configure billing reports? the word report appears nowhere in this template.