Skip to content

Commit

Permalink
Promoting Memorystore to GA (#12112) (#837)
Browse files Browse the repository at this point in the history
[upstream:61370a87fcc2c9f8f9040b692b728c6ba20077e4]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Oct 30, 2024
1 parent 01f837e commit b1f39e4
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 0 deletions.
15 changes: 15 additions & 0 deletions memorystore_instance_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"
}
43 changes: 43 additions & 0 deletions memorystore_instance_basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resource "google_memorystore_instance" "instance-basic" {
instance_id = "basic-instance-${local.name_suffix}"
shard_count = 3
desired_psc_auto_connections {
network = google_compute_network.producer_net.id
project_id = data.google_project.project.project_id
}
location = "us-central1"
deletion_protection_enabled = false
depends_on = [
google_network_connectivity_service_connection_policy.default
]

lifecycle {
prevent_destroy = "true-${local.name_suffix}"
}
}

resource "google_network_connectivity_service_connection_policy" "default" {
name = "my-policy-${local.name_suffix}"
location = "us-central1"
service_class = "gcp-memorystore"
description = "my basic service connection policy"
network = google_compute_network.producer_net.id
psc_config {
subnetworks = [google_compute_subnetwork.producer_subnet.id]
}
}

resource "google_compute_subnetwork" "producer_subnet" {
name = "my-subnet-${local.name_suffix}"
ip_cidr_range = "10.0.0.248/29"
region = "us-central1"
network = google_compute_network.producer_net.id
}

resource "google_compute_network" "producer_net" {
name = "my-network-${local.name_suffix}"
auto_create_subnetworks = false
}

data "google_project" "project" {
}
7 changes: 7 additions & 0 deletions memorystore_instance_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 memorystore_instance_basic/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Memorystore Instance Basic - Terraform

## Setup

<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="memorystore_instance_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 memorystore_instance_full/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"
}
66 changes: 66 additions & 0 deletions memorystore_instance_full/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
resource "google_memorystore_instance" "instance-full" {
instance_id = "full-instance-${local.name_suffix}"
shard_count = 3
desired_psc_auto_connections {
network = google_compute_network.producer_net.id
project_id = data.google_project.project.project_id
}
location = "us-central1"
replica_count = 2
node_type = "SHARED_CORE_NANO"
transit_encryption_mode = "TRANSIT_ENCRYPTION_DISABLED"
authorization_mode = "AUTH_DISABLED"
engine_configs = {
maxmemory-policy = "volatile-ttl"
}
zone_distribution_config {
mode = "SINGLE_ZONE"
zone = "us-central1-b"
}
engine_version = "VALKEY_7_2"
deletion_protection_enabled = false
mode = "CLUSTER"
persistence_config {
mode = "RDB"
rdb_config {
rdb_snapshot_period = "ONE_HOUR"
rdb_snapshot_start_time = "2024-10-02T15:01:23Z"
}
}
labels = {
"abc" : "xyz"
}
depends_on = [
google_network_connectivity_service_connection_policy.default
]

lifecycle {
prevent_destroy = "true-${local.name_suffix}"
}
}

resource "google_network_connectivity_service_connection_policy" "default" {
name = "my-policy-${local.name_suffix}"
location = "us-central1"
service_class = "gcp-memorystore"
description = "my basic service connection policy"
network = google_compute_network.producer_net.id
psc_config {
subnetworks = [google_compute_subnetwork.producer_subnet.id]
}
}

resource "google_compute_subnetwork" "producer_subnet" {
name = "my-subnet-${local.name_suffix}"
ip_cidr_range = "10.0.0.248/29"
region = "us-central1"
network = google_compute_network.producer_net.id
}

resource "google_compute_network" "producer_net" {
name = "my-network-${local.name_suffix}"
auto_create_subnetworks = false
}

data "google_project" "project" {
}
7 changes: 7 additions & 0 deletions memorystore_instance_full/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 memorystore_instance_full/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Memorystore Instance Full - Terraform

## Setup

<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="memorystore_instance_full" 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 memorystore_instance_persistence_aof/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"
}
48 changes: 48 additions & 0 deletions memorystore_instance_persistence_aof/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
resource "google_memorystore_instance" "instance-persistence-aof" {
instance_id = "aof-instance-${local.name_suffix}"
shard_count = 3
desired_psc_auto_connections {
network = google_compute_network.producer_net.id
project_id = data.google_project.project.project_id
}
location = "us-central1"
persistence_config {
mode = "AOF"
aof_config {
append_fsync = "EVERY_SEC"
}
}
depends_on = [
google_network_connectivity_service_connection_policy.default
]
deletion_protection_enabled = false
lifecycle {
prevent_destroy = "true-${local.name_suffix}"
}
}

resource "google_network_connectivity_service_connection_policy" "default" {
name = "my-policy-${local.name_suffix}"
location = "us-central1"
service_class = "gcp-memorystore"
description = "my basic service connection policy"
network = google_compute_network.producer_net.id
psc_config {
subnetworks = [google_compute_subnetwork.producer_subnet.id]
}
}

resource "google_compute_subnetwork" "producer_subnet" {
name = "my-subnet-${local.name_suffix}"
ip_cidr_range = "10.0.0.248/29"
region = "us-central1"
network = google_compute_network.producer_net.id
}

resource "google_compute_network" "producer_net" {
name = "my-network-${local.name_suffix}"
auto_create_subnetworks = false
}

data "google_project" "project" {
}
7 changes: 7 additions & 0 deletions memorystore_instance_persistence_aof/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

0 comments on commit b1f39e4

Please sign in to comment.