Terraform for GCP How to create Memorystore (Redis)
Hi, this is Paul, and welcome to the #30 part of my Terraform guide. Today we will discuss, how to create a Memorystore Redis using the Terraform script.
Add Role for Service Account
First, to create a Memorystore you need to add a Role Cloud Memorystore Redis Admin
to you're Service Account. How to add permissions we already discussed in this article:
Understanding the Terraform Block
resource "google_redis_instance" "demo_redis" {
name = "demo-redis"
memory_size_gb = 1
tier = "BASIC"
location_id = "asia-southeast1-a"
authorized_network = "default"
redis_version = "REDIS_5_0"
display_name = "Demo Redis"
}
The resource
Section
The resource
block in Terraform specifies an infrastructure component that needs to be created, updated, or destroyed. resource
takes two main arguments: the type of resource and a local name. In this case, google_redis_instance
is a resource type provided by Google's Terraform provider, and demo_redis
is the local name we use to refer to this resource within our Terraform configuration.
Redis Instance Parameters
name
: A unique name for the resource within the project and region, here specified asdemo-redis
.memory_size_gb
: The amount of memory allocated to the Redis instance, in gigabytes. Here, it is set to 1 GB.tier
: The service tier for the Redis instance.BASIC
indicates a basic level without replication; another possible tier isSTANDARD
, which includes replication.location_id
: The identifier for the zone where the Redis instance will be located. Specified here asasia-southeast1-a
.authorized_network
: The name of the VPC network where this Redis instance is allowed to be used.default
refers to the default network in the project.redis_version
: The version of Redis that will be used. Specified here asREDIS_5_0
.display_name
: A human-readable name for the instance that will appear in the Google Cloud console, listed here asDemo Redis
.
Conclusion
Using Terraform to manage infrastructure simplifies the deployment and scaling of applications by streamlining cloud resource management through code. The provided example demonstrates how you can easily configure and manage a Redis instance in Google Cloud using clear and understandable Terraform configurations. This makes Terraform an excellent choice for automating cloud infrastructure.
Thank you for reading until the end. Before you go:
- Please consider clapping and following the writer! 👏
- Follow us on Twitter(X), LinkedIn