From 6194945c2783c20400ccb693b3ea57aec41336ea Mon Sep 17 00:00:00 2001 From: Luke Hoban Date: Thu, 1 Jun 2017 23:09:51 -0700 Subject: [PATCH] Get Elastic Beanstalk sample working again Changes the Source property on AWS S3 Objects to be an `in` property. Adds an AllOptionSettings output property to store the settings returned from AWS. This unblocks keeping Beanstalk workign while we evaluate options for #189. Silently skip unsupported AWS ElasticBeanstalk Environment properties in Get operation. Fixes ARN resource name pair extraction to skip the "/" between parts of the name pair. --- lib/aws/idl/elasticbeanstalk/environment.go | 4 +++- lib/aws/idl/s3/object.go | 2 +- lib/aws/pack/elasticbeanstalk/environment.ts | 1 + lib/aws/provider/arn/arn.go | 2 +- .../provider/elasticbeanstalk/environment.go | 24 ++++++++++++------- lib/aws/provider/s3/bucket.go | 2 +- lib/aws/provider/s3/object.go | 3 +-- lib/aws/rpc/elasticbeanstalk/environment.go | 2 ++ lib/aws/rpc/s3/object.go | 2 +- 9 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/aws/idl/elasticbeanstalk/environment.go b/lib/aws/idl/elasticbeanstalk/environment.go index f25450fe1..3389df132 100644 --- a/lib/aws/idl/elasticbeanstalk/environment.go +++ b/lib/aws/idl/elasticbeanstalk/environment.go @@ -51,9 +51,11 @@ type Environment struct { Tier *Tier `lumi:"tier,optional,replaces"` // The version to associate with the environment. Version *ApplicationVersion `lumi:"version,optional"` - // The URL to the load balancer for this environment. EndpointURL string `lumi:"endpointURL,out"` + // Key-value pairs defining all of the configuration options for this environment, including both values provided + // in the OptionSettings input, as well as settings with default values. + AllOptionSettings *[]OptionSetting `lumi:"allOptionSettings,out"` } // OptionSetting specifies options for an Elastic Beanstalk environment. diff --git a/lib/aws/idl/s3/object.go b/lib/aws/idl/s3/object.go index 0696d1e2f..3173f3138 100644 --- a/lib/aws/idl/s3/object.go +++ b/lib/aws/idl/s3/object.go @@ -27,5 +27,5 @@ type Object struct { // The Bucket this object belongs to. Bucket *Bucket `lumi:"bucket,replaces"` // The Source of content for this object. - Source *idl.Asset `lumi:"source,replaces"` + Source *idl.Asset `lumi:"source,replaces,in"` } diff --git a/lib/aws/pack/elasticbeanstalk/environment.ts b/lib/aws/pack/elasticbeanstalk/environment.ts index 639c56650..ab9a54c99 100644 --- a/lib/aws/pack/elasticbeanstalk/environment.ts +++ b/lib/aws/pack/elasticbeanstalk/environment.ts @@ -22,6 +22,7 @@ export class Environment extends lumi.Resource implements EnvironmentArgs { public readonly tier?: Tier; public version?: ApplicationVersion; @lumi.out public endpointURL: string; + @lumi.out public allOptionSettings: OptionSetting[]; constructor(name: string, args: EnvironmentArgs) { super(); diff --git a/lib/aws/provider/arn/arn.go b/lib/aws/provider/arn/arn.go index 56390e881..e94110523 100644 --- a/lib/aws/provider/arn/arn.go +++ b/lib/aws/provider/arn/arn.go @@ -186,7 +186,7 @@ func (a ARNParts) ResourceName() string { func (a ARNParts) ResourceNamePair() (string, string) { name := a.ResourceName() if ix := strings.Index(name, "/"); ix != -1 { - return name[:ix], name[ix:] + return name[:ix], name[ix+1:] } return name, "" } diff --git a/lib/aws/provider/elasticbeanstalk/environment.go b/lib/aws/provider/elasticbeanstalk/environment.go index 3c9ac9839..2f5f2002d 100644 --- a/lib/aws/provider/elasticbeanstalk/environment.go +++ b/lib/aws/provider/elasticbeanstalk/environment.go @@ -91,7 +91,7 @@ func (p *environmentProvider) Create(ctx context.Context, obj *elasticbeanstalk. } var versionLabel *string if obj.Version != nil { - version, err := arn.ParseResourceName(*obj.Version) + _, version, err := arn.ParseResourceNamePair(*obj.Version) if err != nil { return "", err } @@ -132,7 +132,6 @@ func (p *environmentProvider) Create(ctx context.Context, obj *elasticbeanstalk. return "", fmt.Errorf("Timed out waiting for environment to become ready") } - fmt.Printf("Created ElasticBeanstalk Environment '%v' with EndpointURL: %v\n", name, *endpointURL) return arn.NewElasticBeanstalkEnvironmentID(p.ctx.Region(), p.ctx.AccountID(), appname, name), nil } @@ -157,9 +156,7 @@ func (p *environmentProvider) Get(ctx context.Context, id resource.ID) (*elastic // Successfully found the environment, now map all of its properties onto the struct. contract.Assert(len(envresp.Environments) == 1) env := envresp.Environments[0] - if env.CNAME != nil || env.TemplateName != nil || env.Tier != nil { - return nil, fmt.Errorf("Properties not yet supported: CNAMEPrefix, TemplateName, Tier") - } + var versionLabel *resource.ID if env.VersionLabel != nil { version := arn.NewElasticBeanstalkApplicationVersionID( @@ -175,9 +172,18 @@ func (p *environmentProvider) Get(ctx context.Context, id resource.ID) (*elastic EndpointURL: aws.StringValue(env.EndpointURL), } + // TODO[pulumi/lumi#189] We may want to call `DecribeConfigurationSettings` to populate all of + // the option settings onto the returned object. However, this returns all of the settings with + // their default values, not just those provided as input. This leads to signalling deletions + // on future updates. For now, we will populate a seperate output property with the full set + // of settings, but we should revisist this once we've resolved #189. + // Next see if there are any configuration option settings and, if so, set them on the return. confresp, err := p.ctx.ElasticBeanstalk().DescribeConfigurationSettings( - &awselasticbeanstalk.DescribeConfigurationSettingsInput{EnvironmentName: aws.String(envname)}) + &awselasticbeanstalk.DescribeConfigurationSettingsInput{ + ApplicationName: aws.String(appname), + EnvironmentName: aws.String(envname), + }) if err != nil { return nil, err } @@ -192,7 +198,7 @@ func (p *environmentProvider) Get(ctx context.Context, id resource.ID) (*elastic }) } } - envobj.OptionSettings = &options + envobj.AllOptionSettings = &options } return envobj, nil @@ -249,7 +255,7 @@ func (p *environmentProvider) Update(ctx context.Context, id resource.ID, return err } succ, err := awsctx.RetryUntilLong(p.ctx, func() (bool, error) { - fmt.Printf("Waiting for environment %v to become Ready\n", id.String()) + fmt.Printf("Waiting for environment %v to become Ready\n", envname) resp, err := p.getEnvironment(appname, envname) if err != nil { return false, err @@ -284,7 +290,7 @@ func (p *environmentProvider) Delete(ctx context.Context, id resource.ID) error return err } succ, err := awsctx.RetryUntilLong(p.ctx, func() (bool, error) { - fmt.Printf("Waiting for environment %v to become Terminated\n", id.String()) + fmt.Printf("Waiting for environment %v to become Terminated\n", envname) resp, err := p.getEnvironment(appname, envname) if err != nil { return false, err diff --git a/lib/aws/provider/s3/bucket.go b/lib/aws/provider/s3/bucket.go index abe0d2b20..56ef2fe55 100644 --- a/lib/aws/provider/s3/bucket.go +++ b/lib/aws/provider/s3/bucket.go @@ -128,7 +128,7 @@ func (p *buckProvider) Get(ctx context.Context, id resource.ID) (*s3.Bucket, err // InspectChange checks what impacts a hypothetical update will have on the resource's properties. func (p *buckProvider) InspectChange(ctx context.Context, id resource.ID, old *s3.Bucket, new *s3.Bucket, diff *resource.ObjectDiff) ([]string, error) { - return nil, errors.New("Not yet implemented") + return nil, nil } // Update updates an existing resource with new values. Only those values in the provided property bag are updated diff --git a/lib/aws/provider/s3/object.go b/lib/aws/provider/s3/object.go index e8f4154fa..02d18436b 100644 --- a/lib/aws/provider/s3/object.go +++ b/lib/aws/provider/s3/object.go @@ -127,14 +127,13 @@ func (p *objProvider) Get(ctx context.Context, id resource.ID) (*s3.Object, erro return &s3.Object{ Bucket: resource.ID(arn.NewS3Bucket(buck)), Key: key, - Source: resource.NewURIAsset(fmt.Sprintf("s3://%v/%v", buck, key)), }, nil } // InspectChange checks what impacts a hypothetical update will have on the resource's properties. func (p *objProvider) InspectChange(ctx context.Context, id resource.ID, old *s3.Object, new *s3.Object, diff *resource.ObjectDiff) ([]string, error) { - return nil, errors.New("Not yet implemented") + return nil, nil } // Update updates an existing resource with new values. Only those values in the provided property bag are updated diff --git a/lib/aws/rpc/elasticbeanstalk/environment.go b/lib/aws/rpc/elasticbeanstalk/environment.go index 99f8b03a1..8e4043ace 100644 --- a/lib/aws/rpc/elasticbeanstalk/environment.go +++ b/lib/aws/rpc/elasticbeanstalk/environment.go @@ -204,6 +204,7 @@ type Environment struct { Tier *Tier `json:"tier,omitempty"` Version *resource.ID `json:"version,omitempty"` EndpointURL string `json:"endpointURL,omitempty"` + AllOptionSettings *[]OptionSetting `json:"allOptionSettings,omitempty"` } // Environment's properties have constants to make dealing with diffs and property bags easier. @@ -220,6 +221,7 @@ const ( Environment_Tier = "tier" Environment_Version = "version" Environment_EndpointURL = "endpointURL" + Environment_AllOptionSettings = "allOptionSettings" ) /* Marshalable OptionSetting structure(s) */ diff --git a/lib/aws/rpc/s3/object.go b/lib/aws/rpc/s3/object.go index 96f122781..b3cbcac5f 100644 --- a/lib/aws/rpc/s3/object.go +++ b/lib/aws/rpc/s3/object.go @@ -176,7 +176,7 @@ func (p *ObjectProvider) Unmarshal( type Object struct { Key string `json:"key"` Bucket resource.ID `json:"bucket"` - Source resource.Asset `json:"source"` + Source *resource.Asset `json:"source,omitempty"` } // Object's properties have constants to make dealing with diffs and property bags easier.