Policies

You can have four types of policies in your AWS organization: service control policies, tag policies, backup policies, and AI services opt-out policies. You can use Takomo to manage all of these.

Policy files

You use policy files to store the policies you want to deploy to your AWS organization. Each policy type has its own directory from where Takomo looks for the policies.

Policy typeDirectory

Service control policies

service-control-policies

Tag policies

tag-policies

Backup policies

backup-policies

AI services opt-out policies

ai-services-opt-out-policies

Example

Here's an example of a service control policy that denies everything from regions that are not explicitly allowed. Because it's a service control policy, it needs to be placed into the service-control-policies directory.

organization/service-control-policies/restrict-by-regions.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyAllOutsideAllowedRegions",
      "Effect": "Deny",
      "Action": "*",
      "Resource": "*",
      "Condition": {
        "StringNotEquals": {
          "aws:RequestedRegion": [
            "us-east-1",
            "eu-central-1",
            "eu-west-1",
            "eu-west-2",
            "eu-west-3",
            "eu-north-1"
          ]
        }
      }
    }
  ]
}

Declaring policies

Once you have policy files in the correct directories, you can declare them in the organization configuration. Each policy type has its own property under which you declare the policies.

Policy typeProperty

Service control policies

serviceControlPolicies

Tag policies

tagPolicies

Backup policies

backupPolicies

AI services opt-out policies

aiServicesOptOutPolicies

Each of the above are objects whose keys are policy names and values are configuration for the corresponding policy. The policy name is the file name of the policy file, excluding the file extension.

Example

Here's how you would declare the service control policy we created in the previous example:

organization/organization.yml
masterAccountId: "098765432100"

# Use serviceControlPolicies property 
# to specify service control policies
serviceControlPolicies:
  restrict-by-regions:
    description: Restrict regions
    
organizationalUnits:
  Root:
    accounts:
      - "098765432100"
  Root/Workloads/Dev: {}
  Root/Workloads/Test: {}
  Root/Workloads/Prod: 
    accounts:
      - id: "876754648373"
        name: MyAccount
        email: account@example.com
        description: This is a production account
  Root/Sandbox:
    accounts:
      - "123456789012"
      - "448873940474"     

AWS managed policies

There is a default service control policy named FullAWSAccess which is managed by AWS. You can't provide your own policy with this name. You can still use this policy with your organizational units and accounts by declaring it with awsManaged: true. Because AWS manages the policy, you don't need to provide a policy file for it.

Example

Here's how you declare the AWS managed policy:

organization/organization.yml
masterAccountId: "098765432100"

serviceControlPolicies:
  restrict-by-regions:
    description: Restrict regions
    
  # This is the AWS managed default service control policy
  FullAWSAccess:
    description: AWS managed default policy
    awsManaged: true
    
organizationalUnits:
  Root:
    accounts:
      - "098765432100"
  Root/Workloads/Dev: {}
  Root/Workloads/Test: {}
  Root/Workloads/Prod: 
    accounts:
      - id: "876754648373"
        name: MyAccount
        email: account@example.com
        description: This is a production account
  Root/Sandbox:
    accounts:
      - "123456789012"
      - "448873940474" 

Attaching policies

You can attach declared policies to OUs and accounts with the following properties.

Policy typeProperty

Service control policies

serviceControlPolicies

Tag policies

tagPolicies

Backup policies

backupPolicies

AI services opt-out policies

aiServicesOptOutPolicies

Each of them accepts a single policy name or a list of policy names. Service control policies behave differently than others policies. If you attach a service control policy to an OU, it is also attached automatically to all OUs and accounts under that OU. If you attach any other policy to an OU, the policy is not attached to OUs and accounts under the first OU, but they inherit the policy instead.

Example

Let's add one backup policy named MyBackups and attach it directly to account 123456789012. Then, we attach the AWS managed default service control policy FullAWSAccess to Root OU, so it will be inherited by all OUs and accounts in the organization. Finally, we want our workload accounts under Root/Workloads OU to be restricted to use only the allowed regions, so we attach the restrict-by-regions policy to it.

organization/organization.yml
masterAccountId: "098765432100"

serviceControlPolicies:
  restrict-by-regions:
    description: Restrict regions
  FullAWSAccess:
    description: AWS managed default policy
    awsManaged: true
    
backupPolicies:
  MyBackups:
    description: Backup policy    
    
organizationalUnits:
  Root:
    serviceControlPolicies: FullAWSAccess
    accounts:
      - "098765432100"
  Root/Workloads:
    serviceControlPolicies: restrict-by-regions
  Root/Workloads/Dev: {}
  Root/Workloads/Test: {}
  Root/Workloads/Prod: 
    accounts:
      - id: "876754648373"
        name: MyAccount
        email: account@example.com
        description: This is a production account
  Root/Sandbox:
    accounts:
      - id: "123456789012"
        backupPolicies:
          - MyBackups
      - "448873940474"

Last updated