DATAFORM/TERRAFORM - terraform can't destroy google_dataform_repository resource

Hello wonderful people!

 

I'm using Terraform to implement IaC for a project. I'm running my .tf files in Cloud Shell I'm using a block like this to create a google_dataform_repository resource:

 

#Create a Dataform repository
resource "google_dataform_repository" "XXXXXXXXXXXXX" {
  provider = google-beta
  name = var.YYYYYYYYYYYYYY
  display_name = var.YYYYYYYYYYYYYY
  service_account = google_service_account.dataform_service_account.email
  
  git_remote_settings {
      url = var.compute_git_remote_url
      default_branch = "main"
      
      ssh_authentication_config{
        user_private_key_secret_version = google_secret_manager_secret_version.git_secret_private_key_version.id
        host_public_key = var.compute_host_public_key
      }
  }

  workspace_compilation_overrides {
    default_database = var.compute_workspace_compilation_overrides_default_database
    schema_suffix = ""
    table_prefix = ""
  }
}

 

But everytime I try to destroy (terraform destroy) all of my resources, I get this error message:

Error: Error when reading or editing Repository: googleapi: Error 400: Resource '"projects/ZZZZZZ/us-south1/repositories/VVVVVVVVV"' has nested resources. If the API supports cascading delete, set 'force' to true to delete it and its nested resources.

Screenshot 2024-05-30 at 18.10.11.png

Is there a way to destroy that google_dataform_repository using Terraform? I don't want to do it manually.

--
Best regards
David Regalado
Web | Linkedin | Cloudskillsboost

Solved Solved
2 3 859
1 ACCEPTED SOLUTION

Hello @davidregalado25  ,Welcome on Google Cloud Community.

Unfortunately this is not possible via TF. You can destroy google_dataform_repository resource ONLY if your config does not contain for example workspaces in other words, if it's empty. If you have repo, where you are configuring "Development workspace", TF will not be able to destroy repo, due to nested resources (also there is no destroy/delete parameter available for this resource to set). You probably will be able to deal with that via [1]API, but it's not super handy. 

[1.]. https://cloud.google.com/dataform/reference/rest/v1beta1/projects.locations.repositories/delete

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

View solution in original post

3 REPLIES 3

Hello @davidregalado25  ,Welcome on Google Cloud Community.

Unfortunately this is not possible via TF. You can destroy google_dataform_repository resource ONLY if your config does not contain for example workspaces in other words, if it's empty. If you have repo, where you are configuring "Development workspace", TF will not be able to destroy repo, due to nested resources (also there is no destroy/delete parameter available for this resource to set). You probably will be able to deal with that via [1]API, but it's not super handy. 

[1.]. https://cloud.google.com/dataform/reference/rest/v1beta1/projects.locations.repositories/delete

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

Hi Damian!

I hope that destroy parameter will be available in the future. Meanwhile, I'll work with what I have.

--
Best regards
David Regalado
Web | Linkedin | Cloudskillsboost

Hi @davidregalado25 @DamianS , did above change work for you to delete the dataform repository? 
I am running into the same issue where I tried updating the location of repository through terraform but was unable to delete in order to recreate the repo. Do you have any suggestions how to approach this issue? 

Thank you! 

Best, 
Prashant Pancholi