Skip to content

Commit

Permalink
add enforce_in_transit field in google_pubsub_topic (#12716) (#9069)
Browse files Browse the repository at this point in the history
[upstream:47353838db00bc219c8d1c5df636674b117732e8]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 15, 2025
1 parent c7ec001 commit d8df79d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12716.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: enhancement
pubsub: added `enforce_in_transit` fields to `google_pubsub_topic` resource
```
25 changes: 25 additions & 0 deletions google-beta/services/pubsub/resource_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ and is not a valid configuration.`,
Type: schema.TypeString,
},
},
"enforce_in_transit": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, 'allowedPersistenceRegions' is also used to enforce in-transit
guarantees for messages. That is, Pub/Sub will fail topics.publish
operations on this topic and subscribe operations on any subscription
attached to this topic in any region that is not in 'allowedPersistenceRegions'.`,
},
},
},
},
Expand Down Expand Up @@ -819,12 +827,18 @@ func flattenPubsubTopicMessageStoragePolicy(v interface{}, d *schema.ResourceDat
transformed := make(map[string]interface{})
transformed["allowed_persistence_regions"] =
flattenPubsubTopicMessageStoragePolicyAllowedPersistenceRegions(original["allowedPersistenceRegions"], d, config)
transformed["enforce_in_transit"] =
flattenPubsubTopicMessageStoragePolicyEnforceInTransit(original["enforceInTransit"], d, config)
return []interface{}{transformed}
}
func flattenPubsubTopicMessageStoragePolicyAllowedPersistenceRegions(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicMessageStoragePolicyEnforceInTransit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicSchemaSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1087,13 +1101,24 @@ func expandPubsubTopicMessageStoragePolicy(v interface{}, d tpgresource.Terrafor
transformed["allowedPersistenceRegions"] = transformedAllowedPersistenceRegions
}

transformedEnforceInTransit, err := expandPubsubTopicMessageStoragePolicyEnforceInTransit(original["enforce_in_transit"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnforceInTransit); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["enforceInTransit"] = transformedEnforceInTransit
}

return transformed, nil
}

func expandPubsubTopicMessageStoragePolicyAllowedPersistenceRegions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicMessageStoragePolicyEnforceInTransit(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicSchemaSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ resource "google_pubsub_topic" "example" {
allowed_persistence_regions = [
"europe-west3",
]
enforce_in_transit = true
}
}
`, context)
Expand Down
1 change: 1 addition & 0 deletions google-beta/services/pubsub/resource_pubsub_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ resource "google_pubsub_topic" "foo" {
allowed_persistence_regions = [
"%s",
]
enforce_in_transit = false
}
}
`, topic, key, value, region)
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/pubsub_topic.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ resource "google_pubsub_topic" "example" {
allowed_persistence_regions = [
"europe-west3",
]
enforce_in_transit = true
}
}
```
Expand Down Expand Up @@ -257,6 +258,13 @@ The following arguments are supported:
allowed regions. An empty list means that no regions are allowed,
and is not a valid configuration.

* `enforce_in_transit` -
(Optional)
If true, `allowedPersistenceRegions` is also used to enforce in-transit
guarantees for messages. That is, Pub/Sub will fail topics.publish
operations on this topic and subscribe operations on any subscription
attached to this topic in any region that is not in `allowedPersistenceRegions`.

<a name="nested_schema_settings"></a>The `schema_settings` block supports:

* `schema` -
Expand Down

0 comments on commit d8df79d

Please sign in to comment.