Skip to content

Commit

Permalink
fix wording
Browse files Browse the repository at this point in the history
  • Loading branch information
thoward committed Jan 30, 2025
1 parent 8b0d8d3 commit 1993a5f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
13 changes: 8 additions & 5 deletions content/tutorials/custom-policy-pack/create-policy-pack/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ While this example is a useful policy, it's not what we need right now. Let's de
Replace the contents of `index.ts` with the following:

```typescript
{{< example-program-snippet path="custom-policy-pack-typescript" language="typescript">}}
{{< example-program-snippet path="custom-policy-pack" language="typescript">}}
```

Here we define three different policies:
Expand Down Expand Up @@ -170,7 +170,10 @@ Current stack resources (5):
Finally we assemble the policies into a policy pack object, giving it the name `custom-policy-pack`.

{{% notes type="tip" %}}
**Writing Testable Code**: We've structured this code to be a little bit more readable than the template example, and also more testable. Instead of defining everything in one big nested object, we break each policy out into its own definition and then assemble the policy pack at the end. We use the `export` keyword to make these policies available to the testing framework (although not technically necessary for the policy pack itself). Have a look at the `tests` directory to see an example of writing tests for each policy.
**Writing Testable Code**: We've structured this code to be a little bit more readable than the template example, and also more testable. Instead of defining everything in one big nested object, we break each policy out into its own definition and then assemble the policy pack at the end. We use the `export` keyword to make these policies available to the testing framework (although not technically necessary for the policy pack itself).

Have a look at the [`tests`](https://github.com/pulumi/docs/blob/master/static/programs/custom-policy-pack-typescript/tests/) directory in the [full version of this example](https://github.com/pulumi/docs/blob/master/static/programs/custom-policy-pack-typescript/) to see how you can write unit tests for each policy.

{{% /notes %}}

{{% /choosable %}}
Expand All @@ -180,7 +183,7 @@ Finally we assemble the policies into a policy pack object, giving it the name `
Replace the contents of `__main__.py` with the following:

```python
{{< example-program-snippet path="custom-policy-pack-python" file="policies.py" language="python">}}
{{< example-program-snippet path="custom-policy-pack" file="policies.py" language="python">}}
```

Here we define three different policies:
Expand Down Expand Up @@ -216,11 +219,11 @@ Current stack resources (5):
Finally we assemble the policies into a policy pack object in `__main__.py`, giving it the name `custom-policy-pack`.

```python
{{< example-program-snippet path="custom-policy-pack-python" file="__main__.py" language="python">}}
{{< example-program-snippet path="custom-policy-pack" file="__main__.py" language="python">}}
```

{{% notes type="tip" %}}
**Writing Testable Code**: We've structured this code to be a little bit more readable and testable than the template example. The `PolicyPack` definition is in `__main__.py` while the policies are in `policies.py`. This allows us to import the policies into to the testing framework, without including the `PolicyPack`, which would cause a unit test run to hang. Have a look at the `policy_tests.py` file to see an example of writing tests for each policy.
**Writing Testable Code**: We've structured this code to be a little bit more readable and testable than the template example. In the [full version of this example](https://github.com/pulumi/docs/blob/master/static/programs/custom-policy-pack-python/), the `PolicyPack` definition is in [`__main__.py`](https://github.com/pulumi/docs/blob/master/static/programs/custom-policy-pack-python/__main__.py) while the policies are in [`policies.py`](https://github.com/pulumi/docs/blob/master/static/programs/custom-policy-pack-python/policies.py). This allows us to import the policies into to the testing framework, without including the `PolicyPack`, which would cause a unit test run to hang. Have a look at the [`policy_tests.py`](https://github.com/pulumi/docs/blob/master/static/programs/custom-policy-pack-python/policy_tests.py) file to see how you can write unit tests for each policy.
{{% /notes %}}

{{% /choosable %}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Follow the prompts as usual to set up your project.
Below are examples of non-compliant resources defined in Pulumi. Replace the contents of `index.ts` with this code.

```typescript
{{< example-program-snippet path="custom-policy-pack-integration-test-typescript" file="index.non-compliant.ts" language="typescript" >}}
{{< example-program-snippet path="custom-policy-pack-integration-test" file="index.non-compliant.ts" language="typescript" >}}
```

{{% /choosable %}}
Expand All @@ -47,7 +47,7 @@ Follow the prompts as usual to set up your project.
Below are examples of non-compliant resources defined in Pulumi. Replace the contents of `__main__.py` with this code.

```python
{{< example-program-snippet path="custom-policy-pack-integration-test-python" file="non-compliant.py" language="python" >}}
{{< example-program-snippet path="custom-policy-pack-integration-test" file="non_compliant.py" language="python" >}}
```

{{% /choosable %}}
Expand All @@ -71,6 +71,7 @@ From the root of the Pulumi project, run `pulumi preview` with the `--policy-pac

```sh
$ pulumi preview --policy-pack ../custom-policy-pack-typescript

Loading policy packs...

Type Name Plan
Expand Down Expand Up @@ -146,7 +147,7 @@ We need to:
Replace the contents of `index.ts` with this code.

```python
{{< example-program-snippet path="custom-policy-pack-integration-test-typescript" file="index.ts" language="typescript" >}}
{{< example-program-snippet path="custom-policy-pack-integration-test" file="index.ts" language="typescript" >}}
```

{{% /choosable %}}
Expand All @@ -156,7 +157,7 @@ Replace the contents of `index.ts` with this code.
Replace the contents of `__main__.py` with this code.

```python
{{< example-program-snippet path="custom-policy-pack-integration-test-python" file="__main__.py" language="python" >}}
{{< example-program-snippet path="custom-policy-pack-integration-test" file="__main__.py" language="python" >}}
```

{{% /choosable %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

// Create an AWS S3 Bucket
const bucket = new aws.s3.BucketV2("my-bucket", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

// Create an AWS S3 Bucket
const bucket = new aws.s3.BucketV2("my-bucket", {
Expand Down

0 comments on commit 1993a5f

Please sign in to comment.