Skip to content

Commit acb8cf7

Browse files
fix pubsub schema update failure (#5553) (#10768)
Signed-off-by: Modular Magician <[email protected]>
1 parent a54fad2 commit acb8cf7

File tree

4 files changed

+30
-83
lines changed

4 files changed

+30
-83
lines changed

.changelog/5553.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:breaking-change
2+
pubsub: changed `google_pubsub_schema` so that modifiying fields will recreate the resource rather than causing Terraform to report it would attempt an invalid update
3+
```
4+
```release-note:bug
5+
pubsub: fix update failure when attempting to change non-updatable resource `google_pubsub_schema`
6+
```

google/resource_pubsub_schema.go

+2-60
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func resourcePubsubSchema() *schema.Resource {
2828
return &schema.Resource{
2929
Create: resourcePubsubSchemaCreate,
3030
Read: resourcePubsubSchemaRead,
31-
Update: resourcePubsubSchemaUpdate,
3231
Delete: resourcePubsubSchemaDelete,
3332

3433
Importer: &schema.ResourceImporter{
@@ -37,7 +36,6 @@ func resourcePubsubSchema() *schema.Resource {
3736

3837
Timeouts: &schema.ResourceTimeout{
3938
Create: schema.DefaultTimeout(4 * time.Minute),
40-
Update: schema.DefaultTimeout(4 * time.Minute),
4139
Delete: schema.DefaultTimeout(6 * time.Minute),
4240
},
4341

@@ -52,13 +50,15 @@ func resourcePubsubSchema() *schema.Resource {
5250
"definition": {
5351
Type: schema.TypeString,
5452
Optional: true,
53+
ForceNew: true,
5554
Description: `The definition of the schema.
5655
This should contain a string representing the full definition of the schema
5756
that is a valid schema definition of the type specified in type.`,
5857
},
5958
"type": {
6059
Type: schema.TypeString,
6160
Optional: true,
61+
ForceNew: true,
6262
ValidateFunc: validation.StringInSlice([]string{"TYPE_UNSPECIFIED", "PROTOCOL_BUFFER", "AVRO", ""}, false),
6363
Description: `The type of the schema definition Default value: "TYPE_UNSPECIFIED" Possible values: ["TYPE_UNSPECIFIED", "PROTOCOL_BUFFER", "AVRO"]`,
6464
Default: "TYPE_UNSPECIFIED",
@@ -216,64 +216,6 @@ func resourcePubsubSchemaRead(d *schema.ResourceData, meta interface{}) error {
216216
return nil
217217
}
218218

219-
func resourcePubsubSchemaUpdate(d *schema.ResourceData, meta interface{}) error {
220-
config := meta.(*Config)
221-
userAgent, err := generateUserAgentString(d, config.userAgent)
222-
if err != nil {
223-
return err
224-
}
225-
226-
billingProject := ""
227-
228-
project, err := getProject(d, config)
229-
if err != nil {
230-
return fmt.Errorf("Error fetching project for Schema: %s", err)
231-
}
232-
billingProject = project
233-
234-
obj := make(map[string]interface{})
235-
typeProp, err := expandPubsubSchemaType(d.Get("type"), d, config)
236-
if err != nil {
237-
return err
238-
} else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, typeProp)) {
239-
obj["type"] = typeProp
240-
}
241-
definitionProp, err := expandPubsubSchemaDefinition(d.Get("definition"), d, config)
242-
if err != nil {
243-
return err
244-
} else if v, ok := d.GetOkExists("definition"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, definitionProp)) {
245-
obj["definition"] = definitionProp
246-
}
247-
nameProp, err := expandPubsubSchemaName(d.Get("name"), d, config)
248-
if err != nil {
249-
return err
250-
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
251-
obj["name"] = nameProp
252-
}
253-
254-
url, err := replaceVars(d, config, "{{PubsubBasePath}}projects/{{project}}/schemas/{{name}}")
255-
if err != nil {
256-
return err
257-
}
258-
259-
log.Printf("[DEBUG] Updating Schema %q: %#v", d.Id(), obj)
260-
261-
// err == nil indicates that the billing_project value was found
262-
if bp, err := getBillingProject(d, config); err == nil {
263-
billingProject = bp
264-
}
265-
266-
res, err := sendRequestWithTimeout(config, "PUT", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
267-
268-
if err != nil {
269-
return fmt.Errorf("Error updating Schema %q: %s", d.Id(), err)
270-
} else {
271-
log.Printf("[DEBUG] Finished updating Schema %q: %#v", d.Id(), res)
272-
}
273-
274-
return resourcePubsubSchemaRead(d, meta)
275-
}
276-
277219
func resourcePubsubSchemaDelete(d *schema.ResourceData, meta interface{}) error {
278220
config := meta.(*Config)
279221
userAgent, err := generateUserAgentString(d, config.userAgent)

website/docs/r/os_config_os_policy_assignment.html.markdown

+22-22
Original file line numberDiff line numberDiff line change
@@ -703,28 +703,6 @@ The `disruption_budget` block supports:
703703
(Optional)
704704
Specifies the relative value defined as a percentage, which will be multiplied by a reference value.
705705

706-
The `validate` block supports:
707-
708-
* `interpreter` -
709-
(Required)
710-
Required. The script interpreter to use. Possible values: INTERPRETER_UNSPECIFIED, NONE, SHELL, POWERSHELL
711-
712-
* `args` -
713-
(Optional)
714-
Optional arguments to pass to the source during execution.
715-
716-
* `file` -
717-
(Optional)
718-
Required. A deb package.
719-
720-
* `output_file_path` -
721-
(Optional)
722-
Only recorded for enforce Exec. Path to an output file (that is created by this Exec) whose content will be recorded in OSPolicyResourceCompliance after a successful run. Absence or failure to read this file will result in this ExecResource being non-compliant. Output file size is limited to 100K bytes.
723-
724-
* `script` -
725-
(Optional)
726-
An inline script. The size of the script is limited to 1024 characters.
727-
728706
- - -
729707

730708
* `description` -
@@ -1016,6 +994,28 @@ The `remote` block supports:
1016994
(Optional)
1017995
SHA256 checksum of the remote file.
1018996

997+
The `enforce` block supports:
998+
999+
* `interpreter` -
1000+
(Required)
1001+
Required. The script interpreter to use. Possible values: INTERPRETER_UNSPECIFIED, NONE, SHELL, POWERSHELL
1002+
1003+
* `args` -
1004+
(Optional)
1005+
Optional arguments to pass to the source during execution.
1006+
1007+
* `file` -
1008+
(Optional)
1009+
Required. A deb package.
1010+
1011+
* `output_file_path` -
1012+
(Optional)
1013+
Only recorded for enforce Exec. Path to an output file (that is created by this Exec) whose content will be recorded in OSPolicyResourceCompliance after a successful run. Absence or failure to read this file will result in this ExecResource being non-compliant. Output file size is limited to 100K bytes.
1014+
1015+
* `script` -
1016+
(Optional)
1017+
An inline script. The size of the script is limited to 1024 characters.
1018+
10191019
## Attributes Reference
10201020

10211021
In addition to the arguments listed above, the following computed attributes are exported:

website/docs/r/pubsub_schema.html.markdown

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ This resource provides the following
111111
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
112112

113113
- `create` - Default is 4 minutes.
114-
- `update` - Default is 4 minutes.
115114
- `delete` - Default is 6 minutes.
116115

117116
## Import

0 commit comments

Comments
 (0)