Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

CustomResources do not respect DependsOn #270

Closed
Sayan- opened this issue Feb 25, 2020 · 4 comments
Closed

CustomResources do not respect DependsOn #270

Sayan- opened this issue Feb 25, 2020 · 4 comments

Comments

@Sayan-
Copy link

Sayan- commented Feb 25, 2020

This is an issue in v4

CustomResources still follow the pattern in #132. The goformation library has since changed to using field types and custom JSON marshal/unmarshal in #245.

This is problematic when I attempt to create a CustomResource in a Template. The DependsOn will never be populated correctly during a Template.YAML() or Template.JSON() call.

Additionally, there are actually two versions of CustomResources in this library:

in: github.com/awslabs/goformation/v4/cloudformation

// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html
type CustomResource struct {
Type string `json:"Type,omitempty"`
Properties map[string]interface{} `json:"Properties,omitempty"`
// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy policies.DeletionPolicy
// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string
// _metadata stores structured data associated with this resource
_metadata map[string]interface{}
}

vs

in: github.com/awslabs/goformation/v4/cloudformation/cloudformation

// CustomResource AWS CloudFormation Resource (AWS::CloudFormation::CustomResource)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html
type CustomResource struct {
// ServiceToken AWS CloudFormation Property
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html#cfn-customresource-servicetoken
ServiceToken string `json:"ServiceToken,omitempty"`
// AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy
AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"`
// AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource
AWSCloudFormationDependsOn []string `json:"-"`
// AWSCloudFormationMetadata stores structured data associated with this resource
AWSCloudFormationMetadata map[string]interface{} `json:"-"`
// AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created
AWSCloudFormationCondition string `json:"-"`
}

@douglas-gibbons-lark
Copy link

douglas-gibbons-lark commented Dec 4, 2020

Here's a simple example, showing the issue:

package main

import (
	"io/ioutil"

	"github.com/awslabs/goformation/v4/cloudformation"
)

func main() {
	c := &cloudformation.CustomResource{
		Type: "AWS::Something::Someting",
		Properties: map[string]interface{}{
			"Foo": "Bar",
		},
	}

       // This sets the _dependsOn private field which is never Marshaled into JSON
	c.SetDependsOn([]string{"OtherResource"})

	t := cloudformation.NewTemplate()
	t.Resources["customResource"] = c

	j, _ := t.JSON()
	ioutil.WriteFile("/tmp/stack.json", j, 0644)
}

This outputs:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "customResource": {
      "Properties": {
        "Foo": "Bar"
      },
      "Type": "AWS::Something::Somehting"
    }
  }
}

i.e. It's missing DependsOn.

@sgavulla
Copy link

I can confirm that DependsOn is missing as mentioned by @douglas-gibbons-lark. This is needed otherwise our stack creation fails (the custom resource for our stack dependsOn a DDB table to be created first).

@xrn
Copy link
Contributor

xrn commented Feb 25, 2021

Let's close it 🎊 @PaulMaddox

@Sayan-
Copy link
Author

Sayan- commented Feb 26, 2021

Amazing! Thank you @xrn - I entirely forgot about this thread.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants