You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Design principles in action](#design-principles-in-action)
12
-
*[FAST stage design](#fast-stage-design)
13
-
*[Style guide reference](#style-guide-reference)
14
-
*[Interacting with checks and tools](#interacting-with-checks-and-tools)
10
+
-[The Zen of Fabric](#the-zen-of-fabric)
11
+
-[Design principles in action](#design-principles-in-action)
12
+
-[FAST stage design](#fast-stage-design)
13
+
-[Style guide reference](#style-guide-reference)
14
+
-[Interacting with checks and tools](#interacting-with-checks-and-tools)
15
15
-[Using and writing tests](#using-and-writing-tests)
16
-
*[Testing via README.md example blocks.](#testing-via-readmemd-example-blocks)
17
-
+[Testing examples against an inventory YAML](#testing-examples-against-an-inventory-yaml)
18
-
+[Using external files](#using-external-files)
19
-
+[Running tests for specific examples](#running-tests-for-specific-examples)
20
-
+[Generating the inventory automatically](#generating-the-inventory-automatically)
21
-
+[Building tests for blueprints](#building-tests-for-blueprints)
22
-
*[Testing via `tfvars` and `yaml` (aka `tftest`-based tests)](#testing-via-tfvars-and-yaml-aka-tftest-based-tests)
23
-
+[Generating the inventory for `tftest`-based tests](#generating-the-inventory-for-tftest-based-tests)
24
-
*[Writing tests in Python (legacy approach)](#writing-tests-in-python-legacy-approach)
25
-
*[Running tests from a temporary directory](#running-tests-from-a-temporary-directory)
16
+
-[Testing via README.md example blocks.](#testing-via-readmemd-example-blocks)
17
+
-[Testing examples against an inventory YAML](#testing-examples-against-an-inventory-yaml)
18
+
-[Using external files](#using-external-files)
19
+
-[Running tests for specific examples](#running-tests-for-specific-examples)
20
+
-[Generating the inventory automatically](#generating-the-inventory-automatically)
21
+
-[Building tests for blueprints](#building-tests-for-blueprints)
22
+
-[Testing via `tfvars` and `yaml` (aka `tftest`-based tests)](#testing-via-tfvars-and-yaml-aka-tftest-based-tests)
23
+
-[Generating the inventory for `tftest`-based tests](#generating-the-inventory-for-tftest-based-tests)
24
+
-[Writing tests in Python (legacy approach)](#writing-tests-in-python-legacy-approach)
25
+
-[Running tests from a temporary directory](#running-tests-from-a-temporary-directory)
26
26
-[Fabric tools](#fabric-tools)
27
27
28
28
## I just found a bug / have a feature request
@@ -205,11 +205,11 @@ We have several such interfaces defined for IAM, log sinks, organizational polic
205
205
#### Design interfaces to support actual usage
206
206
207
207
> “When developing a module, look for opportunities to take a little bit of extra suffering upon yourself in order to reduce the suffering of your users.”
208
-
>
208
+
>
209
209
> “Providing choice is good, but interfaces should be designed to make the common case as simple as possible”
210
-
>
210
+
>
211
211
> — John Ousterhout in "A Philosophy of Software Design"
212
-
212
+
213
213
Variables should not simply map to the underlying resource attributes, but their **interfaces should be designed to match common use cases** to reduce friction and offer the highest possible degree of legibility.
214
214
215
215
This translates into different practical approaches:
@@ -300,7 +300,6 @@ module "project" {
300
300
>
301
301
> — John Ousterhout in "A Philosophy of Software Design"
302
302
303
-
304
303
Designing variable spaces is one of the most complex aspects to get right, as they are the main entry point through which users consume modules, examples and FAST stages. We always strive to **design small variable spaces by leveraging objects and implementing defaults** so that users can quickly produce highly readable code.
305
304
306
305
One of many examples of this approach comes from disk support in the `compute-vm` module, where preset defaults allow quick VM management with very few lines of code, and optional variables allow progressively expanding the code when more control is needed.
@@ -688,7 +687,7 @@ In the following sections we describe the three testing approaches we currently
688
687
-[tfvars-based tests](#testing-via-tfvars-and-yaml): allows you to test a module or blueprint by providing variables via tfvar files and an expected plan result in form of an inventory. This type of test is useful, for example, for FAST stages that don't have any examples within their READMEs.
689
688
-[Python-based (legacy) tests](#writing-tests-in-python--legacy-approach-): in some situations you might still want to interact directly with `tftest` via Python, if that's the case, use this method to write custom Python logic to test your module in any way you see fit.
690
689
691
-
### Testing via README.md example blocks.
690
+
### Testing via README.md example blocks
692
691
693
692
This is the preferred method to write tests for modules and blueprints. Example-based tests are triggered from [HCL Markdown fenced code blocks](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting) in any file named README.md, hence there's no need to create any additional files or revert to Python to write a test. Most of our documentation examples are using this method.
@@ -814,6 +814,7 @@ As mentioned before, we use `pytest` as our test runner, so you can use any of t
814
814
Example-based test are named based on the section within the README.md that contains them. You can use this name to select specific tests.
815
815
816
816
Here we show a few commonly used selection commands:
817
+
817
818
- Run all examples:
818
819
- `pytest tests/examples/`
819
820
- Run all examples for modules:
@@ -919,7 +920,7 @@ The second approach to testing requires you to:
919
920
- define `yaml` "inventory" files with the plan and output results you want to test
920
921
- declare which of these files need to be run as tests in a `tftest.yaml` file
921
922
922
-
Let's go through each step in succession, assuming you are testing the new `net-glb` module.
923
+
Let's go through each step in succession, assuming you are testing the new `net-lb-app-ext` module.
923
924
924
925
First create a new folder under `tests/modules` replacing any dash in the module name with underscores. Note that if you were testing a blueprint the folder would go in `tests/blueprints`.
925
926
@@ -973,7 +974,7 @@ Create as many pairs of `tfvars`/`yaml` files as you need to test every scenario
973
974
974
975
```yaml
975
976
# file: tests/modules/net_glb/tftest.yaml
976
-
module: modules/net-glb
977
+
module: modules/net-lb-app-ext
977
978
# if there are variables shared among all tests you can define a common file
978
979
# common_tfvars:
979
980
# - defaults.tfvars
@@ -1052,22 +1053,24 @@ You can now use this output to create the inventory file for your test. As menti
1052
1053
Where possible, we recommend using the testing methods described in the previous sections. However, if you need it, you can still write tests using Python directly.
1053
1054
1054
1055
In general, you should try to use the `plan_summary` fixture, which runs a a terraform plan and returns a `PlanSummary` object. The most important arguments to `plan_summary` are:
1056
+
1055
1057
- the path of the Terraform module you want to test, relative to the root of the repository
1056
1058
- a list of paths representing the tfvars file to pass in to terraform. These paths are relative to the python file defining the test.
1057
1059
1058
1060
If successful, `plan_summary` will return a `PlanSummary` object with the `values`, `counts` and `outputs` attributes following the same semantics described in the previous section. You can use this fields to write your custom tests.
1059
1061
1060
-
Like before let's imagine we're writing a (python) test for `net-glb` module. First create a new folder under `tests/modules` replacing any dash in the module name with underscores. You also need to create an empty `__init__.py` file in it, to ensure `pytest` discovers you new tests automatically.
1062
+
Like before let's imagine we're writing a (python) test for `net-lb-app-ext` module. First create a new folder under `tests/modules` replacing any dash in the module name with underscores. You also need to create an empty `__init__.py` file in it, to ensure `pytest` discovers you new tests automatically.
1061
1063
1062
1064
```bash
1063
1065
mkdir tests/modules/net_glb
1064
1066
touch tests/modules/net_glb/__init__.py
1065
1067
```
1066
1068
1067
1069
Now create a file containing your tests, e.g. `test_plan.py`:
@@ -1081,16 +1084,19 @@ Most of the time you can run tests using the `pytest` command as described in pr
1081
1084
To enable this option, just define the environment variable `TFTEST_COPY` and any tests using the `plan_summary` fixture will automatically run from a temporary directory.
1082
1085
1083
1086
Running tests from temporary directories is useful if:
1087
+
1084
1088
- you're running tests in parallel using `pytest-xdist`. In this case, just run you tests as follows:
1089
+
1085
1090
```bash
1086
1091
TFTEST_COPY=1 pytest -n 4
1087
1092
```
1093
+
1088
1094
- you're running tests for the `fast/` directory which contain tfvars and auto.tfvars files (which are read by terraform automatically) making your tests fail. In this case, you can run
1095
+
1089
1096
```
1090
1097
TFTEST_COPY=1 pytest fast/
1091
1098
```
1092
1099
1093
-
1094
1100
## Fabric tools
1095
1101
1096
1102
The main tool you will interact with in development is `tfdoc`, used to generate file, output and variable tables in README documents.
Copy file name to clipboardExpand all lines: blueprints/apigee/README.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,5 +20,6 @@ The blueprints in this folder contain a variety of deployment scenarios for Apig
20
20
21
21
The following blueprints demonstrate a set of networking scenarios that can be implemented for Apigee X deployments.
22
22
23
-
#### Apigee X - Northbound: GLB with PSC Neg, Southbouth: PSC with ILB (L7) and Hybrid NEG
24
-
<ahref="./network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg"title="Apigee X - Northbound: GLB with PSC Neg, Southbouth: PSC with ILB (L7) and Hybrid NEG"><imgsrc="./network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/diagram.png"align="left"width="280px"></a>This [blueprint](./network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/) shows how to expose an on-prem target backend to clients in the Internet.
23
+
#### Apigee X - Northbound: External Application LB with PSC Neg, Southbouth: PSC with Internal Application LB and Hybrid NEG
24
+
25
+
<ahref="./network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg"title="Northbound: External Application LB with PSC Neg, Southbouth: PSC with Internal Application LB and Hybrid NEG"><imgsrc="./network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/diagram.png"align="left"width="280px"></a>This [blueprint](./network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/) shows how to expose an on-prem target backend to clients in the Internet.
Copy file name to clipboardExpand all lines: blueprints/apigee/network-patterns/README.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,5 +2,6 @@
2
2
3
3
The blueprints in this folder demonstrate a set of networking scenarios that can be implemented for Apigee X deployments.
4
4
5
-
## Apigee X - Northbound: GLB with PSC Neg, Southbouth: PSC with ILB (L7) and Hybrid NEG
6
-
<ahref="./nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg"title="Apigee X - Northbound: GLB with PSC Neg, Southbouth: PSC with ILB (L7) and Hybrid NEG"><imgsrc="./nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/diagram.png"align="left"width="280px"></a>This [blueprint](./nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/) shows how to expose an on-prem target backend to clients in the Internet.g
5
+
## Northbound: External Application LB with PSC Neg, Southbouth: PSC with Internal Application LB and Hybrid NEG
6
+
7
+
<ahref="./nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg"title="Northbound: External Application LB with PSC Neg, Southbouth: PSC with Internal Application LB and Hybrid NEG"><imgsrc="./nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/diagram.png"align="left"width="280px"></a>This [blueprint](./nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/) shows how to expose an on-prem target backend to clients in the Internet.g
0 commit comments