goformation icon indicating copy to clipboard operation
goformation copied to clipboard

DependsOn Attribute

Open tskinn opened this issue 7 years ago • 5 comments

Is the DependsOn attribute on the road map or is it already supported some how?

tskinn avatar Jan 26 '18 03:01 tskinn

Bump on this, any luck of getting this?

moserke avatar Apr 17 '18 03:04 moserke

@tskinn FWIW I worked around this by extending the objects I needed "DependsOn" for. Not a great scale solution, but if there are a handful of objects you need this could help you out. I'm sure there is a more generic way of doing it as well, but only needed one object myself. Example code:

package main

import (
  cfn "github.com/awslabs/goformation/cloudformation"
  "encoding/json"
  "fmt"
)

type AWSIAMPolicy struct {
  cfn.AWSIAMPolicy
  DependsOn []string
}

func (r *AWSIAMPolicy) MarshalJSON() ([]byte, error) {
	type Properties cfn.AWSIAMPolicy
	return json.Marshal(&struct {
		Type       string
		Properties Properties
    DependsOn  []string
	}{
		Type:       r.AWSIAMPolicy.AWSCloudFormationType(),
		Properties: (Properties)(r.AWSIAMPolicy),
    DependsOn:  r.DependsOn,
	})
}

func main() {
  t := cfn.NewTemplate()
  t.Resources["policys3" + resourceName] = &AWSIAMPolicy{
    AWSIAMPolicy: cfn.AWSIAMPolicy{
      Roles: []string{"role"},
      PolicyName: "policy",
      PolicyDocument: "policyDoc",
    },
    DependsOn: []string{"resource"},
  }

  j, err := t.JSON()
  fmt.Printf("%s\n", string(j))
}

moserke avatar Apr 17 '18 13:04 moserke

@PaulMaddox Can we close this as resolved via #132 now?

mumoshu avatar Nov 28 '18 13:11 mumoshu

Any progress on this?

gnaqvi avatar Jan 28 '19 22:01 gnaqvi

The DependsOn in CF Resources could be just a string, it does not need to be a list of strings. Should that be created as separated issue? thanks

tcondeixa avatar Oct 05 '21 18:10 tcondeixa