ENG-1290: Allow creating resources for multiple environments in the same account.#120
ENG-1290: Allow creating resources for multiple environments in the same account.#120TurboNHS wants to merge 15 commits into
Conversation
If we're going to be able to have all resources for multiple environments in one account (PR pending), we must make sure that all resources have the environment name in them, so they can be separated.
The AWSBackup/Framework must be unique in the account. As in, it's not possible to create the framework with the same rules etc. Instead, we "import" the "base" framework, and use that where needed.
…ble.
It was included in the main variable for all types, but Aurora.
With a value of:
```
module "source" {
[...]
backup_plan_config_XXX = {
[...]
"selection_tags" : [
{
"key": "Environment"
"value": var.environment
},
{
"key": "Stack"
"value": "rds-cluster"
},
{
"key": "ManagedBy"
"value": "Terraform"
}
]
[...]
}
[...]
}
```
We narrow down the list of resources that the plan etc will find to
only that of the environment (tag `Environment=dev` for example).
Before this commit, it would only look for `selection_tag=selection_tag_value`,
which would catch all resources with that tag set. One could set
different tags for different environments, but that would be confusing
in the long run. Better to have the same tag for the backup, but specify
the environment as well.
There where two variables for the same thing: * `enable_cross_account_vault_access`. * `enable_cross_account_role_permissions`. Use the latter.. + The IAM role and policy should be created IF we want resources in the same account OR (not AND!) we want cross-account permissions.
Instead, we'll use a `count` on the module in the stack calling it. It's either-or for this - either we create ALL resources, or NONE of them.
Instead, add a `create_framework` in each of the `backup_plan_config*` variables (set to `true`) that controls wether we should create the framework or not. There can only be one framework per account with the specific setup, so if/when we create multiple AWSBackup/Source's in the same account (for multiple environments), then we make sure we create the framework for ONE of the environments.
| default = 5 | ||
| } | ||
|
|
||
| variable "include_environment_in_resource_names" { |
There was a problem hiding this comment.
After speaking to the team, the conclusion we arrived at is that the name_prefix flexibility is the preferred option and we don't want to complicate the code with this variable when that can handle name uniqueness.
| var.backup_plan_config_ebsvol.enable ? data.aws_backup_framework.ebsvol[0].arn : [], | ||
| var.backup_plan_config_dynamodb.enable ? data.aws_backup_framework.dynamodb[0].arn : [], | ||
| var.backup_plan_config_aurora.enable ? data.aws_backup_framework.aurora[0].arn : [], |
There was a problem hiding this comment.
this should be the created framework, otherwise when the enable is set to true and create_framework too it will not be using the created framework.
There was a problem hiding this comment.
Ok, so something like
var.backup_plan_config_XXX.enable && var.backup_plan_config_XXX.create_framework ? aws_backup_framework.XXX[0].arn : []
Like the original code, but just add the .create_framework?
framework_arn_list = flatten(concat(
[aws_backup_framework.main.arn],
var.backup_plan_config_ebsvol.enable ? [aws_backup_framework.ebsvol[0].arn] : [],
var.backup_plan_config_dynamodb.enable ? [aws_backup_framework.dynamodb[0].arn] : [],
var.backup_plan_config_aurora.enable ? [aws_backup_framework.aurora[0].arn] : [],
var.backup_plan_config_parameter_store.enable ? [aws_backup_framework.parameter_store[0].arn] : []
))
There was a problem hiding this comment.
yes, exactly. and the main framework will also have it toggles based on the general backup_plan_config
| data "aws_backup_framework" "main" { | ||
| count = var.backup_plan_config.enable && var.backup_plan_config.create_framework ? 1 : 0 | ||
| name = replace("${local.resource_name_prefix}-framework", "-", "_") | ||
| } |
There was a problem hiding this comment.
This data block is attempting to read existing information in the account, this means there will be resource reusing across the sub-environments which we agreed we wouldn't support.
Environments where the framework isn't being created, just won't have a framework attached to the plan
There was a problem hiding this comment.
That's fine, it's actually only used in the locals, which you commented on above.
Description
If there's multiple environment builds in the same account (such as dev, test, non-prod etc), we can't create ALL resources in that account.
Plans and frameworks are account specific, not environment specific.
As in, a plan will have a selection (such as "backup everything with the tag xyz set to abc"). So having separate plans for each env doesn make any sense, they will be identical and backup the same resources.
So introduce a new variable resources_in_same_account which should be set to the account where everything (the "account specific" resources) are created.
Depends on: include_environment_in_resource_names = true.
Depends on: #118
NOTE: In this PR, the #118 PR is included, because it builds on that! That PR needs to be merged before this, which should then be rebased to remove that first commit, before this PR can be merged.
Context
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.