Skip to content

Commit d816cee

Browse files
committed
chore: added more examples about on how modify the policy items
1 parent 4d78d3f commit d816cee

File tree

1 file changed

+155
-2
lines changed

1 file changed

+155
-2
lines changed

website/docs/r/cloud_provider_snapshot_backup_policy.html.markdown

+155-2
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,23 @@ resource "mongodbatlas_cloud_provider_snapshot_backup_policy" "test" {
4848
retention_unit = "days"
4949
retention_value = 1
5050
}
51+
5152
policy_item {
5253
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.1.id
5354
frequency_interval = 1
5455
frequency_type = "daily"
5556
retention_unit = "days"
5657
retention_value = 2
5758
}
59+
5860
policy_item {
5961
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.2.id
6062
frequency_interval = 4
6163
frequency_type = "weekly"
6264
retention_unit = "weeks"
6365
retention_value = 3
6466
}
67+
6568
policy_item {
6669
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.3.id
6770
frequency_interval = 5
@@ -72,8 +75,11 @@ resource "mongodbatlas_cloud_provider_snapshot_backup_policy" "test" {
7275
}
7376
}
7477
```
78+
# Examples Modifying Polices
79+
When Cloud Backup is enabled for a cluster MongoDB Atlas automatically creates a default Cloud Backup schedule for the cluster with four policy items; hourly, daily, weekly, and monthly. Because of this default creation this provider automatically saves the Cloud Backup Snapshot Policy into the Terraform state. If the default works well for you then you do not need to do anything other than create a cluster with Cloud Backup enabled and your Terraform state will have this information if you need it. However, if you want the policy to be different than the default simply follow the next examples.
7580

76-
## Example Usage implementing at least one Policy Item
81+
## Example Usage - Create a Cluster and Modify the 4 Default Policies Simultaneously
82+
This cluster has already been created and is here as an example
7783

7884
```hcl
7985
resource "mongodbatlas_cluster" "my_cluster" {
@@ -104,15 +110,162 @@ resource "mongodbatlas_cloud_provider_snapshot_backup_policy" "test" {
104110
105111
policy_item {
106112
id = 5f0747cad187d8609a72f546
113+
frequency_interval = 4
114+
frequency_type = "weekly"
115+
retention_unit = "days"
116+
retention_value = 3
117+
}
118+
}
119+
}
120+
```
121+
122+
-> **NOTE:** This is the id MongoDB Atlas returns for the policy item we want to keep. Here it is hard coded because you need to either use the actual value from the Terraform state or look to map the policy item you want to keep to it's placement in the state file array that was imported in when the cluster was originally created.
123+
124+
Summarized: to use the state file value for a policy item you need to determine the array placement # of the same frequency_type you want to keep. With this Terraform configuration the anothers policy items will be removed.
125+
126+
~> **IMPORTANT:** For example in the state file we are using the weekly policy is the third policy in the array so it could be referred to with `mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.2.id` instead of the hard coded value, but it's not recommended when the cluster presents changes or make `terraform refresh` due to once this will applied, the cluster state will remove the rest of the items, so the posicion of the array will change to position 0.
127+
128+
## Example Usage - Create a Cluster and Modify 3 Default Policies and Remove 1 Default Policy Simultaneously
129+
130+
```hcl
131+
resource "mongodbatlas_cluster" "my_cluster" {
132+
project_id = "<PROJECT-ID>"
133+
name = "clusterTest"
134+
disk_size_gb = 5
135+
136+
//Provider Settings "block"
137+
provider_name = "AWS"
138+
provider_region_name = "EU_CENTRAL_1"
139+
provider_instance_size_name = "M10"
140+
provider_backup_enabled = true // must be enabled in order to use cloud_provider_snapshot_backup_policy resource
141+
provider_disk_iops = 100
142+
provider_encrypt_ebs_volume = false
143+
}
144+
145+
resource "mongodbatlas_cloud_provider_snapshot_backup_policy" "test" {
146+
project_id = mongodbatlas_cluster.my_cluster.project_id
147+
cluster_name = mongodbatlas_cluster.my_cluster.name
148+
149+
reference_hour_of_day = 3
150+
reference_minute_of_hour = 45
151+
restore_window_days = 4
152+
153+
154+
policies {
155+
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.id
156+
157+
policy_item {
158+
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.0.id
107159
frequency_interval = 1
108160
frequency_type = "hourly"
109161
retention_unit = "days"
110162
retention_value = 1
111163
}
164+
165+
policy_item {
166+
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.1.id
167+
frequency_interval = 1
168+
frequency_type = "daily"
169+
retention_unit = "days"
170+
retention_value = 2
171+
}
172+
173+
# Item removed
174+
# policy_item {
175+
# id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.2.id
176+
# frequency_interval = 4
177+
# frequency_type = "weekly"
178+
# retention_unit = "weeks"
179+
# retention_value = 3
180+
# }
181+
182+
policy_item {
183+
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.3.id
184+
frequency_interval = 5
185+
frequency_type = "monthly"
186+
retention_unit = "months"
187+
retention_value = 4
188+
}
112189
}
113190
}
114191
```
115-
-> **NOTE:** By default, MongoDB Atlas automatically creates a four schedule for each cluster if you want to remove and keep at least one, you can implement the above example. When the cluster is created, we need to note that `snapshot_backup_policy` information is created in its state as well, so you can choose the `policy_item` that you want to keep or remove before creating the `mongodbatlas_cloud_provider_snapshot_backup_policy` resource.Also, if the `mongodbatlas_cloud_provider_snapshot_backup_policy` resource has been created with its four default schedules, you can remove the policy is needed just removing it on the configuration.
192+
193+
-> **NOTE:** (See text in first example for more details on the default.) If you want the Cloud Backup Snapshot Policy to vary in the number of policies from the default when creating the cluster, perhaps you want to remove one policy item and modify the remaining three, simply follow this example here to remove a policy and modify three.
194+
195+
~> **IMPORTANT:** If we decide to remove item 2 as our above example marked with `#` we need to consider that once the cluster being modified or makes a `terraform refresh` the item 2 will be replaced with the 3, so it could cause inconsistency. We recommend using hardcoded id value to handle these situations. (See text in the first example for more details on it)
196+
197+
198+
199+
## Example Usage - Remove 3 Default Policies Items After the Cluster Has Already Been Created
200+
201+
```hcl
202+
resource "mongodbatlas_cluster" "my_cluster" {
203+
project_id = "<PROJECT-ID>"
204+
name = "clusterTest"
205+
disk_size_gb = 5
206+
207+
//Provider Settings "block"
208+
provider_name = "AWS"
209+
provider_region_name = "EU_CENTRAL_1"
210+
provider_instance_size_name = "M10"
211+
provider_backup_enabled = true // must be enabled in order to use cloud_provider_snapshot_backup_policy resource
212+
provider_disk_iops = 100
213+
provider_encrypt_ebs_volume = false
214+
}
215+
216+
resource "mongodbatlas_cloud_provider_snapshot_backup_policy" "test" {
217+
project_id = mongodbatlas_cluster.my_cluster.project_id
218+
cluster_name = mongodbatlas_cluster.my_cluster.name
219+
220+
reference_hour_of_day = 3
221+
reference_minute_of_hour = 45
222+
restore_window_days = 4
223+
224+
225+
policies {
226+
id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.id
227+
228+
# Item removed
229+
# policy_item {
230+
# id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.0.id
231+
# frequency_interval = 1
232+
# frequency_type = "hourly"
233+
# retention_unit = "days"
234+
# retention_value = 1
235+
# }
236+
237+
# Item removed
238+
# policy_item {
239+
# id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.1.id
240+
# frequency_interval = 1
241+
# frequency_type = "daily"
242+
# retention_unit = "days"
243+
# retention_value = 2
244+
# }
245+
246+
# Item removed
247+
# policy_item {
248+
# id = mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.2.id
249+
# frequency_interval = 4
250+
# frequency_type = "weekly"
251+
# retention_unit = "weeks"
252+
# retention_value = 3
253+
# }
254+
255+
policy_item {
256+
id = 5f0747cad187d8609a72f546
257+
frequency_interval = 5
258+
frequency_type = "monthly"
259+
retention_unit = "months"
260+
retention_value = 4
261+
}
262+
}
263+
}
264+
```
265+
266+
-> **NOTE:** (See text in first example for more details on the default.) If you want the Cloud Backup Snapshot Policy to vary in number of policies for a cluster that was already created/imported, perhaps you want to remove three policy items and modify the remaining policy, simply follow the above example here.
267+
268+
~> **IMPORTANT:** Note in this example we decided to remove the first 3 items so we can't use `mongodbatlas_cluster.my_cluster.snapshot_backup_policy.0.policies.0.policy_item.3.id` this sentence to retrieve the monthly id value of the cluster state due to once the cluster being modified or makes a `terraform refresh` will cause that the three items will remove from the state, so we will get an error due to the index 3 doesn't exists any more and our monthly policy item is moved to the first place of the array.(See text in the first example for more details on it)
116269

117270
## Argument Reference
118271

0 commit comments

Comments
 (0)