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

Resource Properties with JSON as primitive type still accept strings #29

Closed
scrthq opened this issue Apr 2, 2018 · 4 comments
Closed
Assignees

Comments

@scrthq
Copy link
Member

scrthq commented Apr 2, 2018

Getting this working requires conversion from JSON to PSObject via ConvertFrom-JSON or initial build of policy as a PSObject or Hashtable directly:

$assumeRolePolicyDoc_ddbRole = '{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Allow",
        "Principal": {
            "Service": "iot.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }]
}' | ConvertFrom-JSON
$pol = Add-VSIAMRolePolicy -PolicyDocument $assumeRolePolicyDoc_ddbRole -PolicyName ddbRole

PS > $pol.PolicyDocument

Version    Statement
-------    ---------
2012-10-17 {@{Effect=Allow; Principal=; Action=sts:AssumeRole}}

Not working when passing a JSON string in as the policy document (which is accepted as the generated function's parameter allows String, Hashtable or PSObject):

$assumeRolePolicyDoc_ddbRole = '{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Allow",
        "Principal": {
            "Service": "iot.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }]
}'
$pol = Add-VSIAMRolePolicy -PolicyDocument $assumeRolePolicyDoc_ddbRole -PolicyName ddbRole

PS > $pol.PolicyDocument
{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Allow",
        "Principal": {
            "Service": "iot.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }]
}

Looking into adding in logic for CloudFormation resource properties where the primitive type is JSON like the PolicyDocument type expects here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-iam-policy.html

Issue stemmed from comments on issue #28

@RegEM
Copy link

RegEM commented Apr 2, 2018

Thanks Nate.

@scrthq scrthq closed this as completed in 31190ce Jul 22, 2018
@ghost ghost removed the in progress label Jul 22, 2018
@scrthq
Copy link
Member Author

scrthq commented Jul 22, 2018

@RegEM hey man! FYI, this is fixed as of v2.3.2! You should get the same behavior whether you pass a JSON string or a hashtable or a PSObject now. Deployment should be out shortly!

@scrthq
Copy link
Member Author

scrthq commented Jul 22, 2018

In action:

[ICode]> $assumeRolePolicyDoc_ddbRole = '{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Allow",
        "Principal": {
            "Service": "iot.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }]
}'
$pol = Add-VSIAMRolePolicy -PolicyDocument $assumeRolePolicyDoc_ddbRole -PolicyName ddbRole -Verbose
$pol.PolicyDocument

Version    Statement
-------    ---------
2012-10-17 {@{Effect=Allow; Principal=; Action=sts:AssumeRole}}

@RegEM
Copy link

RegEM commented Jul 22, 2018

Awesome. I figured you must have worked thru it.
Thanks sir.

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

No branches or pull requests

2 participants