Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit c0bf1bc

Browse files
author
twistedgrim
committed
Terraform 0.12 upgrade
1 parent 742258e commit c0bf1bc

25 files changed

+225
-153
lines changed

modules/backup/examples/all_options.tf

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module "backup" {
3333
},
3434
]
3535
selection_name = "fullSelectionName"
36+
3637
# Vault
3738
vault_name = "newVault"
3839
plan_tags = {
@@ -42,6 +43,7 @@ module "backup" {
4243
schedule = "cron(0 12 * * ? *)"
4344
start_window = 240
4445
completion_window = 600
46+
4547
# Use Lifecycle Cold Storage
4648
use_lifecycle = true
4749
lifecycle = {
@@ -54,6 +56,8 @@ module "backup" {
5456
vault_tags = {
5557
vault_tag = "vault_tag_value"
5658
}
59+
5760
# Using a custom KMS key for encryption
5861
kms_key_arn = "arn:aws:kms:us-west-2:<account>:key/e267ea23-9d4d-a24e-247bc44f5fae"
5962
}
63+

modules/backup/examples/backup_default_role.tf

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ locals {
1414
module "backup" {
1515
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-backup//modules/backup/?ref=v0.0.3"
1616

17-
environment = "${local.tags["Environment"]}"
17+
environment = local.tags["Environment"]
1818

1919
lifecycle = {
2020
delete_after = 35
2121
}
2222

2323
lifecycle_enable = true
24-
plan_name = "${local.plan_name}"
25-
plan_tags = "${local.tags}"
24+
plan_name = local.plan_name
25+
plan_tags = local.tags
2626
rule_name = "Daily"
2727
schedule = "cron(0 5 ? * * *)"
2828
selection_name = "fullSelectionName"
@@ -31,11 +31,12 @@ module "backup" {
3131
{
3232
type = "STRINGEQUALS"
3333
key = "BackupPlan"
34-
value = "${local.plan_name}"
34+
value = local.plan_name
3535
},
3636
]
3737

3838
start_window = 60
3939
vault_name = "${local.tags["Environment"]}-Vault"
40-
vault_tags = "${local.tags}"
40+
vault_tags = local.tags
4141
}
42+

modules/backup/examples/backup_default_role_efs.tf

+11-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ locals {
1414
module "efs" {
1515
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-efs//?ref=v0.0.8"
1616

17-
custom_tags = "${merge(
17+
custom_tags = merge(
1818
local.tags,
19-
map("BackupPlan", "${local.plan_name}")
20-
)}"
19+
{
20+
"BackupPlan" = local.plan_name
21+
},
22+
)
2123

2224
name = "${local.tags["Environment"]}-EFS"
2325
security_groups = ["sg-1234567890abcdef1"]
@@ -28,16 +30,16 @@ module "backup" {
2830
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-backup//modules/backup/?ref=v0.0.3"
2931

3032
completion_window = 300
31-
environment = "${local.tags["Environment"]}"
33+
environment = local.tags["Environment"]
3234

3335
lifecycle = {
3436
cold_storage_after = 30
3537
delete_after = 120
3638
}
3739

3840
lifecycle_enable = true
39-
plan_name = "${local.plan_name}"
40-
plan_tags = "${local.tags}"
41+
plan_name = local.plan_name
42+
plan_tags = local.tags
4143
rule_name = "Daily"
4244
schedule = "cron(0 5 ? * * *)"
4345
selection_name = "fullSelectionName"
@@ -46,11 +48,12 @@ module "backup" {
4648
{
4749
type = "STRINGEQUALS"
4850
key = "BackupPlan"
49-
value = "${local.plan_name}"
51+
value = local.plan_name
5052
},
5153
]
5254

5355
start_window = 60
5456
vault_name = "${local.tags["Environment"]}-Vault"
55-
vault_tags = "${local.tags}"
57+
vault_tags = local.tags
5658
}
59+

modules/backup/main.tf

+24-29
Original file line numberDiff line numberDiff line change
@@ -40,52 +40,47 @@
4040

4141
locals {
4242
tags = {
43-
Environment = "${var.environment}"
43+
Environment = var.environment
4444
ServiceProvider = "Rackspace"
4545
}
4646

47-
plan_tags = "${merge(
48-
local.tags,
49-
var.plan_tags
50-
)}"
47+
plan_tags = merge(local.tags, var.plan_tags)
5148

52-
vault_tags = "${merge(
53-
local.tags,
54-
var.vault_tags
55-
)}"
49+
vault_tags = merge(local.tags, var.vault_tags)
5650
}
5751

5852
module "vault" {
5953
source = "../vault"
6054

61-
kms_key_arn = "${var.kms_key_arn}"
62-
tags = "${local.vault_tags}"
63-
vault_name = "${var.vault_name}"
55+
kms_key_arn = var.kms_key_arn
56+
tags = local.vault_tags
57+
vault_name = var.vault_name
6458
}
6559

6660
module "plan" {
6761
source = "../plan"
6862

69-
completion_window = "${var.completion_window}"
70-
lifecycle = "${var.lifecycle}"
71-
lifecycle_enable = "${var.lifecycle_enable}"
72-
plan_name = "${var.plan_name}"
73-
recovery_point_tags = "${var.recovery_point_tags}"
74-
rule_name = "${var.rule_name}"
75-
schedule = "${var.schedule}"
76-
start_window = "${var.start_window}"
77-
tags = "${local.plan_tags}"
78-
target_vault_name = "${module.vault.vault_name}"
63+
completion_window = var.completion_window
64+
lifecycle = var.lifecycle
65+
lifecycle_enable = var.lifecycle_enable
66+
plan_name = var.plan_name
67+
recovery_point_tags = var.recovery_point_tags
68+
rule_name = var.rule_name
69+
schedule = var.schedule
70+
start_window = var.start_window
71+
tags = local.plan_tags
72+
target_vault_name = module.vault.vault_name
7973
}
8074

8175
module "selection" {
8276
source = "../selection"
8377

84-
create_iam_role = "${var.create_iam_role}"
85-
iam_role_arn = "${var.iam_role_arn}"
86-
iam_role_name = "${var.iam_role_name}"
87-
plan_id = "${module.plan.plan_id}"
88-
selection_name = "${var.selection_name}"
89-
resources = "${var.resources}"
90-
selection_tag = "${var.selection_tag}"
78+
create_iam_role = var.create_iam_role
79+
iam_role_arn = var.iam_role_arn
80+
iam_role_name = var.iam_role_name
81+
plan_id = module.plan.plan_id
82+
selection_name = var.selection_name
83+
resources = var.resources
84+
selection_tag = var.selection_tag
9185
}
86+

modules/backup/outputs.tf

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
output "backup_iam_role_arn" {
22
description = "ARN for given IAM Role or newly created IAM Role."
3-
value = "${module.selection.backup_iam_role_arn}"
3+
value = module.selection.backup_iam_role_arn
44
}
55

66
output "plan_arn" {
77
description = "Plan ARN."
8-
value = "${module.plan.plan_arn}"
8+
value = module.plan.plan_arn
99
}
1010

1111
output "plan_id" {
1212
description = "Plan ID"
13-
value = "${module.plan.plan_id}"
13+
value = module.plan.plan_id
1414
}
1515

1616
output "plan_version" {
1717
description = "Unique, randomly generated, Unicode, UTF-8 encoded string that serves as the version ID of the backup plan."
18-
value = "${module.plan.plan_version}"
18+
value = module.plan.plan_version
1919
}
2020

2121
output "selection_id" {
2222
description = "Backup Selection identifier."
23-
value = "${module.selection.selection_id}"
23+
value = module.selection.selection_id
2424
}
2525

2626
output "vault_arn" {
2727
description = "The ARN of the vault."
28-
value = "${module.vault.vault_arn}"
28+
value = module.vault.vault_arn
2929
}
3030

3131
output "vault_name" {
3232
description = "The name of the vault."
33-
value = "${module.vault.vault_name}"
33+
value = module.vault.vault_name
3434
}
3535

3636
output "vault_recovery_points" {
3737
description = "The number of recovery points that are stored in a backup vault."
38-
value = "${module.vault.vault_recovery_points}"
38+
value = module.vault.vault_recovery_points
3939
}
40+

modules/backup/variables.tf

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
variable "completion_window" {
22
description = "The amount of time AWS Backup attempts a backup before canceling the job and returning an error. Defaults to 8 hours. Completion windows only apply to EFS backups."
3-
type = "string"
3+
type = string
44
default = 480
55
}
66

77
variable "create_iam_role" {
88
description = "Create a new IAM role that AWS Backup uses to authenticate when backing up the target resource(s) using the default policy, `AWSBackupServiceRolePolicyForBackup`. Setting this to `true` must be accompanied by `iam_role_name`. If this is `false` and both `iam_role_arn` and `iam_role_name` are empty the module will attempt to use the default AWS Backup role, `AWSBackupDefaultServiceRole`."
9-
type = "string"
9+
type = string
1010
default = false
1111
}
1212

1313
variable "environment" {
1414
description = "Application environment for which these resources are being created, e.g. Production, Development, etc."
15-
type = "string"
15+
type = string
1616
default = "Development"
1717
}
1818

1919
variable "iam_role_arn" {
2020
description = "Optional, the ARN of an existing IAM role that AWS Backup uses to authenticate when backing up the target resource(s). Must have the appropriate permissions for the target(s) and AWS Backup."
21-
type = "string"
21+
type = string
2222
default = ""
2323
}
2424

2525
variable "iam_role_name" {
2626
description = "Optional, the name for the IAM Role to be created if setting `create_iam_role` to `true`."
27-
type = "string"
27+
type = string
2828
default = ""
2929
}
3030

3131
variable "kms_key_arn" {
3232
description = "Optional server-side KMS encryption key that is used to protect your backups. If this is not provided AWS Backup will use a default aws:kms key for this service."
33-
type = "string"
33+
type = string
3434
default = ""
3535
}
3636

@@ -42,53 +42,54 @@ variable "lifecycle" {
4242
See [examples](./examples).
4343
EOF
4444

45-
type = "map"
45+
46+
type = map(string)
4647
default = {}
4748
}
4849

4950
variable "lifecycle_enable" {
5051
description = "Set to `true` if an input was provided for variable `lifecycle`."
51-
type = "string"
52+
type = string
5253
default = false
5354
}
5455

5556
variable "plan_name" {
5657
description = "The display name of the backup plan."
57-
type = "string"
58+
type = string
5859
}
5960

6061
variable "plan_tags" {
6162
description = "Map of tags to assign to created plan."
62-
type = "map"
63+
type = map(string)
6364
default = {}
6465
}
6566

6667
variable "recovery_point_tags" {
6768
description = "Map of tags to assign to created recovery points. Note that changes to this variable once set will require the rule to be deleted due to Terraform providers issues [8431](https://github.com/terraform-providers/terraform-provider-aws/issues/8431) and [8737](https://github.com/terraform-providers/terraform-provider-aws/issues/8737)."
68-
type = "map"
69+
type = map(string)
6970
default = {}
7071
}
7172

7273
variable "resources" {
7374
description = "Optional list of strings that either contain Amazon Resource Names (ARNs) or match patterns of resources to assign to a backup plan. Must use `selection_tag` and/or `resources`. i.e ['arn:aws:ec2:us-east-1:123456789012:volume/','arn:aws:ec2:us-east-1:56789012234:volume/']"
74-
type = "list"
75+
type = list(string)
7576
default = []
7677
}
7778

7879
variable "rule_name" {
7980
description = "A display name for the backup rule."
80-
type = "string"
81+
type = string
8182
}
8283

8384
variable "schedule" {
8485
description = "A CRON expression specifying when AWS Backup initiates a backup job. Default is 05:00 UTC every day. Consult https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html for expression help."
85-
type = "string"
86+
type = string
8687
default = "cron(0 5 ? * * *)"
8788
}
8889

8990
variable "selection_name" {
9091
description = "The display name of the resource selection document."
91-
type = "string"
92+
type = string
9293
}
9394

9495
variable "selection_tag" {
@@ -100,24 +101,26 @@ variable "selection_tag" {
100101
See [examples](./examples).
101102
EOF
102103

103-
type = "list"
104+
105+
type = list(string)
104106
default = []
105107
}
106108

107109
variable "start_window" {
108110
description = "The amount of time in minutes after a backup is scheduled before a job is canceled if it doesn't start successfully. Minimum and Default value is 60. Max is 720 (12 Hours)."
109-
type = "string"
111+
type = string
110112
default = 60
111113
}
112114

113115
variable "vault_name" {
114116
description = "Name of the backup vault to create."
115-
type = "string"
117+
type = string
116118
}
117119

118120
variable "vault_tags" {
119121
description = "Map of tags to assign to created vault."
120122

121-
type = "map"
123+
type = map(string)
122124
default = {}
123125
}
126+

modules/iam_default/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ resource "aws_iam_role" "backup_service" {
2525
name = "AWSBackupDefaultServiceRole"
2626
description = "Provides AWS Backup permission to create backups and perform restores on your behalf across AWS services."
2727
path = "/service-role/"
28-
assume_role_policy = "${data.aws_iam_policy_document.backup_assume.json}"
28+
assume_role_policy = data.aws_iam_policy_document.backup_assume.json
2929
}
3030

3131
resource "aws_iam_role_policy_attachment" "backup" {
32-
role = "${aws_iam_role.backup_service.name}"
32+
role = aws_iam_role.backup_service.name
3333
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
3434
}
3535

3636
resource "aws_iam_role_policy_attachment" "restore" {
37-
role = "${aws_iam_role.backup_service.name}"
37+
role = aws_iam_role.backup_service.name
3838
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores"
3939
}

0 commit comments

Comments
 (0)