Skip to content

Commit ea966e0

Browse files
Fix/add examples (#9)
* in progress. added azure example * in progress. example without requiring a provider * with working tests, in the current standard * Update examples/complete/main.tf Co-authored-by: Chris Taylor <132399041+chris11-taylor-nttd@users.noreply.github.com> Signed-off-by: Bryce Lynn <160785634+bryce-lynn-nttd@users.noreply.github.com> * remove empty locals file --------- Signed-off-by: Bryce Lynn <160785634+bryce-lynn-nttd@users.noreply.github.com> Co-authored-by: Chris Taylor <132399041+chris11-taylor-nttd@users.noreply.github.com>
1 parent 5bcc7bb commit ea966e0

File tree

15 files changed

+592
-155
lines changed

15 files changed

+592
-155
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ If `make check` target is successful, developer is good to commit the code to pr
147147

148148
| Name | Version |
149149
|------|---------|
150-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.0, <= 1.5.5 |
150+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.0 |
151151
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.5 |
152152

153153
## Providers
154154

155155
| Name | Version |
156156
|------|---------|
157-
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.1 |
157+
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.3 |
158158

159159
## Modules
160160

examples/complete/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# complete
2+
3+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4+
## Requirements
5+
6+
| Name | Version |
7+
|------|---------|
8+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.0 |
9+
10+
## Providers
11+
12+
No providers.
13+
14+
## Modules
15+
16+
| Name | Source | Version |
17+
|------|--------|---------|
18+
| <a name="module_resource_names"></a> [resource\_names](#module\_resource\_names) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 1.0 |
19+
20+
## Resources
21+
22+
No resources.
23+
24+
## Inputs
25+
26+
| Name | Description | Type | Default | Required |
27+
|------|-------------|------|---------|:--------:|
28+
| <a name="input_logical_product_family"></a> [logical\_product\_family](#input\_logical\_product\_family) | (Required) Name of the product family for which the resource is created.<br> Example: org\_name, department\_name. | `string` | `"launch"` | no |
29+
| <a name="input_logical_product_service"></a> [logical\_product\_service](#input\_logical\_product\_service) | (Required) Name of the product service for which the resource is created.<br> For example, backend, frontend, middleware etc. | `string` | `"backend"` | no |
30+
| <a name="input_instance_resource"></a> [instance\_resource](#input\_instance\_resource) | Number that represents the instance of the resource. | `number` | `0` | no |
31+
| <a name="input_instance_env"></a> [instance\_env](#input\_instance\_env) | Number that represents the instance of the environment. | `number` | `0` | no |
32+
| <a name="input_class_env"></a> [class\_env](#input\_class\_env) | (Required) Environment where resource is going to be deployed. For example. dev, qa, uat | `string` | `"dev"` | no |
33+
| <a name="input_resource_names_map"></a> [resource\_names\_map](#input\_resource\_names\_map) | A map of key to resource\_name that will be used by tf-launch-module\_library-resource\_name to generate resource names | <pre>map(object(<br> {<br> name = string<br> max_length = optional(number, 60)<br> }<br> ))</pre> | `{}` | no |
34+
| <a name="input_region"></a> [region](#input\_region) | (Required) The location where the resource will be created. Must not have spaces<br> For example, us-east-1, us-west-2, eu-west-1, etc. | `string` | `"us-east-2"` | no |
35+
36+
## Outputs
37+
38+
| Name | Description |
39+
|------|-------------|
40+
| <a name="output_resource_one_standard"></a> [resource\_one\_standard](#output\_resource\_one\_standard) | Resource one in standard format. |
41+
| <a name="output_resource_two_standard"></a> [resource\_two\_standard](#output\_resource\_two\_standard) | Resource two in standard format. |
42+
| <a name="output_resource_one_lowercase"></a> [resource\_one\_lowercase](#output\_resource\_one\_lowercase) | Resource one in lowercase format. |
43+
| <a name="output_resource_one_uppercase"></a> [resource\_one\_uppercase](#output\_resource\_one\_uppercase) | Resource one in uppercase format. |
44+
| <a name="output_resource_one_lowercase_without_any_separators"></a> [resource\_one\_lowercase\_without\_any\_separators](#output\_resource\_one\_lowercase\_without\_any\_separators) | Resource one in lowercase format without separator. |
45+
| <a name="output_resource_one_uppercase_without_any_separators"></a> [resource\_one\_uppercase\_without\_any\_separators](#output\_resource\_one\_uppercase\_without\_any\_separators) | Resource one in uppercase format without separator. |
46+
| <a name="output_resource_one_minimal"></a> [resource\_one\_minimal](#output\_resource\_one\_minimal) | Resource one in minimal format. |
47+
| <a name="output_resource_one_minimal_random_suffix"></a> [resource\_one\_minimal\_random\_suffix](#output\_resource\_one\_minimal\_random\_suffix) | Resource one in minimal format with random number. |
48+
| <a name="output_resource_one_minimal_random_suffix_without_any_separators"></a> [resource\_one\_minimal\_random\_suffix\_without\_any\_separators](#output\_resource\_one\_minimal\_random\_suffix\_without\_any\_separators) | Resource one in minimal format with random number without separator. |
49+
| <a name="output_resource_one_dns_compliant_standard"></a> [resource\_one\_dns\_compliant\_standard](#output\_resource\_one\_dns\_compliant\_standard) | Resource one in DNS compliant format. |
50+
| <a name="output_resource_one_dns_compliant_minimal"></a> [resource\_one\_dns\_compliant\_minimal](#output\_resource\_one\_dns\_compliant\_minimal) | Resource one in DNS compliant minimal format. |
51+
| <a name="output_resource_one_dns_compliant_minimal_random_suffix"></a> [resource\_one\_dns\_compliant\_minimal\_random\_suffix](#output\_resource\_one\_dns\_compliant\_minimal\_random\_suffix) | Resource one in DNS compliant minimal format with random number. |
52+
| <a name="output_resource_one_camel_case"></a> [resource\_one\_camel\_case](#output\_resource\_one\_camel\_case) | Resource one in camel case format. |
53+
| <a name="output_resource_one_camel_case_without_any_separators"></a> [resource\_one\_camel\_case\_without\_any\_separators](#output\_resource\_one\_camel\_case\_without\_any\_separators) | Resource one in camel case format without separator. |
54+
| <a name="output_resource_one_camel_case_with_separator"></a> [resource\_one\_camel\_case\_with\_separator](#output\_resource\_one\_camel\_case\_with\_separator) | Resource one in camel case format with separator. |
55+
| <a name="output_resource_one_recommended_per_length_restriction"></a> [resource\_one\_recommended\_per\_length\_restriction](#output\_resource\_one\_recommended\_per\_length\_restriction) | Resource one in recommended format as per length restriction. |
56+
| <a name="output_resource_two_recommended_per_length_restriction"></a> [resource\_two\_recommended\_per\_length\_restriction](#output\_resource\_two\_recommended\_per\_length\_restriction) | Resource two in recommended format as per length restriction. |
57+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/complete/main.tf

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
14+
// Licensed under the Apache License, Version 2.0 (the "License");
15+
// you may not use this file except in compliance with the License.
16+
// You may obtain a copy of the License at
17+
//
18+
// http://www.apache.org/licenses/LICENSE-2.0
19+
//
20+
// Unless required by applicable law or agreed to in writing, software
21+
// distributed under the License is distributed on an "AS IS" BASIS,
22+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
// See the License for the specific language governing permissions and
24+
// limitations under the License.
25+
26+
module "resource_names" {
27+
source = "../.."
28+
29+
for_each = var.resource_names_map
30+
31+
logical_product_family = var.logical_product_family
32+
logical_product_service = var.logical_product_service
33+
region = join("", split("-", var.region))
34+
class_env = var.class_env
35+
cloud_resource_type = each.value.name
36+
instance_env = var.instance_env
37+
instance_resource = var.instance_resource
38+
maximum_length = each.value.max_length
39+
}

examples/complete/outputs.tf

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
output "resource_one_standard" {
14+
value = module.resource_names["resource_one"].standard
15+
description = "Resource one in standard format."
16+
}
17+
18+
output "resource_two_standard" {
19+
value = module.resource_names["resource_two"].standard
20+
description = "Resource two in standard format."
21+
}
22+
23+
output "resource_one_lowercase" {
24+
value = module.resource_names["resource_one"].lower_case_with_separator
25+
description = "Resource one in lowercase format."
26+
}
27+
28+
output "resource_one_uppercase" {
29+
value = module.resource_names["resource_one"].upper_case_with_separator
30+
description = "Resource one in uppercase format."
31+
}
32+
33+
output "resource_one_lowercase_without_any_separators" {
34+
value = module.resource_names["resource_one"].lower_case_without_any_separators
35+
description = "Resource one in lowercase format without separator."
36+
}
37+
38+
output "resource_one_uppercase_without_any_separators" {
39+
value = module.resource_names["resource_one"].upper_case_without_any_separators
40+
description = "Resource one in uppercase format without separator."
41+
}
42+
43+
output "resource_one_minimal" {
44+
value = module.resource_names["resource_one"].minimal
45+
description = "Resource one in minimal format."
46+
}
47+
48+
output "resource_one_minimal_random_suffix" {
49+
value = module.resource_names["resource_one"].minimal_random_suffix
50+
description = "Resource one in minimal format with random number."
51+
}
52+
53+
output "resource_one_minimal_random_suffix_without_any_separators" {
54+
value = module.resource_names["resource_one"].minimal_random_suffix_without_any_separators
55+
description = "Resource one in minimal format with random number without separator."
56+
}
57+
58+
output "resource_one_dns_compliant_standard" {
59+
value = module.resource_names["resource_one"].dns_compliant_standard
60+
description = "Resource one in DNS compliant format."
61+
}
62+
63+
output "resource_one_dns_compliant_minimal" {
64+
value = module.resource_names["resource_one"].dns_compliant_minimal
65+
description = "Resource one in DNS compliant minimal format."
66+
}
67+
68+
output "resource_one_dns_compliant_minimal_random_suffix" {
69+
value = module.resource_names["resource_one"].dns_compliant_minimal_random_suffix
70+
description = "Resource one in DNS compliant minimal format with random number."
71+
}
72+
73+
output "resource_one_camel_case" {
74+
value = module.resource_names["resource_one"].camel_case
75+
description = "Resource one in camel case format."
76+
}
77+
78+
output "resource_one_camel_case_without_any_separators" {
79+
value = module.resource_names["resource_one"].camel_case_without_any_separators
80+
description = "Resource one in camel case format without separator."
81+
}
82+
83+
output "resource_one_camel_case_with_separator" {
84+
value = module.resource_names["resource_one"].camel_case_with_separator
85+
description = "Resource one in camel case format with separator."
86+
}
87+
88+
output "resource_one_recommended_per_length_restriction" {
89+
value = module.resource_names["resource_one"].recommended_per_length_restriction
90+
description = "Resource one in recommended format as per length restriction."
91+
}
92+
93+
output "resource_two_recommended_per_length_restriction" {
94+
value = module.resource_names["resource_two"].recommended_per_length_restriction
95+
description = "Resource two in recommended format as per length restriction."
96+
}

examples/complete/test.tfvars

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
logical_product_family = "terratest"
2+
logical_product_service = "resource_NAME_test"
3+
4+
resource_names_map = {
5+
resource_one = {
6+
name = "r1"
7+
max_length = 80
8+
}
9+
resource_two = {
10+
name = "r2"
11+
max_length = 50
12+
}
13+
}

examples/complete/variables.tf

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
variable "logical_product_family" {
14+
type = string
15+
description = <<EOF
16+
(Required) Name of the product family for which the resource is created.
17+
Example: org_name, department_name.
18+
EOF
19+
nullable = false
20+
default = "launch"
21+
22+
validation {
23+
condition = can(regex("^[_\\-A-Za-z0-9]+$", var.logical_product_family))
24+
error_message = "The variable must contain letters, numbers, -, _, and .."
25+
}
26+
}
27+
28+
variable "logical_product_service" {
29+
type = string
30+
description = <<EOF
31+
(Required) Name of the product service for which the resource is created.
32+
For example, backend, frontend, middleware etc.
33+
EOF
34+
nullable = false
35+
default = "backend"
36+
37+
validation {
38+
condition = can(regex("^[_\\-A-Za-z0-9]+$", var.logical_product_service))
39+
error_message = "The variable must contain letters, numbers, -, _, and .."
40+
}
41+
}
42+
43+
variable "instance_resource" {
44+
type = number
45+
description = "Number that represents the instance of the resource."
46+
default = 0
47+
48+
validation {
49+
condition = var.instance_resource >= 0 && var.instance_resource <= 100
50+
error_message = "Instance number should be between 1 to 100."
51+
}
52+
}
53+
54+
variable "instance_env" {
55+
type = number
56+
description = "Number that represents the instance of the environment."
57+
default = 0
58+
59+
validation {
60+
condition = var.instance_env >= 0 && var.instance_env <= 999
61+
error_message = "Instance number should be between 1 to 999."
62+
}
63+
}
64+
65+
variable "class_env" {
66+
type = string
67+
default = "dev"
68+
description = "(Required) Environment where resource is going to be deployed. For example. dev, qa, uat"
69+
nullable = false
70+
71+
validation {
72+
condition = length(regexall("\\b \\b", var.class_env)) == 0
73+
error_message = "Spaces between the words are not allowed."
74+
}
75+
}
76+
77+
variable "resource_names_map" {
78+
description = "A map of key to resource_name that will be used by tf-launch-module_library-resource_name to generate resource names"
79+
type = map(object(
80+
{
81+
name = string
82+
max_length = optional(number, 60)
83+
}
84+
))
85+
default = {}
86+
}
87+
88+
variable "region" {
89+
type = string
90+
description = <<EOF
91+
(Required) The location where the resource will be created. Must not have spaces
92+
For example, us-east-1, us-west-2, eu-west-1, etc.
93+
EOF
94+
nullable = false
95+
default = "us-east-2"
96+
97+
validation {
98+
condition = length(regexall("\\b \\b", var.region)) == 0
99+
error_message = "Spaces between the words are not allowed."
100+
}
101+
}

examples/complete/versions.tf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
terraform {
14+
required_version = "~> 1.0"
15+
16+
required_providers {
17+
}
18+
}

0 commit comments

Comments
 (0)