Skip to content

574n13y/Google-Pub-Subtopic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google-Pub-Subtopic

Develop Terraform code for creating and managing Google Pub/Subtopic. Website

GCP

  • Create a GCP account in case you don't have one.

  • Once GCP account is created -> Create Project

  • Navigate to "IAM & Admin" -> click on service account iam

  • Create a service account -> Give nessary permission's as per your requirement. iam 1

  • Click on Created (in my case i have created terraform service account) service account navigate to "key" -> click on "ADD KEY" iam 2

  • Click on create new key -> Select json file - Click on create. iam 3

  • Once key is created, private key will be downloaded in you local pc, rename it to key.json iam 4 iam 5

  • Before starting with the terraform code make sure to 'enable' pub/sub service from marketplace

Github

  • Create a Repo

  • Write a code for creating and managing Google Pub/Subtopic.

  • Here is the demo code i created, you can use this or you can use my code main.tf

    # main.tf
    
    provider "google" {
    credentials = file("<path-to-service-account-key>")
    project     = "<your-project-id>"
     region      = "us-central1"  # Update with your desired region
    }
    
    module "pubsub_topic" {
     source = "./modules/pubsub-topic"
    
      topic_name = "example-topic"
    }
    
    
    
     # modules/pubsub-topic/main.tf
    
    variable "topic_name" {
     description = "The name of the Pub/Sub topic"
     type        = string
     }
    
    resource "google_pubsub_topic" "pubsub_topic" {
     name = var.topic_name
    }
    
    

    main Github

  • upload the key.json service account key

Terraform cloud

  • Login to Terraform cloud terra 0

  • Create a workspace terra 1

  • Click on Version control -> select github -> authenticate it with your github account -> select github repo -> Click on Create terra

  • Once workspace is created Add variable value and save it. terra 2

  • Click on Start new Plan terra 3

  • Terraform cloud will run the plan and show to the ouptup for the same. terraformcloud plan

  • Now cick on apply to make changes -> it will create a pubsub topic. applyper apply

Valiadtion

  • Plan plan 1 plan 2 plan 3

  • Apply apply 1 apply 2 apply 3

  • topics top top-details topics ps request ps

  • Subscriptions subscriptions sub details

                                                                  ***