Skip to content

Commit 6fee7a5

Browse files
committed
docs: update usage section with vars.yml
1 parent 57cb2b8 commit 6fee7a5

File tree

1 file changed

+78
-28
lines changed

1 file changed

+78
-28
lines changed

README.md

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,52 +81,102 @@ vars:
8181
### Example
8282

8383
```text
84-
resource "aws_vpc" "vpc" {
85-
cidr_block = "${var.cidr}"
86-
enable_dns_hostnames = "${var.enable_dns_hostnames}"
87-
enable_dns_support = "${var.enable_dns_support}"
84+
resource "aws_eip" "nat" {
85+
vpc = true
86+
count = "${length(var.public_subnets)}"
87+
}
8888
89-
tags {
90-
Name = "${var.name}"
91-
}
89+
resource "aws_nat_gateway" "nat" {
90+
allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
91+
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
92+
count = "${length(var.public_subnets)}"
93+
tags = "${var.tags}"
9294
}
9395
94-
resource "aws_internet_gateway" "vpc" {
95-
vpc_id = "${aws_vpc.vpc.id}"
96+
data "template_file" "template1" {
97+
template = "${file("${path.module}/template1.tpl")}"
9698
97-
tags {
98-
Name = "${var.name}-igw"
99+
vars {
100+
t1_var1 = "${var.cidrs}"
101+
t1-var2 = "${var.t1-var2}"
102+
t1-var3 = "${var.t1-Var3}-${var.t1-inline}"
99103
}
100104
}
101105
```
102106

103-
Will generate
107+
Will generate:
104108

105-
```text
106-
variable "ami" {
107-
description = ""
108-
}
109+
```text
110+
variable "cidrs" {}
109111
110-
variable "instance_type" {
111-
description = ""
112-
}
112+
variable "public_subnets" {}
113+
114+
variable "t1-Var3" {}
115+
116+
variable "t1-inline" {}
117+
118+
variable "t1-var2" {}
119+
120+
variable "tags" {}
121+
```
122+
123+
And, if you add customized conf `vars.yml`:
113124

114-
variable "cidr" {
115-
description = ""
125+
```yaml
126+
vars:
127+
- public_subnets:
128+
type: list
129+
description: subnets for public
130+
default: |
131+
["sub1", "sub2"]
132+
- tags:
133+
type: map
134+
default: |
135+
{
136+
Name = "Terraform"
137+
}
138+
- cidrs:
139+
type: list
140+
default: |
141+
["10.0.0.0/16", "10.1.0.0/16"]
142+
- t1-var2:
143+
description: var for t1
144+
type: string
145+
```
146+
147+
then run generator again, the result will be:
148+
149+
```text
150+
variable "cidrs" {
151+
type = "list"
152+
153+
default = ["10.0.0.0/16", "10.1.0.0/16"]
116154
}
117155

118-
variable "enable_dns_hostnames" {
119-
description = ""
156+
variable "public_subnets" {
157+
description = "subnets for public"
158+
type = "list"
159+
160+
default = ["sub1", "sub2"]
120161
}
121162

122-
variable "enable_dns_support" {
123-
description = ""
163+
variable "t1-Var3" {}
164+
165+
variable "t1-inline" {}
166+
167+
variable "t1-var2" {
168+
description = "var for t1"
169+
type = "string"
124170
}
125171

126-
variable "name" {
127-
description = ""
172+
variable "tags" {
173+
type = "map"
174+
175+
default = {
176+
Name = "Terraform"
177+
}
128178
}
129-
```
179+
```
130180

131181
## Development
132182

0 commit comments

Comments
 (0)