Skip to content

Commit

Permalink
Add capability to not to update old rds those are affected by AWS clo…
Browse files Browse the repository at this point in the history
…udformation and rds api changes
  • Loading branch information
nightfury1204 committed Apr 25, 2024
1 parent c7c8200 commit 5f520ae
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 13 deletions.
2 changes: 1 addition & 1 deletion provider/aws/formation/app.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
{{ if .Port.Port }}
"RecordSet{{ upper .Name }}Internal": {
"Type": "AWS::Route53::RecordSet",
"Condition": "InternalDomains",
"Properties": {
"HostedZoneId": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:HostedZone" } },
"Name": { "Fn::Sub": "internal-{{.Name}}.{{$.App}}.${Rack}.convox." },
Expand Down Expand Up @@ -361,6 +360,7 @@
{{ range .Manifest.Services }}
"Service{{ upper .Name }}": {
"Type": "AWS::CloudFormation::Stack",
"DependsOn": "RecordSet{{ upper .Name }}Internal",
"Properties": {
"NotificationARNs": [ "{{ $.Topic }}" ],
"Parameters": {
Expand Down
79 changes: 67 additions & 12 deletions provider/aws/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,46 @@ func (p *Provider) ReleasePromote(app, id string, opts structs.ReleasePromoteOpt
rtp := map[string]interface{}{
"ThirdAvailabilityZone": hasThirdAZ,
}
data, err := formationTemplate(fmt.Sprintf("resource/%s", r.Type), rtp)
if err != nil {
return err
}

ou, err := p.ObjectStore(app, "", bytes.NewReader(data), structs.ObjectStoreOptions{Presign: options.Bool(true)})
if err != nil {
return err
var data []byte
var params map[string]string

if r.Options["noUpdate"] == "true" {
data, params, err = p.getResourceTemplateAndParams(app, r.Name)
if err != nil {
return err
}

// these params are set from the app itself, so remove from params
removeParamKeys := []string{
"Rack",
"Password",
"AutoMinorVersionUpgrade",
}
for _, k := range removeParamKeys {
delete(params, k)
}
} else {
data, err = formationTemplate(fmt.Sprintf("resource/%s", r.Type), rtp)
if err != nil {
return err
}

params, err = p.ResourceDefaults(app, r.Name)
if err != nil {
return err
}

for k, v := range r.Options {
params[upperName(k)] = v
}
}

params, err := p.ResourceDefaults(app, r.Name)
ou, err := p.ObjectStore(app, "", bytes.NewReader(data), structs.ObjectStoreOptions{Presign: options.Bool(true)})
if err != nil {
return err
}

for k, v := range r.Options {
params[upperName(k)] = v
}

tp[fmt.Sprintf("ResourceParams%s", upperName(r.Name))] = params
tp[fmt.Sprintf("ResourceTemplate%s", upperName(r.Name))] = ou.Url
}
Expand Down Expand Up @@ -943,3 +964,37 @@ func (p *Provider) getTimerState(app, timerName string) (string, error) {
}
return "", fmt.Errorf("Timer rule not found")
}

func (p *Provider) getResourceTemplateAndParams(app, resourceName string) ([]byte, map[string]string, error) {
ars, err := p.describeStackResources(&cloudformation.DescribeStackResourcesInput{
StackName: aws.String(p.rackStack(app)),
})
if err != nil {
return nil, nil, err
}

arsns := map[string]string{}

for _, ar := range ars.StackResources {
arsns[cs(ar.LogicalResourceId, "")] = cs(ar.PhysicalResourceId, "")
}

stack := arsns[fmt.Sprintf("Resource%s", upperName(resourceName))]

tmplBody, err := p.stackTemplate(stack)
if err != nil {
return nil, nil, err
}

res, err := p.describeStack(stack)
if err != nil {
return nil, nil, err
}

params := map[string]string{}
for _, p := range res.Parameters {
params[*p.ParameterKey] = *p.ParameterValue
}

return tmplBody, params, nil
}

0 comments on commit 5f520ae

Please sign in to comment.