|
| 1 | +# Upgrade from v3.x to v4.x |
| 2 | + |
| 3 | +If you have any questions regarding this upgrade process, please consult the [`examples/`](https://github.com/terraform-aws-modules/terraform-aws-kms/tree/master/examples) projects: |
| 4 | + |
| 5 | +If you find a bug, please open an issue with supporting configuration to reproduce. |
| 6 | + |
| 7 | +## List of backwards incompatible changes |
| 8 | + |
| 9 | +- Support for Terraform `<1.5.7` has been dropped; `1.5.7` is now the minimum supported version |
| 10 | +- Terraform AWS provider minimum version is now `v6.0.0` in order to support the `region` argument in resources |
| 11 | +- Variable `key_statements.conditions` is now `key_statements.condition` |
| 12 | +- Variable `grants.constraints` has changed to type list |
| 13 | + |
| 14 | +## Additional changes |
| 15 | + |
| 16 | +### Added |
| 17 | + |
| 18 | +- `region` to support creating resources in a different region than the provider region |
| 19 | + |
| 20 | +### Modified |
| 21 | + |
| 22 | +- `key_statements.conditions` changed to `key_statements.condition` |
| 23 | +- `grants.constrants` changed to type list |
| 24 | + |
| 25 | +### Variable and output changes |
| 26 | + |
| 27 | +1. Removed variables: |
| 28 | + |
| 29 | + - None |
| 30 | + |
| 31 | +2. Renamed variables: |
| 32 | + |
| 33 | + - `key_statements.conditions` -> `key_statements.condition` |
| 34 | + |
| 35 | +3. Added variables: |
| 36 | + |
| 37 | + - `region` |
| 38 | + |
| 39 | +4. Removed outputs: |
| 40 | + |
| 41 | + - None |
| 42 | + |
| 43 | +5. Renamed outputs: |
| 44 | + |
| 45 | + - None |
| 46 | + |
| 47 | +6. Added outputs: |
| 48 | + |
| 49 | + - `key_region` added to support output for setting the `region` variable |
| 50 | + |
| 51 | +## Upgrade Migrations |
| 52 | + |
| 53 | +The following examples demonstrate some of the changes that users can elect to make to avoid any potential disruptions when upgrading. |
| 54 | + |
| 55 | +### Before 3.x Example |
| 56 | + |
| 57 | +```hcl |
| 58 | +module "kms" { |
| 59 | + source = "terraform-aws-modules/rds/aws" |
| 60 | + version = "~> 3.0" |
| 61 | +
|
| 62 | + # Only the affected attributes are shown |
| 63 | + key_statements = [ |
| 64 | + { |
| 65 | + sid = "CloudWatchLogs" |
| 66 | + actions = [ |
| 67 | + "kms:Encrypt*", |
| 68 | + "kms:Decrypt*", |
| 69 | + "kms:ReEncrypt*", |
| 70 | + "kms:GenerateDataKey*", |
| 71 | + "kms:Describe*" |
| 72 | + ] |
| 73 | + resources = ["*"] |
| 74 | +
|
| 75 | + principals = [ |
| 76 | + { |
| 77 | + type = "Service" |
| 78 | + identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"] |
| 79 | + } |
| 80 | + ] |
| 81 | +
|
| 82 | + conditions = [ |
| 83 | + { |
| 84 | + test = "ArnLike" |
| 85 | + variable = "kms:EncryptionContext:aws:logs:arn" |
| 86 | + values = [ |
| 87 | + "arn:aws:logs:${local.region}:${data.aws_caller_identity.current.account_id}:log-group:*", |
| 88 | + ] |
| 89 | + } |
| 90 | + ] |
| 91 | + } |
| 92 | + ] |
| 93 | +
|
| 94 | + # Grants |
| 95 | + grants = { |
| 96 | + lambda = { |
| 97 | + grantee_principal = aws_iam_role.lambda.arn |
| 98 | + operations = ["Encrypt", "Decrypt", "GenerateDataKey"] |
| 99 | + constraints = { |
| 100 | + encryption_context_equals = { |
| 101 | + Department = "Finance" |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +
|
| 107 | + tags = local.tags |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### After 4.x Example |
| 112 | + |
| 113 | +```hcl |
| 114 | +module "kms" { |
| 115 | + source = "terraform-aws-modules/rds/aws" |
| 116 | + version = "~> 4.0" |
| 117 | +
|
| 118 | + key_statements = [ |
| 119 | + { |
| 120 | + sid = "CloudWatchLogs" |
| 121 | + actions = [ |
| 122 | + "kms:Encrypt*", |
| 123 | + "kms:Decrypt*", |
| 124 | + "kms:ReEncrypt*", |
| 125 | + "kms:GenerateDataKey*", |
| 126 | + "kms:Describe*" |
| 127 | + ] |
| 128 | + resources = ["*"] |
| 129 | +
|
| 130 | + principals = [ |
| 131 | + { |
| 132 | + type = "Service" |
| 133 | + identifiers = ["logs.${local.region}.amazonaws.com"] |
| 134 | + } |
| 135 | + ] |
| 136 | +
|
| 137 | + condition = [ |
| 138 | + { |
| 139 | + test = "ArnLike" |
| 140 | + variable = "kms:EncryptionContext:aws:logs:arn" |
| 141 | + values = [ |
| 142 | + "arn:aws:logs:${local.region}:${local.account_id}:log-group:*", |
| 143 | + ] |
| 144 | + } |
| 145 | + ] |
| 146 | + } |
| 147 | + ] |
| 148 | +
|
| 149 | + # Grants |
| 150 | + grants = { |
| 151 | + lambda = { |
| 152 | + grantee_principal = aws_iam_role.lambda.arn |
| 153 | + operations = ["Encrypt", "Decrypt", "GenerateDataKey"] |
| 154 | + constraints = [{ |
| 155 | + encryption_context_equals = { |
| 156 | + Department = "Finance" |
| 157 | + } |
| 158 | + }] |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | +``` |
0 commit comments