Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create region security policies rules #499

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions region_security_policy_rule_basic/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
25 changes: 25 additions & 0 deletions region_security_policy_rule_basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "google_compute_region_security_policy" "default" {
provider = google-beta

region = "us-west2"
name = "policyruletest-${local.name_suffix}"
description = "basic region security policy"
type = "CLOUD_ARMOR"
}

resource "google_compute_region_security_policy_rule" "policy_rule" {
provider = google-beta

region = "us-west2"
security_policy = google_compute_region_security_policy.default.name
description = "new rule"
priority = 100
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["10.10.0.0/16"]
}
}
action = "allow"
preview = true
}
7 changes: 7 additions & 0 deletions region_security_policy_rule_basic/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
79 changes: 79 additions & 0 deletions region_security_policy_rule_basic/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Region Security Policy Rule Basic - Terraform

## Setup

<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="region_security_policy_rule_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.

## Terraforming!

Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
the project name from the environment variable.

```bash
export GOOGLE_CLOUD_PROJECT={{project-id}}
```

After that, let's get Terraform started. Run the following to pull in the providers.

```bash
terraform init
```

With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!

```bash
terraform apply
```

Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.

```bash
yes
```


## Post-Apply

### Editing your config

Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.

```bash
terraform plan
```

So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
run a 'plan' again.

```bash
terraform plan
```

Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
at the 'yes' prompt.

```bash
terraform apply
```

```bash
yes
```

## Cleanup

Run the following to remove the resources Terraform provisioned:

```bash
terraform destroy
```
```bash
yes
```
15 changes: 15 additions & 0 deletions region_security_policy_rule_multiple_rules/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
42 changes: 42 additions & 0 deletions region_security_policy_rule_multiple_rules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "google_compute_region_security_policy" "default" {
provider = google-beta

region = "us-west2"
name = "policywithmultiplerules-${local.name_suffix}"
description = "basic region security policy"
type = "CLOUD_ARMOR"
}

resource "google_compute_region_security_policy_rule" "policy_rule_one" {
provider = google-beta

region = "us-west2"
security_policy = google_compute_region_security_policy.default.name
description = "new rule one"
priority = 100
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["10.10.0.0/16"]
}
}
action = "allow"
preview = true
}

resource "google_compute_region_security_policy_rule" "policy_rule_two" {
provider = google-beta

region = "us-west2"
security_policy = google_compute_region_security_policy.default.name
description = "new rule two"
priority = 101
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["192.168.0.0/16", "10.0.0.0/8"]
}
}
action = "allow"
preview = true
}
7 changes: 7 additions & 0 deletions region_security_policy_rule_multiple_rules/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
79 changes: 79 additions & 0 deletions region_security_policy_rule_multiple_rules/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Region Security Policy Rule Multiple Rules - Terraform

## Setup

<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="region_security_policy_rule_multiple_rules" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.

## Terraforming!

Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
the project name from the environment variable.

```bash
export GOOGLE_CLOUD_PROJECT={{project-id}}
```

After that, let's get Terraform started. Run the following to pull in the providers.

```bash
terraform init
```

With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!

```bash
terraform apply
```

Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.

```bash
yes
```


## Post-Apply

### Editing your config

Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.

```bash
terraform plan
```

So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
run a 'plan' again.

```bash
terraform plan
```

Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
at the 'yes' prompt.

```bash
terraform apply
```

```bash
yes
```

## Cleanup

Run the following to remove the resources Terraform provisioned:

```bash
terraform destroy
```
```bash
yes
```
15 changes: 15 additions & 0 deletions region_security_policy_with_user_defined_fields/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
21 changes: 21 additions & 0 deletions region_security_policy_with_user_defined_fields/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "google_compute_region_security_policy" "region-sec-policy-user-defined-fields" {
provider = google-beta

name = "my-sec-policy-user-defined-fields-${local.name_suffix}"
description = "with user defined fields"
type = "CLOUD_ARMOR_NETWORK"
user_defined_fields {
name = "SIG1_AT_0"
base = "UDP"
offset = 8
size = 2
mask = "0x8F00"
}
user_defined_fields {
name = "SIG2_AT_8"
base = "UDP"
offset = 16
size = 4
mask = "0xFFFFFFFF"
}
}
7 changes: 7 additions & 0 deletions region_security_policy_with_user_defined_fields/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
Loading