Skip to content

Commit 586621a

Browse files
authored
Merge pull request #23 from cytopia/release-0.11
Fix description key inside type
2 parents 27f96ab + aa05ef3 commit 586621a

File tree

11 files changed

+171
-58
lines changed

11 files changed

+171
-58
lines changed

data/terraform-docs.awk

Lines changed: 123 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,79 +14,154 @@
1414
braceCnt--
1515
}
1616

17+
18+
# ----------------------------------------------------------------------------------------------
19+
# variable|output "..." {
20+
# ----------------------------------------------------------------------------------------------
21+
# [END] variable/output block
22+
if (blockCnt > 0 && blockTypeCnt == 0 && blockDefaultCnt == 0) {
23+
if (braceCnt == 0 && blockCnt > 0) {
24+
blockCnt--
25+
print $0
26+
}
27+
}
1728
# [START] variable or output block started
1829
if ($0 ~ /^[[:space:]]*(variable|output)[[:space:]][[:space:]]*"(.*?)"/) {
19-
# Normalize the braceCnt (should be 1 now)
30+
# Normalize the braceCnt and block (should be 1 now)
2031
braceCnt = 1
21-
# [CLOSE] "default" block
22-
if (blockDefCnt > 0) {
23-
blockDefCnt = 0
24-
}
25-
blockCnt++
32+
blockCnt = 1
33+
# [CLOSE] "default" and "type" block
34+
blockDefaultCnt = 0
35+
blockTypeCnt = 0
36+
# Print variable|output line
2637
print $0
2738
}
2839

29-
# [START] multiline default statement started
30-
if (blockCnt > 0) {
40+
41+
# ----------------------------------------------------------------------------------------------
42+
# default = ...
43+
# ----------------------------------------------------------------------------------------------
44+
# [END] multiline "default" continues/ends
45+
if (blockCnt > 0 && blockTypeCnt == 0 && blockDefaultCnt > 0) {
46+
print $0
47+
# Count opening blocks
48+
blockDefaultCnt += gsub(/\(/, "")
49+
blockDefaultCnt += gsub(/\[/, "")
50+
blockDefaultCnt += gsub(/\{/, "")
51+
# Count closing blocks
52+
blockDefaultCnt -= gsub(/\)/, "")
53+
blockDefaultCnt -= gsub(/\]/, "")
54+
blockDefaultCnt -= gsub(/\}/, "")
55+
}
56+
# [START] multiline "default" statement started
57+
if (blockCnt > 0 && blockTypeCnt == 0 && blockDefaultCnt == 0) {
3158
if ($0 ~ /^[[:space:]][[:space:]]*(default)[[:space:]][[:space:]]*=/) {
3259
if ($3 ~ "null") {
3360
print " default = \"null\""
3461
} else {
3562
print $0
36-
blockDefCnt++
37-
blockDefStart=1
63+
# Count opening blocks
64+
blockDefaultCnt += gsub(/\(/, "")
65+
blockDefaultCnt += gsub(/\[/, "")
66+
blockDefaultCnt += gsub(/\{/, "")
67+
# Count closing blocks
68+
blockDefaultCnt -= gsub(/\)/, "")
69+
blockDefaultCnt -= gsub(/\]/, "")
70+
blockDefaultCnt -= gsub(/\}/, "")
3871
}
3972
}
4073
}
4174

42-
# [PRINT] single line "description"
43-
if (blockCnt > 0) {
44-
if (blockDefCnt == 0) {
45-
if ($0 ~ /^[[:space:]][[:space:]]*description[[:space:]][[:space:]]*=/) {
46-
# [CLOSE] "default" block
47-
if (blockDefCnt > 0) {
48-
blockDefCnt = 0
49-
}
50-
print $0
51-
}
52-
}
53-
}
5475

55-
# [PRINT] single line "type"
56-
if (blockCnt > 0) {
57-
if ($0 ~ /^[[:space:]][[:space:]]*type[[:space:]][[:space:]]*=/ ) {
58-
# [CLOSE] "default" block
59-
if (blockDefCnt > 0) {
60-
blockDefCnt = 0
61-
}
62-
type=$3
63-
if (type ~ "object") {
76+
# ----------------------------------------------------------------------------------------------
77+
# type = ...
78+
# ----------------------------------------------------------------------------------------------
79+
# [END] multiline "type" continues/ends
80+
if (blockCnt > 0 && blockTypeCnt > 0 && blockDefaultCnt == 0) {
81+
# The following 'print $0' would print multiline type definitions
82+
#print $0
83+
# Count opening blocks
84+
blockTypeCnt += gsub(/\(/, "")
85+
blockTypeCnt += gsub(/\[/, "")
86+
blockTypeCnt += gsub(/\{/, "")
87+
# Count closing blocks
88+
blockTypeCnt -= gsub(/\)/, "")
89+
blockTypeCnt -= gsub(/\]/, "")
90+
blockTypeCnt -= gsub(/\}/, "")
91+
}
92+
# [START] multiline "type" statement started
93+
if (blockCnt > 0 && blockTypeCnt == 0 && blockDefaultCnt == 0) {
94+
if ($0 ~ /^[[:space:]][[:space:]]*(type)[[:space:]][[:space:]]*=/ ) {
95+
if ($3 ~ "object") {
6496
print " type = \"object\""
6597
} else {
66-
# legacy quoted types: "string", "list", and "map"
67-
if ($3 ~ /^[[:space:]]*"(.*?)"[[:space:]]*$/) {
68-
print " type = " $3
69-
} else {
70-
print " type = \"" $3 "\""
71-
}
98+
# Convert multiline stuff into single line
99+
if ($3 ~ /^[[:space:]]*list[[:space:]]*\([[:space:]]*$/) {
100+
type = "list"
101+
} else if ($3 ~ /^[[:space:]]*string[[:space:]]*\([[:space:]]*$/) {
102+
type = "string"
103+
} else if ($3 ~ /^[[:space:]]*map[[:space:]]*\([[:space:]]*$/) {
104+
type = "map"
105+
} else {
106+
type = $3
107+
}
108+
109+
# legacy quoted types: "string", "list", and "map"
110+
if (type ~ /^[[:space:]]*"(.*?)"[[:space:]]*$/) {
111+
print " type = " type
112+
} else {
113+
print " type = \"" type "\""
114+
}
72115
}
116+
# Count opening blocks
117+
blockTypeCnt += gsub(/\(/, "")
118+
blockTypeCnt += gsub(/\[/, "")
119+
blockTypeCnt += gsub(/\{/, "")
120+
# Count closing blocks
121+
blockTypeCnt -= gsub(/\)/, "")
122+
blockTypeCnt -= gsub(/\]/, "")
123+
blockTypeCnt -= gsub(/\}/, "")
73124
}
74125
}
75126

76-
# [CLOSE] variable/output block
77-
if (blockCnt > 0) {
78-
if (braceCnt == 0 && blockCnt > 0) {
79-
blockCnt--
127+
128+
# ----------------------------------------------------------------------------------------------
129+
# description = ...
130+
# ----------------------------------------------------------------------------------------------
131+
# [PRINT] single line "description"
132+
if (blockCnt > 0 && blockTypeCnt == 0 && blockDefaultCnt == 0) {
133+
if ($0 ~ /^[[:space:]][[:space:]]*description[[:space:]][[:space:]]*=/) {
80134
print $0
81135
}
82136
}
83137

84-
# [PRINT] Multiline "default" statement
85-
if (blockCnt > 0 && blockDefCnt > 0) {
86-
if (blockDefStart == 1) {
87-
blockDefStart = 0
88-
} else {
89-
print $0
90-
}
138+
139+
# ----------------------------------------------------------------------------------------------
140+
# value = ...
141+
# ----------------------------------------------------------------------------------------------
142+
## [PRINT] single line "value"
143+
#if (blockCnt > 0 && blockTypeCnt == 0 && blockDefaultCnt == 0) {
144+
# if ($0 ~ /^[[:space:]][[:space:]]*value[[:space:]][[:space:]]*=/) {
145+
# print $0
146+
# }
147+
#}
148+
149+
150+
# ----------------------------------------------------------------------------------------------
151+
# Newlines, comments, everything else
152+
# ----------------------------------------------------------------------------------------------
153+
#if (blockTypeCnt == 0 && blockDefaultCnt == 0) {
154+
# Comments with '#'
155+
if ($0 ~ /^[[:space:]]*#/) {
156+
print $0
157+
}
158+
# Comments with '//'
159+
if ($0 ~ /^[[:space:]]*\/\//) {
160+
print $0
161+
}
162+
# Newlines
163+
if ($0 ~ /^[[:space:]]*$/) {
164+
print $0
91165
}
166+
#}
92167
}

tests/0.12/TEST-0.1.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Stuff before terraform-docs
5252
| final_snapshot_identifier | The name of your final DB snapshot when this DB instance is deleted. | `null` | no |
5353
| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | `false` | no |
5454
| identifier | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | - | yes |
55+
| ingress_cidr_blocks | Bzzzzz | `<list>` | no |
5556
| ingress_cidr_blocks | List of IPv4 CIDR ranges to use on all ingress rules | `<list>` | no |
5657
| ingress_ipv6_cidr_blocks | List of IPv6 CIDR ranges to use on all ingress rules | `<list>` | no |
5758
| ingress_prefix_list_ids | List of prefix list IDs (for allowing access to VPC endpoints) to use on all ingress rules | `<list>` | no |
@@ -70,8 +71,8 @@ Stuff before terraform-docs
7071
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero. | `` | no |
7172
| monitoring_role_name | Name of the IAM role which will be created when create_monitoring_role is enabled. | `rds-monitoring-role` | no |
7273
| multi_az | Specifies if the RDS instance is multi-AZ | `false` | no |
73-
| name | Name of security group | - | yes |
7474
| name | The DB name to create. If omitted, no database is created initially | `` | no |
75+
| name | Name of security group | - | yes |
7576
| network | The network | `<map>` | no |
7677
| number_of_computed_egress_rules | Number of computed egress rules to create by name | `0` | no |
7778
| number_of_computed_egress_with_cidr_blocks | Number of computed egress rules to create where 'cidr_blocks' is used | `0` | no |
@@ -126,7 +127,7 @@ Stuff before terraform-docs
126127
| this_db_instance_status | |
127128
| this_db_instance_username | |
128129
| this_db_option_group_arn | |
129-
| this_db_option_group_id | |
130+
| this_db_option_group_id | # DB option group |
130131
| this_db_parameter_group_arn | |
131132
| this_db_parameter_group_id | |
132133
| this_db_subnet_group_arn | |

tests/0.12/TEST-0.1.1.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Stuff before terraform-docs
5252
| final_snapshot_identifier | The name of your final DB snapshot when this DB instance is deleted. | string | `null` | no |
5353
| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no |
5454
| identifier | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | string | - | yes |
55+
| ingress_cidr_blocks | Bzzzzz | list | `<list>` | no |
5556
| ingress_cidr_blocks | List of IPv4 CIDR ranges to use on all ingress rules | list(string) | `<list>` | no |
5657
| ingress_ipv6_cidr_blocks | List of IPv6 CIDR ranges to use on all ingress rules | list(string) | `<list>` | no |
5758
| ingress_prefix_list_ids | List of prefix list IDs (for allowing access to VPC endpoints) to use on all ingress rules | list(string) | `<list>` | no |
@@ -70,8 +71,8 @@ Stuff before terraform-docs
7071
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero. | string | `` | no |
7172
| monitoring_role_name | Name of the IAM role which will be created when create_monitoring_role is enabled. | string | `rds-monitoring-role` | no |
7273
| multi_az | Specifies if the RDS instance is multi-AZ | bool | `false` | no |
73-
| name | Name of security group | string | - | yes |
7474
| name | The DB name to create. If omitted, no database is created initially | string | `` | no |
75+
| name | Name of security group | string | - | yes |
7576
| network | The network | object | `<map>` | no |
7677
| number_of_computed_egress_rules | Number of computed egress rules to create by name | number | `0` | no |
7778
| number_of_computed_egress_with_cidr_blocks | Number of computed egress rules to create where 'cidr_blocks' is used | number | `0` | no |
@@ -126,7 +127,7 @@ Stuff before terraform-docs
126127
| this_db_instance_status | The RDS instance status |
127128
| this_db_instance_username | The master username for the database |
128129
| this_db_option_group_arn | The ARN of the db option group |
129-
| this_db_option_group_id | The db option group id |
130+
| this_db_option_group_id | DB option group |
130131
| this_db_parameter_group_arn | The ARN of the db parameter group |
131132
| this_db_parameter_group_id | The db parameter group id |
132133
| this_db_subnet_group_arn | The ARN of the db subnet group |

tests/0.12/TEST-0.2.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Stuff before terraform-docs
5252
| final_snapshot_identifier | The name of your final DB snapshot when this DB instance is deleted. | string | `null` | no |
5353
| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no |
5454
| identifier | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | string | - | yes |
55+
| ingress_cidr_blocks | Bzzzzz | list | `<list>` | no |
5556
| ingress_cidr_blocks | List of IPv4 CIDR ranges to use on all ingress rules | list(string) | `<list>` | no |
5657
| ingress_ipv6_cidr_blocks | List of IPv6 CIDR ranges to use on all ingress rules | list(string) | `<list>` | no |
5758
| ingress_prefix_list_ids | List of prefix list IDs (for allowing access to VPC endpoints) to use on all ingress rules | list(string) | `<list>` | no |
@@ -70,8 +71,8 @@ Stuff before terraform-docs
7071
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero. | string | `` | no |
7172
| monitoring_role_name | Name of the IAM role which will be created when create_monitoring_role is enabled. | string | `rds-monitoring-role` | no |
7273
| multi_az | Specifies if the RDS instance is multi-AZ | bool | `false` | no |
73-
| name | Name of security group | string | - | yes |
7474
| name | The DB name to create. If omitted, no database is created initially | string | `` | no |
75+
| name | Name of security group | string | - | yes |
7576
| network | The network | object | `<map>` | no |
7677
| number_of_computed_egress_rules | Number of computed egress rules to create by name | number | `0` | no |
7778
| number_of_computed_egress_with_cidr_blocks | Number of computed egress rules to create where 'cidr_blocks' is used | number | `0` | no |
@@ -126,7 +127,7 @@ Stuff before terraform-docs
126127
| this_db_instance_status | The RDS instance status |
127128
| this_db_instance_username | The master username for the database |
128129
| this_db_option_group_arn | The ARN of the db option group |
129-
| this_db_option_group_id | The db option group id |
130+
| this_db_option_group_id | DB option group |
130131
| this_db_parameter_group_arn | The ARN of the db parameter group |
131132
| this_db_parameter_group_id | The db parameter group id |
132133
| this_db_subnet_group_arn | The ARN of the db subnet group |

tests/0.12/TEST-0.3.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Stuff before terraform-docs
5252
| final_snapshot_identifier | The name of your final DB snapshot when this DB instance is deleted. | string | `null` | no |
5353
| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no |
5454
| identifier | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | string | - | yes |
55+
| ingress_cidr_blocks | Bzzzzz | list | `<list>` | no |
5556
| ingress_cidr_blocks | List of IPv4 CIDR ranges to use on all ingress rules | list(string) | `<list>` | no |
5657
| ingress_ipv6_cidr_blocks | List of IPv6 CIDR ranges to use on all ingress rules | list(string) | `<list>` | no |
5758
| ingress_prefix_list_ids | List of prefix list IDs (for allowing access to VPC endpoints) to use on all ingress rules | list(string) | `<list>` | no |
@@ -70,8 +71,8 @@ Stuff before terraform-docs
7071
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero. | string | `` | no |
7172
| monitoring_role_name | Name of the IAM role which will be created when create_monitoring_role is enabled. | string | `rds-monitoring-role` | no |
7273
| multi_az | Specifies if the RDS instance is multi-AZ | bool | `false` | no |
73-
| name | Name of security group | string | - | yes |
7474
| name | The DB name to create. If omitted, no database is created initially | string | `` | no |
75+
| name | Name of security group | string | - | yes |
7576
| network | The network | object | `<map>` | no |
7677
| number_of_computed_egress_rules | Number of computed egress rules to create by name | number | `0` | no |
7778
| number_of_computed_egress_with_cidr_blocks | Number of computed egress rules to create where 'cidr_blocks' is used | number | `0` | no |
@@ -126,7 +127,7 @@ Stuff before terraform-docs
126127
| this_db_instance_status | The RDS instance status |
127128
| this_db_instance_username | The master username for the database |
128129
| this_db_option_group_arn | The ARN of the db option group |
129-
| this_db_option_group_id | The db option group id |
130+
| this_db_option_group_id | DB option group |
130131
| this_db_parameter_group_arn | The ARN of the db parameter group |
131132
| this_db_parameter_group_id | The db parameter group id |
132133
| this_db_subnet_group_arn | The ARN of the db subnet group |

tests/0.12/TEST-0.4.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Stuff before terraform-docs
5252
| final_snapshot_identifier | The name of your final DB snapshot when this DB instance is deleted. | string | `null` | no |
5353
| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no |
5454
| identifier | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | string | - | yes |
55+
| ingress_cidr_blocks | Bzzzzz | list | `[ { "cidr_blocks": "10.0.0.0/32", "description": "SG", "from_port": 22, "protocol": "tcp", "to_port": 22 } ]` | no |
5556
| ingress_cidr_blocks | List of IPv4 CIDR ranges to use on all ingress rules | list(string) | `[]` | no |
5657
| ingress_ipv6_cidr_blocks | List of IPv6 CIDR ranges to use on all ingress rules | list(string) | `[]` | no |
5758
| ingress_prefix_list_ids | List of prefix list IDs (for allowing access to VPC endpoints) to use on all ingress rules | list(string) | `[]` | no |
@@ -70,8 +71,8 @@ Stuff before terraform-docs
7071
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero. | string | `` | no |
7172
| monitoring_role_name | Name of the IAM role which will be created when create_monitoring_role is enabled. | string | `rds-monitoring-role` | no |
7273
| multi_az | Specifies if the RDS instance is multi-AZ | bool | `false` | no |
73-
| name | Name of security group | string | - | yes |
7474
| name | The DB name to create. If omitted, no database is created initially | string | `` | no |
75+
| name | Name of security group | string | - | yes |
7576
| network | The network | object | `{ "subnets": [ { "cidr_block": "10.0.0.0/16", "id": "vpc-123456" } ], "vpc": [ { "cidr_block": "10.0.0.0/16", "id": "vpc-123456" } ] }` | no |
7677
| number_of_computed_egress_rules | Number of computed egress rules to create by name | number | `0` | no |
7778
| number_of_computed_egress_with_cidr_blocks | Number of computed egress rules to create where 'cidr_blocks' is used | number | `0` | no |

tests/0.12/TEST-0.4.5.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Stuff before terraform-docs
5151
| final_snapshot_identifier | The name of your final DB snapshot when this DB instance is deleted. | string | `null` | no |
5252
| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no |
5353
| identifier | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | string | - | yes |
54+
| ingress_cidr_blocks | Bzzzzz | list | `[ { "cidr_blocks": "10.0.0.0/32", "description": "SG", "from_port": 22, "protocol": "tcp", "to_port": 22 } ]` | no |
5455
| ingress_cidr_blocks | List of IPv4 CIDR ranges to use on all ingress rules | list(string) | `[]` | no |
5556
| ingress_ipv6_cidr_blocks | List of IPv6 CIDR ranges to use on all ingress rules | list(string) | `[]` | no |
5657
| ingress_prefix_list_ids | List of prefix list IDs (for allowing access to VPC endpoints) to use on all ingress rules | list(string) | `[]` | no |
@@ -69,8 +70,8 @@ Stuff before terraform-docs
6970
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero. | string | `` | no |
7071
| monitoring_role_name | Name of the IAM role which will be created when create_monitoring_role is enabled. | string | `rds-monitoring-role` | no |
7172
| multi_az | Specifies if the RDS instance is multi-AZ | bool | `false` | no |
72-
| name | Name of security group | string | - | yes |
7373
| name | The DB name to create. If omitted, no database is created initially | string | `` | no |
74+
| name | Name of security group | string | - | yes |
7475
| network | The network | object | `{ "subnets": [ { "cidr_block": "10.0.0.0/16", "id": "vpc-123456" } ], "vpc": [ { "cidr_block": "10.0.0.0/16", "id": "vpc-123456" } ] }` | no |
7576
| number_of_computed_egress_rules | Number of computed egress rules to create by name | number | `0` | no |
7677
| number_of_computed_egress_with_cidr_blocks | Number of computed egress rules to create where 'cidr_blocks' is used | number | `0` | no |

0 commit comments

Comments
 (0)