Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intrinsic Functions with inline policies results in base64 output #190

Open
razor-1 opened this issue Mar 16, 2019 · 2 comments
Open

Intrinsic Functions with inline policies results in base64 output #190

razor-1 opened this issue Mar 16, 2019 · 2 comments
Assignees

Comments

@razor-1
Copy link

razor-1 commented Mar 16, 2019

I'm trying to build a stack similar to what is outlined here. Most of it is working great in goformation, but it seems like it's not possible to embed an inline policy along with intrinsic functions.

What I'm specifically trying to do is add a DestinationPolicy to an AWSLogsDestination. This policy is comprised of the escaped JSON and intrinsic functions. From the above link:

"DestinationPolicy": { "Fn::Join" : ["",[
		"{\"Version\" : \"2012-10-17\",\"Statement\" : [{\"Effect\" : \"Allow\",",
                " \"Principal\" : {\"AWS\" : \"", {"Ref":"SourceAccount"} ,"\"},",
                "\"Action\" : \"logs:PutSubscriptionFilter\",",
                " \"Resource\" : \"", 
                {"Fn::Join": [ "", [ "arn:aws:logs:", { "Ref": "AWS::Region" }, ":" ,{ "Ref": "AWS::AccountId" }, ":destination:",{ "Ref" : "AWS::StackName" },"-Destination" ] ]}  ,"\"}]}"
]]}

But despite various ways of invoking cloudformation.Join(), whenever JSON is passed in, DestinationPolicy ends up getting rendered in the output as base64.

@PaulMaddox PaulMaddox self-assigned this Mar 19, 2019
@rhyselsmore
Copy link

I am also encountering this issue. I am yet to find a workaround.

@rhyselsmore
Copy link

My workaround is super crude, but basically I declare my Log Destination like so:

logDestination := &resources.AWSLogsDestination{
	RoleArn:         cfn.Sub("${LogsRole.Arn}"),
	TargetArn:       cfn.Sub("${Stream.Arn}"),
	DestinationName: "cloudtrail",
	DestinationPolicy: cfn.Sub("${LogDestinationPolicyPlaceholder}"),
}

Then, after the template is rendered, I run:

t = strings.Replace(t, "${LogDestinationPolicyPlaceholder}", destinationPolicy, 1)

Where destinationPolicy is the policy JSON. However, big caveat - I have to wrap destinationPolicy with single quotes. Not sure how this goes if the policy document contains single quotes - however until this is fixed it works fine for me.

Like I said - super crude, and super brittle, but gets me moving along.

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

No branches or pull requests

3 participants