Skip to content

Commit

Permalink
through 6
Browse files Browse the repository at this point in the history
Signed-off-by: Will <[email protected]>
  • Loading branch information
wdower committed Dec 5, 2024
1 parent b5aa7c2 commit 4d5056d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/courses/advanced/03.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ InSpec profiles consist of automated tests, that align to security requirements,

::: details Review

<<<<<<< HEAD
If you don't have the `my_nginx` profile, run the following command to initialize your InSpec profile.
=======
If you don't have `my_nginx` profile, run the following command to initialize your InSpec profile.

>>>>>>> 957bd3d260b8f364c6a5a7a06d09a8cf85708499
```
inspec init profile my_nginx
```
Expand Down
4 changes: 2 additions & 2 deletions src/courses/advanced/04.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Note that the `libraries` directory is not created by default within a profile w

Once you create and populate a custom resource Ruby file inside the `libraries` directory, it can be utilized inside your local profile just like the core resources.

### 6.1 Resource Structure
### Resource Structure

Resources are written as regular Ruby classes, which inherit from the base `inspec.resource` class. The number (1) specifies the version of the parent class that this resource plugin uses. As Chef InSpec evolves, this interface may change and may require a higher version.

Expand All @@ -46,7 +46,7 @@ The following methods are available to the resource:
- `inspec` - Contains a registry of all other resources to interact with the operating system or target in general.
- `skip_resource` - A resource may call this method to indicate that requirements aren’t met. All tests that use this resource will be marked as skipped.

### 6.3 The `etc_hosts` example
### The `etc_hosts` example

Let's look at a simple default resource to get an idea how these resources are used. We'll take a look at the [source code](https://github.com/inspec/inspec/blob/526b52657be571ba1573c12d666dc1f6330f2307/lib/inspec/resources/etc_hosts.rb) for the InSpec resource that models an operating system's hostfile, which is a simple file where we can map IP addresses (e.g. 198.162.8.1) to domain names (e.g. my-heimdall-deployment.my-domain.dev) without having to add a record to a DNS server somewhere.

Expand Down
1 change: 1 addition & 0 deletions src/courses/advanced/05.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ All the tests should pass!
::: tip Exercise!
As a solo exercise, try to create a method in the git.rb file to check what the last commit is.
:::

::: important This is Test-Driven Development!
Did you notice the overall arc of how we wrote this resource? We started with a set of tests before we even wrote any resource code, so we _knew_ we would start out with a failing profile.

Expand Down
11 changes: 7 additions & 4 deletions src/courses/advanced/06.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ headerDepth: 3

## Custom Resource - Docker

Let's try a more complicated example by creating a resource that can parse a `docker-compose` file.
Let's try a more complicated example by creating a resource that can parse a Docker Compose file.

If you've ever deployed containerized applications before, you might be familiar with [Docker Compose](https://docs.docker.com/compose/), which is a container orchestration feature of the Docker container runtime. Docker Compose works by reading a YAML specfile called the Compose file that defines attributes about a set of containers we want to deploy and how they connect together. We don't need to know too much about how to run Docker Compose for this class, but let's say that we want to write an InSpec resource for testing that our Compose files match the configuration we expect.

### Create a new profile and set up Docker files

Expand All @@ -32,7 +34,7 @@ services:
tty: true
```
We will continue writing our controls to check against this docker file:
We will continue writing our controls to check against this Compose file.
::: code-tabs
Expand Down Expand Up @@ -68,7 +70,7 @@ describe yaml('file_name') do
end
```

We test early and often. We know that the test we wrote is not complete, but we can see if we are on the right track. Remember that the command line output can help guide your development!
We test early and often, according to a test-driven development paradigm. We know that the test we wrote is not complete, but we can see if we are on the right track. Remember that the command line output can help guide your development!

::: code-tabs

Expand Down Expand Up @@ -127,9 +129,10 @@ Target ID: 6dcb9e6f-5ede-5474-9521-595fadf5c7ce
Test Summary: 2 successful, 0 failures, 0 skipped
```
:::
Much like our `git ` example, this series of tests works, but it could be made better. We essentially parsed the Compose file with a simple YAML file parser. If anybody else reads this code, it might not be clear what specific system component we are testing. Recall that we want InSpec tests to be extremely intuitive to read, even by people who did not write the code (and even by people who are not InSpec developers!).
:::danger If you received an error above! - Concept Check
If you saw this as your output:
Expand Down

0 comments on commit 4d5056d

Please sign in to comment.