Skip to content

Commit 5eceea1

Browse files
committed
tags & labels
1 parent 97d04dc commit 5eceea1

File tree

2 files changed

+320
-0
lines changed

2 files changed

+320
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
resource "mongodbatlas_advanced_cluster" "simplified" {
2+
project_id = var.project_id
3+
name = "cluster"
4+
cluster_type = "REPLICASET"
5+
replication_specs {
6+
region_configs {
7+
priority = 7
8+
provider_name = "AWS"
9+
region_name = "EU_WEST_1"
10+
electable_specs {
11+
instance_size = "M10"
12+
node_count = 3
13+
}
14+
}
15+
}
16+
dynamic "tags" {
17+
for_each = local.tags
18+
content { // simplified version where var can be used directly
19+
key = tags.key
20+
value = tags.value
21+
}
22+
}
23+
}
24+
25+
resource "mongodbatlas_advanced_cluster" "expression" {
26+
project_id = var.project_id
27+
name = "cluster"
28+
cluster_type = "REPLICASET"
29+
replication_specs {
30+
region_configs {
31+
priority = 7
32+
provider_name = "AWS"
33+
region_name = "EU_WEST_1"
34+
electable_specs {
35+
instance_size = "M10"
36+
node_count = 3
37+
}
38+
}
39+
}
40+
dynamic "tags" {
41+
for_each = local.tags
42+
content { // using expressions
43+
key = tags.key
44+
value = replace(tags.value, "/", "_")
45+
}
46+
}
47+
}
48+
49+
resource "mongodbatlas_advanced_cluster" "simplified_individual" {
50+
project_id = var.project_id
51+
name = "cluster"
52+
cluster_type = "REPLICASET"
53+
replication_specs {
54+
region_configs {
55+
priority = 7
56+
provider_name = "AWS"
57+
region_name = "EU_WEST_1"
58+
electable_specs {
59+
instance_size = "M10"
60+
node_count = 3
61+
}
62+
}
63+
}
64+
tags { // using individual tags apart from simplified version in dynamic tags
65+
key = "tag1"
66+
value = var.tag1val
67+
}
68+
dynamic "tags" {
69+
for_each = var.tags
70+
content { // simplified version where var can be used directly
71+
key = tags.key
72+
value = tags.value
73+
}
74+
}
75+
tags {
76+
key = "tag 2"
77+
value = var.tag2val
78+
}
79+
}
80+
81+
resource "mongodbatlas_advanced_cluster" "expression_individual" {
82+
project_id = var.project_id
83+
name = "cluster"
84+
cluster_type = "REPLICASET"
85+
replication_specs {
86+
region_configs {
87+
priority = 7
88+
provider_name = "AWS"
89+
region_name = "EU_WEST_1"
90+
electable_specs {
91+
instance_size = "M10"
92+
node_count = 3
93+
}
94+
}
95+
}
96+
tags { // using individual tags apart from expressions in dynamic tags
97+
key = "tag1"
98+
value = var.tag1val
99+
}
100+
dynamic "tags" {
101+
for_each = var.tags
102+
content { // using expressions
103+
key = tags.key
104+
value = replace(tags.value, "/", "_")
105+
}
106+
}
107+
tags {
108+
key = "tag 2"
109+
value = var.tag2val
110+
}
111+
}
112+
113+
resource "mongodbatlas_advanced_cluster" "full_example" {
114+
project_id = var.project_id
115+
name = "cluster"
116+
cluster_type = "REPLICASET"
117+
replication_specs {
118+
region_configs {
119+
priority = 7
120+
provider_name = "AWS"
121+
region_name = "EU_WEST_1"
122+
electable_specs {
123+
instance_size = "M10"
124+
node_count = 3
125+
}
126+
}
127+
}
128+
labels {
129+
key = "label1"
130+
value = "label1val"
131+
}
132+
labels {
133+
key = "label2"
134+
value = data.my_resource.my_data.value
135+
}
136+
dynamic "labels" {
137+
for_each = local.tags
138+
content {
139+
key = labels.key
140+
value = labels.value
141+
}
142+
}
143+
tags {
144+
key = "environment"
145+
value = "dev"
146+
}
147+
tags {
148+
key = var.tag_key # non-literal values are supported and enclosed in parentheses
149+
value = var.tag_value
150+
}
151+
dynamic "tags" {
152+
for_each = var.tags
153+
content {
154+
key = tags.key
155+
value = replace(tags.value, "/", "_")
156+
}
157+
}
158+
lifecycle {
159+
precondition {
160+
condition = local.use_new_replication_specs || !(var.auto_scaling_disk_gb_enabled && var.disk_size > 0)
161+
error_message = "Must use either auto_scaling_disk_gb_enabled or disk_size, not both."
162+
}
163+
}
164+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
resource "mongodbatlas_advanced_cluster" "simplified" {
2+
project_id = var.project_id
3+
name = "cluster"
4+
cluster_type = "REPLICASET"
5+
replication_specs = [
6+
{
7+
region_configs = [
8+
{
9+
priority = 7
10+
provider_name = "AWS"
11+
region_name = "EU_WEST_1"
12+
electable_specs = {
13+
instance_size = "M10"
14+
node_count = 3
15+
}
16+
}
17+
]
18+
}
19+
]
20+
tags = local.tags
21+
22+
# Updated by atlas-cli-plugin-terraform, please review the changes.
23+
}
24+
25+
resource "mongodbatlas_advanced_cluster" "expression" {
26+
project_id = var.project_id
27+
name = "cluster"
28+
cluster_type = "REPLICASET"
29+
replication_specs = [
30+
{
31+
region_configs = [
32+
{
33+
priority = 7
34+
provider_name = "AWS"
35+
region_name = "EU_WEST_1"
36+
electable_specs = {
37+
instance_size = "M10"
38+
node_count = 3
39+
}
40+
}
41+
]
42+
}
43+
]
44+
tags = {
45+
for key, value in local.tags : key => replace(value, "/", "_")
46+
}
47+
48+
# Updated by atlas-cli-plugin-terraform, please review the changes.
49+
}
50+
51+
resource "mongodbatlas_advanced_cluster" "simplified_individual" {
52+
project_id = var.project_id
53+
name = "cluster"
54+
cluster_type = "REPLICASET"
55+
replication_specs = [
56+
{
57+
region_configs = [
58+
{
59+
priority = 7
60+
provider_name = "AWS"
61+
region_name = "EU_WEST_1"
62+
electable_specs = {
63+
instance_size = "M10"
64+
node_count = 3
65+
}
66+
}
67+
]
68+
}
69+
]
70+
tags = merge(
71+
var.tags,
72+
{
73+
tag1 = var.tag1val
74+
"tag 2" = var.tag2val
75+
}
76+
)
77+
78+
# Updated by atlas-cli-plugin-terraform, please review the changes.
79+
}
80+
81+
resource "mongodbatlas_advanced_cluster" "expression_individual" {
82+
project_id = var.project_id
83+
name = "cluster"
84+
cluster_type = "REPLICASET"
85+
replication_specs = [
86+
{
87+
region_configs = [
88+
{
89+
priority = 7
90+
provider_name = "AWS"
91+
region_name = "EU_WEST_1"
92+
electable_specs = {
93+
instance_size = "M10"
94+
node_count = 3
95+
}
96+
}
97+
]
98+
}
99+
]
100+
tags = merge(
101+
{
102+
for key, value in var.tags : key => replace(value, "/", "_")
103+
},
104+
{
105+
tag1 = var.tag1val
106+
"tag 2" = var.tag2val
107+
}
108+
)
109+
110+
# Updated by atlas-cli-plugin-terraform, please review the changes.
111+
}
112+
113+
resource "mongodbatlas_advanced_cluster" "full_example" {
114+
project_id = var.project_id
115+
name = "cluster"
116+
cluster_type = "REPLICASET"
117+
lifecycle {
118+
precondition {
119+
condition = local.use_new_replication_specs || !(var.auto_scaling_disk_gb_enabled && var.disk_size > 0)
120+
error_message = "Must use either auto_scaling_disk_gb_enabled or disk_size, not both."
121+
}
122+
}
123+
replication_specs = [
124+
{
125+
region_configs = [
126+
{
127+
priority = 7
128+
provider_name = "AWS"
129+
region_name = "EU_WEST_1"
130+
electable_specs = {
131+
instance_size = "M10"
132+
node_count = 3
133+
}
134+
}
135+
]
136+
}
137+
]
138+
tags = merge(
139+
{
140+
for key, value in var.tags : key => replace(value, "/", "_")
141+
},
142+
{
143+
environment = "dev"
144+
(var.tag_key) = var.tag_value
145+
}
146+
)
147+
labels = merge(
148+
local.tags,
149+
{
150+
label1 = "label1val"
151+
label2 = data.my_resource.my_data.value
152+
}
153+
)
154+
155+
# Updated by atlas-cli-plugin-terraform, please review the changes.
156+
}

0 commit comments

Comments
 (0)