# Update/Replace resource when source code has changed

**URL:** <https://discuss.hashicorp.com/t/update-replace-resource-when-source-code-has-changed/9986>\
**Category:** Terraform\
**Created:** [June 15, 2020, 5:15pm UTC](https://discuss.hashicorp.com/t/update-replace-resource-when-source-code-has-changed/9986 "2020-06-15T17:15:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidPessoa](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/davidpessoa/32/7955_2.png) [@DavidPessoa](https://discuss.hashicorp.com/u/DavidPessoa)\
**Post date:** [June 15, 2020, 5:15pm UTC](https://discuss.hashicorp.com/t/update-replace-resource-when-source-code-has-changed/9986/1 "2020-06-15T17:15:26Z")

</div>

I would like to ask how to configure an update/replace to a Google Cloud Function whenever it’s source code it’s changed.

The terraform is running on a gitlab ci and not storing state. It creates the cloud function when it does not exist but if I run the CI again I get error: 409 Function unzip already exists.

I wonder if someone could explain me how to detect a change to a specific resource and redeploy it.

Currently I have the following tf file:

```
 provider "google" {
      project = "test-project"
      region = "europe-west1"
    }

resource "google_cloudfunctions_function" "unzip" {
  name = "unzip"
  runtime = "python37"
  entry_point = "extractor"
  project = "test-project"
  available_memory_mb = 256

  event_trigger {
    event_type = "google.storage.object.finalize"
    resource = "temp-bucket"
  }
  
  source_repository{
    url = "https://source.developers.google.com/projects/test-project/repos/infra/moveable-aliases/develop/paths/cloud_functions/unzip"
  } 
}
```
