@opengeni/runtime 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2PO56VAL.js +3478 -0
- package/dist/chunk-2PO56VAL.js.map +1 -0
- package/dist/index.d.ts +912 -0
- package/dist/index.js +3663 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/index.d.ts +1738 -0
- package/dist/sandbox/index.js +187 -0
- package/dist/sandbox/index.js.map +1 -0
- package/package.json +49 -0
- package/src/bundled_hashicorp_terraform_skills/LICENSE +373 -0
- package/src/bundled_hashicorp_terraform_skills/README.md +18 -0
- package/src/bundled_hashicorp_terraform_skills/UPSTREAM_GIT_SHA +1 -0
- package/src/bundled_hashicorp_terraform_skills/azure-verified-modules/SKILL.md +613 -0
- package/src/bundled_hashicorp_terraform_skills/checkov/SKILL.md +43 -0
- package/src/bundled_hashicorp_terraform_skills/refactor-module/SKILL.md +538 -0
- package/src/bundled_hashicorp_terraform_skills/social-media-marketing/SKILL.md +35 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-search-import/SKILL.md +372 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-search-import/references/MANUAL-IMPORT.md +113 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-search-import/scripts/list_resources.sh +38 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/SKILL.md +480 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/api-monitoring.md +543 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/component-blocks.md +476 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/deployment-blocks.md +391 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/examples.md +1529 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/linked-stacks.md +187 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/troubleshooting.md +671 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-style-guide/SKILL.md +353 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/SKILL.md +451 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/references/CI_CD.md +80 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/references/EXAMPLES.md +314 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/references/MOCK_PROVIDERS.md +171 -0
- package/src/codex-tool-search.ts +267 -0
- package/src/context-compaction.ts +538 -0
- package/src/history-sanitizer.ts +719 -0
- package/src/index.ts +3299 -0
- package/src/sandbox/capabilities.ts +69 -0
- package/src/sandbox/channel-a.ts +1031 -0
- package/src/sandbox/display-stack.ts +231 -0
- package/src/sandbox/errors.ts +34 -0
- package/src/sandbox/index.ts +832 -0
- package/src/sandbox/providers/blaxel.ts +35 -0
- package/src/sandbox/providers/cloudflare.ts +24 -0
- package/src/sandbox/providers/daytona.ts +34 -0
- package/src/sandbox/providers/docker.ts +17 -0
- package/src/sandbox/providers/e2b.ts +36 -0
- package/src/sandbox/providers/index.ts +107 -0
- package/src/sandbox/providers/local.ts +13 -0
- package/src/sandbox/providers/modal.ts +55 -0
- package/src/sandbox/providers/none.ts +13 -0
- package/src/sandbox/providers/runloop.ts +32 -0
- package/src/sandbox/providers/selfhosted.ts +96 -0
- package/src/sandbox/providers/types.ts +38 -0
- package/src/sandbox/providers/vercel.ts +29 -0
- package/src/sandbox/recording.ts +286 -0
- package/src/sandbox/routing/backend-resolver.ts +189 -0
- package/src/sandbox/routing/routing-session.ts +455 -0
- package/src/sandbox/select.ts +371 -0
- package/src/sandbox/selfhosted/capabilities.ts +255 -0
- package/src/sandbox/selfhosted/control-rpc.ts +351 -0
- package/src/sandbox/selfhosted/session.ts +930 -0
- package/src/sandbox/selfhosted/testing.ts +230 -0
- package/src/sandbox/stream-port.ts +185 -0
- package/src/sandbox/stream-token.ts +90 -0
- package/src/sandbox/terminal-server.ts +203 -0
- package/src/sandbox-computer.ts +835 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# Example Test Suite
|
|
2
|
+
|
|
3
|
+
Complete example testing a VPC module with unit, integration, and mock tests.
|
|
4
|
+
|
|
5
|
+
## Unit Tests (Plan Mode)
|
|
6
|
+
|
|
7
|
+
```hcl
|
|
8
|
+
# tests/vpc_module_unit_test.tftest.hcl
|
|
9
|
+
|
|
10
|
+
variables {
|
|
11
|
+
environment = "test"
|
|
12
|
+
aws_region = "us-west-2"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
run "test_defaults" {
|
|
16
|
+
command = plan
|
|
17
|
+
|
|
18
|
+
variables {
|
|
19
|
+
vpc_cidr = "10.0.0.0/16"
|
|
20
|
+
vpc_name = "test-vpc"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
assert {
|
|
24
|
+
condition = aws_vpc.main.cidr_block == "10.0.0.0/16"
|
|
25
|
+
error_message = "VPC CIDR should match input"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
assert {
|
|
29
|
+
condition = aws_vpc.main.enable_dns_hostnames == true
|
|
30
|
+
error_message = "DNS hostnames should be enabled by default"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
assert {
|
|
34
|
+
condition = aws_vpc.main.tags["Name"] == "test-vpc"
|
|
35
|
+
error_message = "VPC name tag should match input"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
run "test_subnets" {
|
|
40
|
+
command = plan
|
|
41
|
+
|
|
42
|
+
variables {
|
|
43
|
+
vpc_cidr = "10.0.0.0/16"
|
|
44
|
+
vpc_name = "test-vpc"
|
|
45
|
+
public_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
|
|
46
|
+
private_subnets = ["10.0.10.0/24", "10.0.11.0/24"]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
assert {
|
|
50
|
+
condition = length(aws_subnet.public) == 2
|
|
51
|
+
error_message = "Should create 2 public subnets"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
assert {
|
|
55
|
+
condition = length(aws_subnet.private) == 2
|
|
56
|
+
error_message = "Should create 2 private subnets"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
assert {
|
|
60
|
+
condition = alltrue([
|
|
61
|
+
for subnet in aws_subnet.private :
|
|
62
|
+
subnet.map_public_ip_on_launch == false
|
|
63
|
+
])
|
|
64
|
+
error_message = "Private subnets should not assign public IPs"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
run "test_outputs" {
|
|
69
|
+
command = plan
|
|
70
|
+
|
|
71
|
+
variables {
|
|
72
|
+
vpc_cidr = "10.0.0.0/16"
|
|
73
|
+
vpc_name = "test-vpc"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
assert {
|
|
77
|
+
condition = output.vpc_id != ""
|
|
78
|
+
error_message = "VPC ID output should not be empty"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
assert {
|
|
82
|
+
condition = can(regex("^vpc-", output.vpc_id))
|
|
83
|
+
error_message = "VPC ID should have correct format"
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
assert {
|
|
87
|
+
condition = output.vpc_cidr == "10.0.0.0/16"
|
|
88
|
+
error_message = "VPC CIDR output should match input"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
run "test_invalid_cidr" {
|
|
93
|
+
command = plan
|
|
94
|
+
|
|
95
|
+
variables {
|
|
96
|
+
vpc_cidr = "invalid"
|
|
97
|
+
vpc_name = "test-vpc"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
expect_failures = [
|
|
101
|
+
var.vpc_cidr
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Integration Tests (Apply Mode)
|
|
107
|
+
|
|
108
|
+
```hcl
|
|
109
|
+
# tests/vpc_module_integration_test.tftest.hcl
|
|
110
|
+
|
|
111
|
+
variables {
|
|
112
|
+
environment = "integration-test"
|
|
113
|
+
aws_region = "us-west-2"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
run "integration_test_vpc_creation" {
|
|
117
|
+
# command defaults to apply — creates real AWS resources
|
|
118
|
+
|
|
119
|
+
variables {
|
|
120
|
+
vpc_cidr = "10.100.0.0/16"
|
|
121
|
+
vpc_name = "integration-test-vpc"
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
assert {
|
|
125
|
+
condition = aws_vpc.main.id != ""
|
|
126
|
+
error_message = "VPC should be created with valid ID"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
assert {
|
|
130
|
+
condition = aws_vpc.main.state == "available"
|
|
131
|
+
error_message = "VPC should be in available state"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Mock Tests (Plan Mode, No Credentials)
|
|
137
|
+
|
|
138
|
+
```hcl
|
|
139
|
+
# tests/vpc_module_mock_test.tftest.hcl
|
|
140
|
+
|
|
141
|
+
mock_provider "aws" {
|
|
142
|
+
mock_resource "aws_instance" {
|
|
143
|
+
defaults = {
|
|
144
|
+
id = "i-1234567890abcdef0"
|
|
145
|
+
instance_type = "t2.micro"
|
|
146
|
+
ami = "ami-12345678"
|
|
147
|
+
public_ip = "203.0.113.1"
|
|
148
|
+
private_ip = "10.0.1.100"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
mock_resource "aws_vpc" {
|
|
153
|
+
defaults = {
|
|
154
|
+
id = "vpc-12345678"
|
|
155
|
+
cidr_block = "10.0.0.0/16"
|
|
156
|
+
enable_dns_hostnames = true
|
|
157
|
+
enable_dns_support = true
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
mock_resource "aws_subnet" {
|
|
162
|
+
defaults = {
|
|
163
|
+
id = "subnet-12345678"
|
|
164
|
+
vpc_id = "vpc-12345678"
|
|
165
|
+
cidr_block = "10.0.1.0/24"
|
|
166
|
+
availability_zone = "us-west-2a"
|
|
167
|
+
map_public_ip_on_launch = false
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
mock_data "aws_ami" {
|
|
172
|
+
defaults = {
|
|
173
|
+
id = "ami-0c55b159cbfafe1f0"
|
|
174
|
+
name = "ubuntu-focal-20.04-amd64"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
mock_data "aws_availability_zones" {
|
|
179
|
+
defaults = {
|
|
180
|
+
names = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
run "test_instance_with_mocks" {
|
|
186
|
+
command = plan
|
|
187
|
+
|
|
188
|
+
variables {
|
|
189
|
+
instance_type = "t2.micro"
|
|
190
|
+
ami_id = "ami-12345678"
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
assert {
|
|
194
|
+
condition = aws_instance.example.instance_type == "t2.micro"
|
|
195
|
+
error_message = "Instance type should match input variable"
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
assert {
|
|
199
|
+
condition = aws_instance.example.id == "i-1234567890abcdef0"
|
|
200
|
+
error_message = "Mock should return consistent instance ID"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
run "test_data_source_with_mocks" {
|
|
205
|
+
command = plan
|
|
206
|
+
|
|
207
|
+
assert {
|
|
208
|
+
condition = data.aws_ami.ubuntu.id == "ami-0c55b159cbfafe1f0"
|
|
209
|
+
error_message = "Mock data source should return predictable AMI ID"
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
assert {
|
|
213
|
+
condition = length(data.aws_availability_zones.available.names) == 3
|
|
214
|
+
error_message = "Should return 3 mocked availability zones"
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
assert {
|
|
218
|
+
condition = contains(data.aws_availability_zones.available.names, "us-west-2a")
|
|
219
|
+
error_message = "Should include us-west-2a in mocked zones"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
run "test_outputs_with_mocks" {
|
|
224
|
+
command = plan
|
|
225
|
+
|
|
226
|
+
assert {
|
|
227
|
+
condition = output.vpc_id == "vpc-12345678"
|
|
228
|
+
error_message = "VPC ID output should match mocked value"
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
assert {
|
|
232
|
+
condition = can(regex("^vpc-", output.vpc_id))
|
|
233
|
+
error_message = "VPC ID output should have correct format"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
run "test_conditional_resources_with_mocks" {
|
|
238
|
+
command = plan
|
|
239
|
+
|
|
240
|
+
variables {
|
|
241
|
+
create_bastion = true
|
|
242
|
+
create_nat_gateway = false
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
assert {
|
|
246
|
+
condition = length(aws_instance.bastion) == 1
|
|
247
|
+
error_message = "Bastion should be created when enabled"
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
assert {
|
|
251
|
+
condition = length(aws_nat_gateway.nat) == 0
|
|
252
|
+
error_message = "NAT gateway should not be created when disabled"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
run "test_tag_inheritance_with_mocks" {
|
|
257
|
+
command = plan
|
|
258
|
+
|
|
259
|
+
variables {
|
|
260
|
+
common_tags = {
|
|
261
|
+
Environment = "test"
|
|
262
|
+
ManagedBy = "Terraform"
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
assert {
|
|
267
|
+
condition = alltrue([
|
|
268
|
+
for key in keys(var.common_tags) :
|
|
269
|
+
contains(keys(aws_instance.example.tags), key)
|
|
270
|
+
])
|
|
271
|
+
error_message = "All common tags should be present on instance"
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
run "test_invalid_cidr_with_mocks" {
|
|
276
|
+
command = plan
|
|
277
|
+
|
|
278
|
+
variables {
|
|
279
|
+
vpc_cidr = "invalid"
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
expect_failures = [
|
|
283
|
+
var.vpc_cidr
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
run "setup_vpc_with_mocks" {
|
|
288
|
+
command = plan
|
|
289
|
+
|
|
290
|
+
variables {
|
|
291
|
+
vpc_cidr = "10.0.0.0/16"
|
|
292
|
+
vpc_name = "test-vpc"
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
assert {
|
|
296
|
+
condition = aws_vpc.main.cidr_block == "10.0.0.0/16"
|
|
297
|
+
error_message = "VPC CIDR should match input"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
run "test_subnet_references_vpc_with_mocks" {
|
|
302
|
+
command = plan
|
|
303
|
+
|
|
304
|
+
variables {
|
|
305
|
+
vpc_id = run.setup_vpc_with_mocks.vpc_id
|
|
306
|
+
subnet_cidr = "10.0.1.0/24"
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
assert {
|
|
310
|
+
condition = aws_subnet.example.vpc_id == run.setup_vpc_with_mocks.vpc_id
|
|
311
|
+
error_message = "Subnet should reference VPC from previous run"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
```
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Mock Providers
|
|
2
|
+
|
|
3
|
+
Mock providers simulate provider behavior without creating real infrastructure (Terraform 1.7.0+). Use them for fast, credential-free unit tests.
|
|
4
|
+
|
|
5
|
+
## Basic Mock Provider
|
|
6
|
+
|
|
7
|
+
```hcl
|
|
8
|
+
mock_provider "aws" {
|
|
9
|
+
mock_resource "aws_instance" {
|
|
10
|
+
defaults = {
|
|
11
|
+
id = "i-1234567890abcdef0"
|
|
12
|
+
instance_type = "t2.micro"
|
|
13
|
+
ami = "ami-12345678"
|
|
14
|
+
public_ip = "203.0.113.1"
|
|
15
|
+
private_ip = "10.0.1.100"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mock_data "aws_ami" {
|
|
20
|
+
defaults = {
|
|
21
|
+
id = "ami-0c55b159cbfafe1f0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
mock_data "aws_availability_zones" {
|
|
26
|
+
defaults = {
|
|
27
|
+
names = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
run "test_with_mocks" {
|
|
33
|
+
command = plan # Mocks only work with plan mode
|
|
34
|
+
|
|
35
|
+
assert {
|
|
36
|
+
condition = aws_instance.example.id == "i-1234567890abcdef0"
|
|
37
|
+
error_message = "Mock instance ID should match"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Aliased Mock Provider
|
|
43
|
+
|
|
44
|
+
```hcl
|
|
45
|
+
mock_provider "aws" {
|
|
46
|
+
alias = "mocked"
|
|
47
|
+
|
|
48
|
+
mock_resource "aws_s3_bucket" {
|
|
49
|
+
defaults = {
|
|
50
|
+
id = "test-bucket-12345"
|
|
51
|
+
arn = "arn:aws:s3:::test-bucket-12345"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
run "test_with_aliased_mock" {
|
|
57
|
+
command = plan
|
|
58
|
+
|
|
59
|
+
providers = {
|
|
60
|
+
aws = provider.aws.mocked
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
assert {
|
|
64
|
+
condition = aws_s3_bucket.example.id == "test-bucket-12345"
|
|
65
|
+
error_message = "Bucket ID should match mock"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Common Mock Defaults
|
|
71
|
+
|
|
72
|
+
```hcl
|
|
73
|
+
mock_provider "aws" {
|
|
74
|
+
mock_resource "aws_instance" {
|
|
75
|
+
defaults = {
|
|
76
|
+
id = "i-1234567890abcdef0"
|
|
77
|
+
arn = "arn:aws:ec2:us-west-2:123456789012:instance/i-1234567890abcdef0"
|
|
78
|
+
instance_type = "t2.micro"
|
|
79
|
+
ami = "ami-12345678"
|
|
80
|
+
availability_zone = "us-west-2a"
|
|
81
|
+
subnet_id = "subnet-12345678"
|
|
82
|
+
vpc_security_group_ids = ["sg-12345678"]
|
|
83
|
+
associate_public_ip_address = true
|
|
84
|
+
public_ip = "203.0.113.1"
|
|
85
|
+
private_ip = "10.0.1.100"
|
|
86
|
+
tags = {}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
mock_resource "aws_vpc" {
|
|
91
|
+
defaults = {
|
|
92
|
+
id = "vpc-12345678"
|
|
93
|
+
arn = "arn:aws:ec2:us-west-2:123456789012:vpc/vpc-12345678"
|
|
94
|
+
cidr_block = "10.0.0.0/16"
|
|
95
|
+
enable_dns_hostnames = true
|
|
96
|
+
enable_dns_support = true
|
|
97
|
+
instance_tenancy = "default"
|
|
98
|
+
tags = {}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
mock_resource "aws_subnet" {
|
|
103
|
+
defaults = {
|
|
104
|
+
id = "subnet-12345678"
|
|
105
|
+
arn = "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-12345678"
|
|
106
|
+
vpc_id = "vpc-12345678"
|
|
107
|
+
cidr_block = "10.0.1.0/24"
|
|
108
|
+
availability_zone = "us-west-2a"
|
|
109
|
+
map_public_ip_on_launch = false
|
|
110
|
+
tags = {}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
mock_resource "aws_s3_bucket" {
|
|
115
|
+
defaults = {
|
|
116
|
+
id = "test-bucket-12345"
|
|
117
|
+
arn = "arn:aws:s3:::test-bucket-12345"
|
|
118
|
+
bucket = "test-bucket-12345"
|
|
119
|
+
bucket_domain_name = "test-bucket-12345.s3.amazonaws.com"
|
|
120
|
+
region = "us-west-2"
|
|
121
|
+
tags = {}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
mock_data "aws_ami" {
|
|
126
|
+
defaults = {
|
|
127
|
+
id = "ami-0c55b159cbfafe1f0"
|
|
128
|
+
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20210430"
|
|
129
|
+
architecture = "x86_64"
|
|
130
|
+
root_device_type = "ebs"
|
|
131
|
+
virtualization_type = "hvm"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
mock_data "aws_availability_zones" {
|
|
136
|
+
defaults = {
|
|
137
|
+
names = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
|
138
|
+
zone_ids = ["usw2-az1", "usw2-az2", "usw2-az3"]
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
mock_data "aws_vpc" {
|
|
143
|
+
defaults = {
|
|
144
|
+
id = "vpc-12345678"
|
|
145
|
+
cidr_block = "10.0.0.0/16"
|
|
146
|
+
enable_dns_hostnames = true
|
|
147
|
+
enable_dns_support = true
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## When to Use Mocks
|
|
154
|
+
|
|
155
|
+
**Good fit:**
|
|
156
|
+
- Testing Terraform logic, conditionals, `for_each`/`count` expressions
|
|
157
|
+
- Validating variable transformations and output calculations
|
|
158
|
+
- Local development without cloud credentials
|
|
159
|
+
- Fast CI/CD feedback loops
|
|
160
|
+
|
|
161
|
+
**Not a good fit:**
|
|
162
|
+
- Validating actual provider API behavior
|
|
163
|
+
- Testing real resource creation side effects
|
|
164
|
+
- End-to-end integration testing
|
|
165
|
+
|
|
166
|
+
## Limitations
|
|
167
|
+
|
|
168
|
+
- **Plan mode only** — mocks don't work with `command = apply`
|
|
169
|
+
- Mock defaults may not reflect real computed attribute values
|
|
170
|
+
- Mocks need manual updates when provider schemas change
|
|
171
|
+
- Can't test real resource dependencies or timing
|