0

I am creating a asset feed for the deleted/created resource. The code below and the link is showing the expression only for when the resources are getting created, but I want another feed when resources are getting deleted only. Reference link - https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_asset_organization_feed

I just want to receive the notification ONLY for create and delete no UPDATE.

resource "google_cloud_asset_organization_feed" "organization_feed" {
  billing_project = "my-project-name"
  org_id          = "123456789"
  feed_id         = "network-updates"
  content_type    = "RESOURCE"

  asset_types = [
    "compute.googleapis.com/Subnetwork",
    "compute.googleapis.com/Network",
  ]

  feed_output_config {
    pubsub_destination {
      topic = google_pubsub_topic.feed_output.id
    }
  }

  condition {
    expression = <<-EOT
    !temporal_asset.deleted &&
    temporal_asset.prior_asset_state == google.cloud.asset.v1.TemporalAsset.PriorAssetState.DOES_NOT_EXIST
    EOT
    title = "created"
    description = "Send notifications on creation events"
  }
}
emily_r
  • 1
  • 1
  • Have you tried something like `expression = temporal_asset.deleted`? https://cloud.google.com/asset-inventory/docs/monitoring-asset-changes-with-condition and https://cloud.google.com/asset-inventory/docs/reference/rpc/google.cloud.asset.v1#temporalasset – John Hanley Nov 15 '22 at 04:06
  • @JohnHanley I want to get notify when the resources are deleted, this will notify when the resources are created – emily_r Nov 15 '22 at 13:06
  • Your code shows `created`. My comment shows `deleted`. – John Hanley Nov 15 '22 at 20:22

1 Answers1

0

To create a deleted asset feed change the condition to:

  condition {
    expression =  temporal_asset.deleted
    title = "deleted"
    description = "Send notifications on deletion events"
  }

Monitoring asset changes with conditions

TemporalAsset

John Hanley
  • 74,467
  • 6
  • 95
  • 159
  • are you saying don't do it this way - !temporal_asset.deleted && temporal_asset.prior_asset_state == google.cloud.asset.v1.TemporalAsset.PriorAssetState.DOES_NOT_EXIST – emily_r Nov 26 '22 at 22:09
  • Also, I do receive a notification when the bucket gets modified. How can I get the alert just for delete or create – emily_r Nov 26 '22 at 22:10
  • @emily_r - Edit your question and show the condition that created your error. – John Hanley Nov 26 '22 at 22:29
  • I am not receiving any errors, I just want to get the notify when it's created and deleted not for changes. When I use this condition - temporal_asset.deleted && temporal_asset.prior_asset_state == google.cloud.asset.v1.TemporalAsset.PriorAssetState.DOES_NOT_EXIST, I receive notify for when the assets are update. How can I get notify ONLY for create and delete – emily_r Nov 27 '22 at 06:30
  • -- │ Error: Reference to undeclared resource │ │ on main.tf line 64, in resource "google_cloud_asset_organization_feed" "organization_feed": │ 64: expression = temporal_asset.deleted │ │ A managed resource "temporal_asset" "deleted" has not been declared in the root module. – emily_r Nov 27 '22 at 21:19