Skip to content

Commit feed853

Browse files
authored
docs: Improve documentation (#37)
1 parent fbfed2f commit feed853

File tree

1 file changed

+37
-53
lines changed

1 file changed

+37
-53
lines changed

docs/index.md

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,28 @@
22

33
## Introduction
44

5-
### What is terraform
5+
### What is Terraform
66

7-
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.
7+
[Terraform](https://www.terraform.io/) is a tool for building, changing, and versioning infrastructure safely and efficiently.
88
Terraform can manage existing and popular service providers as well as custom in-house solutions.
99

1010
Configuration files describe to Terraform the components needed to run a single application or
1111
your entire datacenter. Terraform generates an execution plan describing what it will do to reach the
12-
desired state, and then executes it to build the described infrastructure or configuration.
12+
desired state, and then executes it to build the described infrastructure or configuration.
13+
1314
As the configuration changes, Terraform is able to determine what changed and create incremental execution
1415
plans which can be applied.
1516

16-
### How can this integration help you
17-
18-
Messing up a configuration can have terrible consequences.
19-
20-
By following the GitOps principles, in which all the configuration has to be applied as code,
21-
committed into a git repository (the single source of truth), and reviewed by the whole team,
22-
we can spot this kind of problem easily.
23-
24-
In case an error passed the reviews, a quick investigation would have revealed who and when
25-
changed the messed configuration, and fixing the issue would be as easy as reverting the
26-
configuration changes.
17+
### Terraform Provider for Sysdig
2718

2819
The Terraform Provider for Sysdig allows you to manage your configuration in Sysdig Secure
29-
and Sysdig Monitor as code, so this kind of scenario don't happen to you.
30-
31-
### What is a provider and how do they work
32-
33-
While resources are the primary construct in the Terraform language,
34-
the behaviors of resources rely on their associated resource types,
35-
and these types are defined by providers.
36-
37-
Each provider offers a set of named resource types, and defines
38-
for each resource type which arguments it accepts, which attributes it exports,
39-
and how changes to resources of that type are actually applied to remote APIs.
40-
41-
The Terraform Provider for Sysdig exposes resources like Alerts, Notification Channels,
42-
Falco Lists, Falco Macros, Policies, and many more, so you don't need to interact with the UI
43-
to configure those, and enabling you to define and update them as code.
44-
45-
For more information, check: [https://www.terraform.io/docs/configuration/providers.html](https://www.terraform.io/docs/configuration/providers.html)
20+
and Sysdig Monitor as code, allowing you to synchronize your declarative configuration with
21+
the configuration at the Platform.
4622

23+
This enables you several cases like:
24+
- Backup/restore
25+
- Disaster recovery
26+
- Configuration version management
4727

4828
## Installation
4929

@@ -59,10 +39,10 @@ for your OS/Architecture, extract it and move the executable under `$HOME/.terra
5939
this directory if it does not exist yet) as this link suggests:
6040
[https://www.terraform.io/docs/configuration/providers.html#third-party-plugins](https://www.terraform.io/docs/configuration/providers.html#third-party-plugins) .
6141

62-
## E2E example
42+
## Use example
6343

64-
Terraform understands that it needs to use the Sysdig provider when you specify a resource
65-
or data source with a name starting with `sysdig_*` (i.e.: `sysdig_user`)
44+
Terraform will use the Sysdig provider when you specify a [resource](https://www.terraform.io/docs/configuration/resources.html)
45+
or [data source](https://www.terraform.io/docs/configuration/data-sources.html) with a name starting with `sysdig_*` (i.e.: `sysdig_user`)
6646

6747
But in order to actually create valid requests to the API and create/update/remove those resources,
6848
you need to specify a correct API token for the product.
@@ -84,13 +64,13 @@ $ export SYSDIG_SECURE_API_TOKEN=323232323-3232-3232-32323232
8464
$ export SYSDIG_MONITOR_API_TOKEN=343434343-3434-3434-34343434
8565
```
8666

87-
Once you execute Terraform an apply the manifests, that env vars will be used to configure
88-
the provider and create API calls with them.
67+
Once you execute Terraform and apply the manifests, that env vars will be used to configure
68+
the provider and create API calls.
8969

9070
### Configure the provider: Using a tfvars file
9171

9272
To use a [tfvars file](https://www.terraform.io/docs/configuration/variables.html#variable-definitions-tfvars-files)
93-
you need to first create it, and specify the API tokens as variables, for example:
73+
you need to first create it, and specify the API tokens as [variables](https://www.terraform.io/docs/configuration/variables.html), for example:
9474

9575
```
9676
# File: terraform.tfvars
@@ -110,11 +90,14 @@ provider "sysdig" {
11090

11191
### Creating resources with Terraform
11292

113-
We are going to create a pair of rules able to detect SSH connections and shells spawned in containers.
93+
This is an example to create a pair of rules able to detect SSH connections and
94+
shells spawned in containers.
11495

115-
We start by defining a couple of rules in the `rules.tf` file. One rule will detect inbound and outbound connections
96+
Start by defining a couple of rules in the `rules.tf` file. One rule will detect inbound and outbound connections
11697
made to the port 22, and the other will detect a shell process being spawned.
11798

99+
For more information about the configuration blocks, see: [https://www.terraform.io/docs/configuration/syntax.html](https://www.terraform.io/docs/configuration/syntax.html)
100+
118101
```hcl
119102
resource "sysdig_secure_rule_network" "disallowed_ssh_connection" {
120103
name = "Disallowed SSH Connection detected"
@@ -139,7 +122,7 @@ resource "sysdig_secure_rule_process" "terminal_shell" {
139122
}
140123
```
141124

142-
Now we are going to create a policy in a file called `policy.tf` to define how these rules
125+
Now create a policy in a file called `policy.tf` to define how these rules
143126
are applied. The policy will stop the affected container and trigger a capture for
144127
further troubleshooting.
145128

@@ -169,7 +152,7 @@ With the given `scope`, the policy will only be applied to processes being execu
169152
scope = "container.id != \"\""
170153
```
171154

172-
Let’s do a terraform apply to apply these resources in the backend:
155+
Using `terraform apply` the resources are applied in the backend:
173156

174157
![Terraform apply creates the resources](./assets/img/terraform-apply-create-sysdig-provider.png)
175158

@@ -180,15 +163,15 @@ Let’s do a terraform apply to apply these resources in the backend:
180163
After applying the plan, Terraform reports that the 3 resources have been successfully created. The policy uses the
181164
rules created before, that’s why it’s the last one being created.
182165

183-
The resources have been created, let’s see how they look in Sysdig Secure:
166+
The resources have been created, this is how they look in Sysdig Secure:
184167

185168
![Terraform rules created in Sysdig Secure](./assets/img/terraform-rules-created-sysdig-secure.png)
186169

187170
![Terraform policy created in Sysdig Secure](./assets/img/terraform-policy-created-sysdig-secure.png)
188171

189-
Now we are protected against terminal shells or SSH connections in our container infrastructure using security as code.
190-
But wait, if this policy triggers we won’t notice unless we define a notification channel.
191-
Let’s create two notification channels, one for the email and another one for slack in a file called `notification.tf`:
172+
But now the problem is that, if this policy triggers there's no alert notice unless notification channels are defined.
173+
Creating two notification channels, one for the email and another one for slack in a file called `notification.tf`,
174+
will alert us when the policy is triggered:
192175

193176
```hcl
194177
resource "sysdig_secure_notification_channel" "devops-email" {
@@ -211,7 +194,7 @@ resource "sysdig_secure_notification_channel" "devops-slack" {
211194
}
212195
```
213196

214-
Let’s bind them to the policy as well modifying the file `policy.tf`, note the `notification_channels` property:
197+
Bind them to the policy, modifying the file `policy.tf`; note the `notification_channels` property:
215198

216199
```hcl
217200
resource "sysdig_secure_policy" "terminal_shell_or_ssh_in_container" {
@@ -236,24 +219,25 @@ resource "sysdig_secure_policy" "terminal_shell_or_ssh_in_container" {
236219
}
237220
```
238221

239-
If we do a `terraform apply`, it will tell us that it will create 2 new resources and modify the existing policy:
222+
Finally, doing a `terraform apply`, it will inform that it will create 2 new resources and modify the existing policy:
240223

241224
![Terraform apply updates the resources](./assets/img/terraform-apply-update-sysdig-provider.png)
242225

243-
After inputting **yes**, Terraform will create the notification channels and bind them to the policy, ensuring that the state in Monitor and Secure matches our state defined in the code.
226+
After inputting **yes**, Terraform will create the notification channels and bind them to the policy,
227+
ensuring that the state in Monitor and Secure matches our state defined in the code.
244228

245-
We can see those new resources appearing on Sysdig UI:
229+
This is how the resources appear on the Sysdig Secure UI:
246230

247231
![Terraform apply creates new notification channels](./assets/img/terraform-new-resources-notification-sysdig.png)
248232

249233
![Terraform updates the policy resource](./assets/img/terraform-updated-resources-policy-sysdig.png)
250234

251-
Now, if someone tries to update it manually, we can always re-apply our policies, and Terraform will
252-
restore the desired status from our `.tf` manifests.
235+
Now, if someone tries to update it manually, by re-applying the policies, Terraform will
236+
restore the desired status from the `.tf` manifests.
253237

254-
## Reference to resources documentation
238+
## Full Terraform resources documentation
255239

256-
You can check all the available resources and datasources for the Terraform Provider for Sysdig here:
240+
Check all the available resources and datasources for the Terraform Provider for Sysdig here:
257241

258242
[Terraform provider for Sysdig Datasources](./usage.md)
259243

0 commit comments

Comments
 (0)