GCP Essential Contacts with Terraform

Hello Community,

I'm running into an issue while creating GCP essential contacts using terraform.

Below code creates an contact in the project:

 
variable "project" {
  description = "GCP project ID."
  type = string
}
 
variable "essential-contact" {
  description = "Value for Product Owner essential contact"
  type = string
  default = "[email protected]"
}
resource "google_essential_contacts_contact" "contact_test" {

  parent = "projects/${var.project}"
  email =  var.essential-contact  
  language_tag = "en-US"
  notification_category_subscriptions = ["ALL","SECURITY"]
}
 
However, problem starts when I try to deploy the contacts in different project.
It destroys the contacts from the project where it was created earlier and then creates it fresh in new project. This is weird behaviors compares all other modules I deploy using terraform.
 
Generally all the resources are at the project level. I don't understand why essential contacts are now working as expected.
 
Really appreciate any guidance in this case.
 
 
 
1 3 60
3 REPLIES 3

Hello @bansodab  ,Welcome on Google Cloud Community.

Did you've tried to use tf workspaces ? It will create separate tfstate file for each workspace. Maybe, if you will create separate workspace, deploy code for ProjectA, then you will switch workspace to project2 and deploy code for Project2, TF will not destroy resources from first project? Ofc, projectIDs must be different 😄 

TF docs: https://developer.hashicorp.com/terraform/cli/workspaces

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost Sessionize Youtube

@DamianS  Thanks for response.

We have tfstate file for each project stored in respective GCS buckets. I've also verified the state files. Nothing conflicts there. I've 50+ projects which I deploy using my TF environment to deploy many other services like BigQuery, GCS Buckets, DataProc. Never seen such issue before because every deployment is always project specific. We select the project for which deployment needs to run. And of course, project IDs are unique 😀

Just like I thought 😄 but had to ask anyway 😄 I'll check something and back to you.

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost Sessionize Youtube