@@ -81,52 +81,102 @@ vars:
81
81
### Example
82
82
83
83
``` 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
+ }
88
88
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}"
92
94
}
93
95
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") }"
96
98
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}"
99
103
}
100
104
}
101
105
```
102
106
103
- Will generate
107
+ Will generate:
104
108
105
- ``` text
106
- variable "ami" {
107
- description = ""
108
- }
109
+ ``` text
110
+ variable "cidrs" {}
109
111
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 ` :
113
124
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"]
116
154
}
117
155
118
- variable "enable_dns_hostnames" {
119
- description = ""
156
+ variable "public_subnets" {
157
+ description = "subnets for public"
158
+ type = "list"
159
+
160
+ default = ["sub1", "sub2"]
120
161
}
121
162
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"
124
170
}
125
171
126
- variable "name" {
127
- description = ""
172
+ variable "tags" {
173
+ type = "map"
174
+
175
+ default = {
176
+ Name = "Terraform"
177
+ }
128
178
}
129
- ```
179
+ ```
130
180
131
181
## Development
132
182
0 commit comments