Add outputs to the Create provider's return

In order to support output properties (pulumi/coconut#90), we need to
modify the Create gRPC interface for resource providers slightly.  In
addition to returning the ID, we need to also return any properties
computed by the AWS provider itself.  For instance, this includes ARNs
and IDs of various kinds.  This change simply propagates the resources
but we don't actually support reading the outputs just yet.
This commit is contained in:
joeduffy 2017-04-21 14:15:06 -07:00
parent a2b37d7dda
commit d6abea728c
7 changed files with 115 additions and 53 deletions

View file

@ -667,11 +667,12 @@ func (s *step) Apply() (State, error) {
contract.Assert(s.old == nil)
contract.Assert(s.new != nil)
contract.Assertf(!s.new.HasID(), "Resources being created must not have IDs already")
id, rst, err := prov.Create(s.new.Type(), s.new.Properties())
id, outs, rst, err := prov.Create(s.new.Type(), s.new.Properties())
if err != nil {
return rst, err
}
s.new.SetID(id)
s.new.SetPropertiesFrom(outs)
case OpDelete, OpReplaceDelete:
// Invoke the Delete RPC function for this provider:

View file

@ -30,7 +30,7 @@ type Provider interface {
// In any case, resources with the same name must be safe to use interchangeably with one another.
Name(t tokens.Type, props PropertyMap) (tokens.QName, error)
// Create allocates a new instance of the provided resource and returns its unique ID afterwards.
Create(t tokens.Type, props PropertyMap) (ID, State, error)
Create(t tokens.Type, props PropertyMap) (ID, PropertyMap, State, error)
// Get reads the instance state identified by id/t, and returns a bag of properties.
Get(id ID, t tokens.Type) (PropertyMap, error)
// PreviewUpdate checks what impacts a hypothetical update will have on the resource's properties.

View file

@ -101,7 +101,7 @@ func (p *provider) Name(t tokens.Type, props PropertyMap) (tokens.QName, error)
}
// Create allocates a new instance of the provided resource and returns its unique ID afterwards.
func (p *provider) Create(t tokens.Type, props PropertyMap) (ID, State, error) {
func (p *provider) Create(t tokens.Type, props PropertyMap) (ID, PropertyMap, State, error) {
glog.V(7).Infof("resource[%v].Create(t=%v,#props=%v) executing", p.pkg, t, len(props))
req := &cocorpc.CreateRequest{
Type: string(t),
@ -111,17 +111,18 @@ func (p *provider) Create(t tokens.Type, props PropertyMap) (ID, State, error) {
resp, err := p.client.Create(p.ctx.Request(), req)
if err != nil {
glog.V(7).Infof("resource[%v].Create(t=%v,...) failed: err=%v", p.pkg, t, err)
return ID(""), StateUnknown, err
return ID(""), nil, StateUnknown, err
}
id := ID(resp.GetId())
glog.V(7).Infof("resource[%v].Create(t=%v,...) success: id=%v", p.pkg, t, id)
outs := resp.GetOutputs()
outprops := UnmarshalProperties(outs)
glog.V(7).Infof("resource[%v].Create(t=%v,...) success: id=%v,#outs=%v", p.pkg, t, id, len(outprops))
if id == "" {
return id,
StateUnknown,
return id, outprops, StateUnknown,
errors.Errorf("plugin for package '%v' returned empty ID from create '%v'", p.pkg, t)
}
return id, StateOK, nil
return id, outprops, StateOK, nil
}
// Get reads the instance state identified by id/t, and returns a bag of properties.

View file

@ -39,14 +39,15 @@ func IDStrings(ids []ID) []string {
// Resource is an instance of a resource with an ID, type, and bag of state.
type Resource interface {
ID() ID // the resource's unique ID, assigned by the resource provider (or blank if uncreated).
URN() URN // the resource's object urn, a human-friendly, unique name for the resource.
Type() tokens.Type // the resource's type.
Properties() PropertyMap // the resource's property map.
HasID() bool // returns true if the resource has been assigned an ID.
SetID(id ID) // assignes an ID to this resource, for those under creation.
HasURN() bool // returns true if the resource has been assigned urn.
SetURN(m URN) // assignes a urn to this resource, for those under creation.
ID() ID // the resource's unique ID assigned by the provider (or blank if uncreated).
URN() URN // the resource's object urn, a human-friendly, unique name for the resource.
Type() tokens.Type // the resource's type.
Properties() PropertyMap // the resource's property map.
HasID() bool // returns true if the resource has been assigned an ID.
SetID(id ID) // assignes an ID to this resource, for those under creation.
SetPropertiesFrom(m PropertyMap) // copies properties from the given map to the resource.
HasURN() bool // returns true if the resource has been assigned URN.
SetURN(m URN) // assignes a URN to this resource, for those under creation.
}
// State is returned when an error has occurred during a resource provider operation. It indicates whether the
@ -79,6 +80,12 @@ func (r *resource) SetID(id ID) {
r.id = id
}
func (r *resource) SetPropertiesFrom(m PropertyMap) {
for k, v := range m {
r.properties[k] = v
}
}
func (r *resource) HasURN() bool { return (string(r.urn) != "") }
func (r *resource) SetURN(m URN) {
contract.Requiref(!r.HasURN(), "urn", "empty")

View file

@ -149,7 +149,8 @@ func (m *CreateRequest) GetProperties() *google_protobuf.Struct {
}
type CreateResponse struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Outputs *google_protobuf.Struct `protobuf:"bytes,2,opt,name=outputs" json:"outputs,omitempty"`
}
func (m *CreateResponse) Reset() { *m = CreateResponse{} }
@ -164,6 +165,13 @@ func (m *CreateResponse) GetId() string {
return ""
}
func (m *CreateResponse) GetOutputs() *google_protobuf.Struct {
if m != nil {
return m.Outputs
}
return nil
}
type GetRequest struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type" json:"type,omitempty"`
@ -600,38 +608,38 @@ var _ResourceProvider_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("provider.proto", fileDescriptor2) }
var fileDescriptor2 = []byte{
// 513 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x54, 0x41, 0x6f, 0xd3, 0x4c,
0x10, 0xad, 0x93, 0x7c, 0x69, 0x32, 0xa9, 0xa3, 0x4f, 0x4b, 0x93, 0x5a, 0x06, 0xa1, 0x68, 0x4f,
0x91, 0x90, 0x5c, 0x9a, 0x0a, 0x81, 0xe0, 0xd6, 0x42, 0x2b, 0x2e, 0xa8, 0x32, 0xe2, 0x02, 0x5c,
0x5c, 0x7b, 0x92, 0x5a, 0x38, 0xde, 0x65, 0x77, 0xdd, 0x2a, 0x3f, 0x82, 0xdf, 0xc3, 0xdf, 0x43,
0xb6, 0xd7, 0x5b, 0xdb, 0x05, 0x52, 0x0e, 0xbd, 0x79, 0x67, 0xde, 0xbc, 0x79, 0xa3, 0x79, 0x63,
0x18, 0x73, 0xc1, 0xae, 0xe3,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a, 0xde, 0x83, 0xdd, 0xd8, 0x49, 0xad, 0x6f, 0xc3, 0x3a,
0xee, 0x53, 0x13, 0xff, 0xed, 0x0e, 0xe9, 0x0e, 0x79, 0x0d, 0xfd, 0x2d, 0x1c, 0xd3, 0x3b, 0xab,
0x7b, 0x97, 0xff, 0x2b, 0xcb, 0xda, 0x72, 0x65, 0xb5, 0xda, 0xc6, 0x0e, 0xff, 0x5c, 0x7b, 0xd9,
0x2f, 0x22, 0xc7, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x0f, 0xcc, 0x6d, 0xae, 0xa2, 0x05, 0x00,
0x00,
// 523 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x54, 0xc1, 0x6e, 0xd3, 0x40,
0x10, 0xad, 0x93, 0x90, 0x36, 0x93, 0x3a, 0x42, 0x4b, 0x93, 0x5a, 0x06, 0xa1, 0x68, 0x4f, 0x91,
0x90, 0x5c, 0x9a, 0x0a, 0x81, 0xe0, 0xd6, 0x42, 0x2b, 0x2e, 0xa8, 0x72, 0xc5, 0x05, 0xb8, 0xb8,
0xf6, 0x24, 0xb5, 0x70, 0xbc, 0xcb, 0xee, 0xba, 0x55, 0x3e, 0x82, 0xef, 0xe1, 0xf7, 0x90, 0xed,
0xf5, 0xd6, 0x76, 0x81, 0x94, 0x43, 0x6f, 0xde, 0x99, 0x37, 0x6f, 0xde, 0xf3, 0xcc, 0x2e, 0x8c,
0xb8, 0x60, 0xd7, 0x71, 0x84, 0xc2, 0xe3, 0x82, 0x29, 0x46, 0xb6, 0x43, 0x16, 0x32, 0xc1, 0x43,
0xf7, 0xe9, 0x92, 0xb1, 0x65, 0x82, 0x07, 0x45, 0xf8, 0x32, 0x5b, 0x1c, 0xe0, 0x8a, 0xab, 0x75,
0x89, 0x72, 0x9f, 0xb5, 0x93, 0x52, 0x89, 0x2c, 0x54, 0x65, 0x96, 0x7e, 0x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0xf2, 0xe7, 0xb5, 0xac,
0x2d, 0x47, 0x56, 0xab, 0x6d, 0xcc, 0xf0, 0xef, 0xb5, 0x97, 0xfd, 0x22, 0x72, 0xf4, 0x3b, 0x00,
0x00, 0xff, 0xff, 0xc2, 0x4b, 0x39, 0xd2, 0xd5, 0x05, 0x00, 0x00,
}

View file

@ -1096,7 +1096,8 @@ proto.cocorpc.CreateResponse.prototype.toObject = function(opt_includeInstance)
*/
proto.cocorpc.CreateResponse.toObject = function(includeInstance, msg) {
var f, obj = {
id: jspb.Message.getFieldWithDefault(msg, 1, "")
id: jspb.Message.getFieldWithDefault(msg, 1, ""),
outputs: (f = msg.getOutputs()) && google_protobuf_struct_pb.Struct.toObject(includeInstance, f)
};
if (includeInstance) {
@ -1137,6 +1138,11 @@ proto.cocorpc.CreateResponse.deserializeBinaryFromReader = function(msg, reader)
var value = /** @type {string} */ (reader.readString());
msg.setId(value);
break;
case 2:
var value = new google_protobuf_struct_pb.Struct;
reader.readMessage(value,google_protobuf_struct_pb.Struct.deserializeBinaryFromReader);
msg.setOutputs(value);
break;
default:
reader.skipField();
break;
@ -1172,6 +1178,14 @@ proto.cocorpc.CreateResponse.serializeBinaryToWriter = function(message, writer)
f
);
}
f = message.getOutputs();
if (f != null) {
writer.writeMessage(
2,
f,
google_protobuf_struct_pb.Struct.serializeBinaryToWriter
);
}
};
@ -1190,6 +1204,36 @@ proto.cocorpc.CreateResponse.prototype.setId = function(value) {
};
/**
* optional google.protobuf.Struct outputs = 2;
* @return {?proto.google.protobuf.Struct}
*/
proto.cocorpc.CreateResponse.prototype.getOutputs = function() {
return /** @type{?proto.google.protobuf.Struct} */ (
jspb.Message.getWrapperField(this, google_protobuf_struct_pb.Struct, 2));
};
/** @param {?proto.google.protobuf.Struct|undefined} value */
proto.cocorpc.CreateResponse.prototype.setOutputs = function(value) {
jspb.Message.setWrapperField(this, 2, value);
};
proto.cocorpc.CreateResponse.prototype.clearOutputs = function() {
this.setOutputs(undefined);
};
/**
* Returns whether this field is set.
* @return {!boolean}
*/
proto.cocorpc.CreateResponse.prototype.hasOutputs = function() {
return jspb.Message.getField(this, 2) != null;
};
/**
* Generated by JsPbCodeGenerator.

View file

@ -60,7 +60,8 @@ message CreateRequest {
}
message CreateResponse {
string id = 1; // the ID of the resource created.
string id = 1; // the ID of the resource created.
google.protobuf.Struct outputs = 2; // any properties populated at creation time.
}
message GetRequest {