Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pubsub schema update failure #3933

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/5553.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:breaking-change
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
```
```release-note:bug
pubsub: fix update failure when attempting to change non-updatable resource `google_pubsub_schema`
```
62 changes: 2 additions & 60 deletions google-beta/resource_pubsub_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func resourcePubsubSchema() *schema.Resource {
return &schema.Resource{
Create: resourcePubsubSchemaCreate,
Read: resourcePubsubSchemaRead,
Update: resourcePubsubSchemaUpdate,
Delete: resourcePubsubSchemaDelete,

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

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Update: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(6 * time.Minute),
},

Expand All @@ -52,13 +50,15 @@ func resourcePubsubSchema() *schema.Resource {
"definition": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The definition of the schema.
This should contain a string representing the full definition of the schema
that is a valid schema definition of the type specified in type.`,
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"TYPE_UNSPECIFIED", "PROTOCOL_BUFFER", "AVRO", ""}, false),
Description: `The type of the schema definition Default value: "TYPE_UNSPECIFIED" Possible values: ["TYPE_UNSPECIFIED", "PROTOCOL_BUFFER", "AVRO"]`,
Default: "TYPE_UNSPECIFIED",
Expand Down Expand Up @@ -216,64 +216,6 @@ func resourcePubsubSchemaRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourcePubsubSchemaUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}

billingProject := ""

project, err := getProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Schema: %s", err)
}
billingProject = project

obj := make(map[string]interface{})
typeProp, err := expandPubsubSchemaType(d.Get("type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
definitionProp, err := expandPubsubSchemaDefinition(d.Get("definition"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("definition"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, definitionProp)) {
obj["definition"] = definitionProp
}
nameProp, err := expandPubsubSchemaName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}

url, err := replaceVars(d, config, "{{PubsubBasePath}}projects/{{project}}/schemas/{{name}}")
if err != nil {
return err
}

log.Printf("[DEBUG] Updating Schema %q: %#v", d.Id(), obj)

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "PUT", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return fmt.Errorf("Error updating Schema %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating Schema %q: %#v", d.Id(), res)
}

return resourcePubsubSchemaRead(d, meta)
}

func resourcePubsubSchemaDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
Expand Down
36 changes: 18 additions & 18 deletions website/docs/r/os_config_os_policy_assignment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,24 @@ The `disruption_budget` block supports:
(Optional)
Specifies the relative value defined as a percentage, which will be multiplied by a reference value.

The `source` block supports:

* `allow_insecure` -
(Optional)
Defaults to false. When false, files are subject to validations based on the file type: Remote: A checksum must be specified. Cloud Storage: An object generation number must be specified.

* `gcs` -
(Optional)
A Cloud Storage object.

* `local_path` -
(Optional)
A local path within the VM to use.

* `remote` -
(Optional)
A generic remote file.

- - -

* `description` -
Expand Down Expand Up @@ -952,24 +970,6 @@ The `zypper` block supports:
(Required)
Required. A one word, unique name for this repository. This is the `repo id` in the zypper config file and also the `display_name` if `display_name` is omitted. This id is also used as the unique identifier when checking for GuestPolicy conflicts.

The `file` block supports:

* `allow_insecure` -
(Optional)
Defaults to false. When false, files are subject to validations based on the file type: Remote: A checksum must be specified. Cloud Storage: An object generation number must be specified.

* `gcs` -
(Optional)
A Cloud Storage object.

* `local_path` -
(Optional)
A local path within the VM to use.

* `remote` -
(Optional)
A generic remote file.

The `gcs` block supports:

* `bucket` -
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/pubsub_schema.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 4 minutes.
- `update` - Default is 4 minutes.
- `delete` - Default is 6 minutes.

## Import
Expand Down