gyro icon indicating copy to clipboard operation
gyro copied to clipboard

Diffable object can't be updated.

Open sshyub opened this issue 5 years ago • 3 comments

Describe the bug Gyro should be able to handle @Updatable fields in Diffable type without replacing whole object.

To Reproduce

class Foo extends Diffable {
  private String name;

  @Updateable
  public String getName() {
    return name;
  }
}

@Type("bar")
class Bar extends Resource {
  private Foo foo;

  public Foo getFoo() {
    return foo;
  }
}

bar.gyro

service-provider::bar bar-resource
  foo
    name: "title"
  end
  1. run gyro up bar.gyro.
  2. modify name to something else.
  3. run gyro up bar.gyro again.

Expected behavior name in Foo type should be updated, but actual behavior is:

>>> gyro up gyro/managed-zone.gyro 
??? Loading plugin: gyro:gyro-google-provider:0.99.1-SNAPSHOT
??? Refreshed resources: 6

Looking for changes...

??? Replace service-provider::bar bar-resource bar (because of foo skipping without a workflow)
    ??? Update foo null::foo (change name)

Are you sure you want to change resources? (y/N) 

where the following output is expected.

>>> gyro up gyro/managed-zone.gyro 
??? Loading plugin: gyro:gyro-google-provider:0.99.1-SNAPSHOT
??? Refreshed resources: 6

Looking for changes...

??? Keep service-provider::bar bar-resource bar
    ??? Update foo null::foo (change name)

Are you sure you want to change resources? (y/N) 

sshyub avatar Dec 03 '19 15:12 sshyub

This is the difference between a Diffable, and a Resource used as a subresource. There are no methods to call on the Diffable to trigger the update, so the parent needs to be called.

Is your suggestion to handle this case by having the output be:

>>> gyro up gyro/managed-zone.gyro 
??? Loading plugin: gyro:gyro-google-provider:0.99.1-SNAPSHOT
??? Refreshed resources: 6

Looking for changes...

??? Update service-provider::bar bar-resource bar
    ??? Update foo null::foo (change name)

Are you sure you want to change resources? (y/N) 

And then call the parent's update method and pass enough information to update the Diffable? (Not an easy change given the current method signature is just a list of strings).

beetlebugorg avatar Dec 03 '19 16:12 beetlebugorg

Also, so I have a more concrete example, can you provide the service provider resource you're trying to implement and specifically what complex type within that resource this is causing an problem with. It'd help me to better understand how to solve this. Thanks.

beetlebugorg avatar Dec 03 '19 16:12 beetlebugorg

Updated OP to include expected output as well.

Here's the concrete example from Google provider implementation:

@Type("dns-managed-zone")
public class ManagedZoneResource extends GoogleResource {

    private String description;

    private String dnsName;

    private ZoneDnsSecConfig dnssecConfig;

    private String name;

    @Required
    @Updatable
    public String getDescription() {
        return description;
    }

    public String getDnsName() {
        return dnsName;
    }

    public ZoneDnsSecConfig getDnssecConfig() {
        return dnssecConfig;
    }

    @Required
    public String getName() {
        return name;
    }
}

public class ZoneDnsSecConfig extends Diffable {

    private String nonExistence;

    @Updatable
    @ValidStrings({ "nsec", "nsec3" })
    public String getNonExistence() {
        return nonExistence;
    }
}

Gyro configuration:

google::dns-managed-zone managed-zone-example-public
    name: "managed-zone-example-public"
    description: "Public Managed Zone Example"
    dns-name: "p.example.com."
    dnssec-config
        non-existence: "nsec"
    end
end

run gyro up and then modify the configuration to:

google::dns-managed-zone managed-zone-example-public
    name: "managed-zone-example-public"
    description: "Public Managed Zone Example"
    dns-name: "p.example.com."
    dnssec-config
        non-existence: "nsec3"
    end
end

and run gyro up again, I expect to see:

>>> gyro up gyro/managed-zone.gyro 
??? Loading plugin: gyro:gyro-google-provider:0.99.1-SNAPSHOT
??? Refreshed resources: 3

Looking for changes...

??? Keep google::dns-managed-zone managed-zone-example-public
    ??? Update dnssec-config null::dnssec-config (change non-existence)

Are you sure you want to change resources? (y/N)

but the actual output is:

gyro up gyro/managed-zone.gyro 
??? Loading plugin: gyro:gyro-google-provider:0.99.1-SNAPSHOT
??? Refreshed resources: 3

Looking for changes...

??? Replace google::dns-managed-zone managed-zone-example-public (because of dnssec-config, skipping without a workflow)
    ??? Update dnssec-config null::dnssec-config (change non-existence)

Are you sure you want to change resources? (y/N)

sshyub avatar Dec 04 '19 20:12 sshyub