Skip to content

Commit

Permalink
split array of object
Browse files Browse the repository at this point in the history
  • Loading branch information
rucciva committed Nov 27, 2023
1 parent 5fc3f86 commit f55b3be
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 35 deletions.
23 changes: 23 additions & 0 deletions huaweicloud/cce.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ locals {
merge(v, {
certificate_users = null
kube_config_raw = null

# split
certificate_clusters = null
endpoints = null
masters = null
})
]
cce_certificate_clusters = flatten([
for cce in data.huaweicloud_cce_clusters.all.clusters : [
for v in cce.certificate_clusters :
merge(v, { cce_id : cce.id })
]
])
cce_endpoints = flatten([
for cce in data.huaweicloud_cce_clusters.all.clusters : [
for v in cce.endpoints :
merge(v, { cce_id : cce.id })
]
])
cce_masters = flatten([
for cce in data.huaweicloud_cce_clusters.all.clusters : [
for v in cce.masters :
merge(v, { cce_id : cce.id })
]
])
}
16 changes: 16 additions & 0 deletions huaweicloud/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ locals {
flavor_id = null
flavor_name = null
user_data = null

# split
network = null
volume_attached = null
})
]
ecs_networks = flatten([
for ecs in data.huaweicloud_compute_instances.all.instances : [
for v in ecs.network :
merge(v, { ecs_id : ecs.id })
]
])
ecs_volumes = flatten([
for ecs in data.huaweicloud_compute_instances.all.instances : [
for v in ecs.volume_attached :
merge(v, { ecs_id : ecs.id })
]
])
}
15 changes: 14 additions & 1 deletion huaweicloud/evs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
data "huaweicloud_evs_volumes" "all" {}

locals {
evs = data.huaweicloud_evs_volumes.all.volumes
evs = [
for evs in data.huaweicloud_evs_volumes.all.volumes :
merge(evs, {
# split
attachments = null
}
)
]
evs_attachments = flatten([
for evs in data.huaweicloud_evs_volumes.all.volumes : [
for a in evs.attachments :
merge(a, { evs_id : evs.id })
]
])
}
81 changes: 60 additions & 21 deletions huaweicloud/output.tf
Original file line number Diff line number Diff line change
@@ -1,41 +1,80 @@
output "vpc" {
value = local.vpc

output "cce" {
value = local.cce
}
output "eip" {
value = local.eip
output "cce_certificate_clusters" {
value = local.cce_certificate_clusters
}
output "cce_endpoints" {
value = local.cce_endpoints
}
output "cce_masters" {
value = local.cce_masters
}

output "ecs" {
value = local.ecs
}
output "evs" {
value = local.evs
output "ecs_networks" {
value = local.ecs_networks
}
output "rds" {
value = local.rds
output "ecs_volumes" {
value = local.ecs_volumes
}
output "cce" {
value = local.cce

output "eip" {
value = local.eip
}

output "elb" {
value = local.elb
}
output "secgroup" {
value = local.secgroup


output "evs" {
value = local.evs
}
output "obs" {
value = local.obs
output "evs_attachments" {
value = local.evs_attachments
}

output "nat" {
value = local.nat
}

output "obs" {
value = local.obs
}

output "rds" {
value = local.rds
}
output "rds_backup_strategy" {
value = local.rds_backup_strategy
}
output "rds_db" {
value = local.rds_db
}
output "rds_nodes" {
value = local.rds_nodes
}
output "rds_volume" {
value = local.rds_volume
}

output "secgroup" {
value = local.secgroup
}
output "secgroup_rules" {
value = local.secgroup_rules
}

output "test" {
value = flatten([
for v in data.huaweicloud_vpc_route_table.all : [
for r in v.route :
r.nexthop if r.type == "nat"
]
])
output "vpc" {
value = local.vpc
}
output "vpc_subnets" {
value = local.vpc_subnets
}
output "vpc_route_tables" {
value = local.vpc_route_tables
}
30 changes: 30 additions & 0 deletions huaweicloud/rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ locals {
db_versions = null
}
)

# split
backup_strategy = null
db = null
nodes = null
volume = null
})
]
rds_backup_strategy = flatten([
for rds in data.huaweicloud_rds_instances.all.instances : [
for v in rds.backup_strategy :
merge(v, { rds_id = rds.id })
]
])
rds_db = flatten([
for rds in data.huaweicloud_rds_instances.all.instances : [
for v in rds.db :
merge(v, { rds_id = rds.id })
]
])
rds_nodes = flatten([
for rds in data.huaweicloud_rds_instances.all.instances : [
for v in rds.nodes :
merge(v, { rds_id = rds.id })
]
])
rds_volume = flatten([
for rds in data.huaweicloud_rds_instances.all.instances : [
for v in rds.volume :
merge(v, { rds_id = rds.id })
]
])
}
13 changes: 7 additions & 6 deletions huaweicloud/secgroup.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ data "huaweicloud_networking_secgroup" "all" {
}

locals {
secgroup = [
for v in data.huaweicloud_networking_secgroups.all.security_groups :
merge(v, {
rules = try(data.huaweicloud_networking_secgroup.all[v.id].rules, null)
})
]
secgroup = data.huaweicloud_networking_secgroups.all.security_groups
secgroup_rules = flatten([
for k, v in data.huaweicloud_networking_secgroup.all : [
for r in v.rules :
merge(r, { secgroup_id = k })
]
])
}
20 changes: 13 additions & 7 deletions huaweicloud/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ data "huaweicloud_vpc_route_table" "all" {
}

locals {
vpc = [
for v in data.huaweicloud_vpcs.all.vpcs :
merge(v, {
subnets = try(data.huaweicloud_vpc_subnets.all[v.id].subnets, null)
route_tables = try(data.huaweicloud_vpc_route_table.all[v.id].route, null)
})
]
vpc = data.huaweicloud_vpcs.all.vpcs
vpc_subnets = flatten([
for k, v in data.huaweicloud_vpc_subnets.all : [
for s in v.subnets :
merge(s, { vpc_id = k })
]
])
vpc_route_tables = flatten([
for k, v in data.huaweicloud_vpc_route_table.all : [
for r in v.route :
merge(r, { vpc_id = k })
]
])
}

0 comments on commit f55b3be

Please sign in to comment.