Skip to content

Commit

Permalink
WIP: Fix tests for 7837
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Jan 5, 2020
1 parent b21e345 commit e90b40d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
10 changes: 8 additions & 2 deletions tests/integration/update_cluster/complex/cloudformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,10 @@
}
],
"Version": "2012-10-17"
}
},
"ManagedPolicyArns": [
"aws:arn:iam:123456789000:policy:test-policy"
]
}
},
"AWSIAMRolenodescomplexexamplecom": {
Expand All @@ -1057,7 +1060,10 @@
}
],
"Version": "2012-10-17"
}
},
"ManagedPolicyArns": [
"aws:arn:iam:123456789000:policy:test-policy"
]
}
},
"AWSRoute53RecordSetapicomplexexamplecom": {
Expand Down
40 changes: 10 additions & 30 deletions tests/integration/update_cluster/complex/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -267,36 +267,6 @@ resource "aws_iam_role" "nodes-complex-example-com" {
assume_role_policy = "${file("${path.module}/data/aws_iam_role_nodes.complex.example.com_policy")}"
}

resource "aws_iam_policy" "role-test-policy" {
name = "role-test-policy"
description = "A test policy"

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}

resource "aws_iam_role_policy_attachment" "nodes-policyoverride" {
role = "${aws_iam_role.nodes-complex-example-com.name}"
policy_arn = "${aws_iam_policy.role-test-policy.arn}"
}

resource "aws_iam_role_policy_attachment" "masters-policyoverride" {
role = "${aws_iam_role.masters-complex-example-com.name}"
policy_arn = "${aws_iam_policy.role-test-policy.arn}"
}

resource "aws_iam_role_policy" "masters-complex-example-com" {
name = "masters.complex.example.com"
role = "${aws_iam_role.masters-complex-example-com.name}"
Expand All @@ -309,6 +279,16 @@ resource "aws_iam_role_policy" "nodes-complex-example-com" {
policy = "${file("${path.module}/data/aws_iam_role_policy_nodes.complex.example.com_policy")}"
}

resource "aws_iam_role_policy_attachment" "master-policyoverride" {
role = "${aws_iam_role.masters-complex-example-com.name}"
policy_arn = "aws:arn:iam:123456789000:policy:test-policy"
}

resource "aws_iam_role_policy_attachment" "node-policyoverride" {
role = "${aws_iam_role.nodes-complex-example-com.name}"
policy_arn = "aws:arn:iam:123456789000:policy:test-policy"
}

resource "aws_internet_gateway" "complex-example-com" {
vpc_id = "${aws_vpc.complex-example-com.id}"

Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/awstasks/iamrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (e *IAMRole) TerraformLink() *terraform.Literal {
type cloudformationIAMRole struct {
RoleName *string `json:"RoleName"`
AssumeRolePolicyDocument map[string]interface{}
ManagedPolicyArns []string `json:"ManagedPolicyArns,omitempty"`
}

func (_ *IAMRole) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *IAMRole) error {
Expand Down
18 changes: 15 additions & 3 deletions upup/pkg/fi/cloudup/awstasks/iamrolepolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ func (e *IAMRolePolicy) policyDocumentString() (string, error) {
}

type terraformIAMRolePolicy struct {
Name *string `json:"name"`
Name *string `json:"name,omitempty"`
Role *terraform.Literal `json:"role"`
PolicyDocument *terraform.Literal `json:"policy"`
PolicyDocument *terraform.Literal `json:"policy,omitempty"`
PolicyArn *string `json:"policy_arn,omitempty"`
}

Expand Down Expand Up @@ -329,7 +329,19 @@ func (_ *IAMRolePolicy) RenderCloudformation(t *cloudformation.CloudformationTar
// Currently CloudFormation does not have a reciprocal function to Terraform that allows the modification of a role
// after the fact. In order to make this feature complete we would have to intercept the role task and modify it.
if e.PolicyOverrides != nil && len(*e.PolicyOverrides) > 0 {
return fmt.Errorf("CloudFormation not supported for use with PolicyOverrides.")
cfObj, ok := t.Find(e.Role.CloudformationLink())
if !ok {
// topo-sort fail?
return fmt.Errorf("Role not yet rendered")
}
cf, ok := cfObj.(*cloudformationIAMRole)
if !ok {
return fmt.Errorf("unexpected type for CF record: %T", cfObj)
}

cf.ManagedPolicyArns = *e.PolicyOverrides

return nil
}

policyString, err := e.policyDocumentString()
Expand Down

0 comments on commit e90b40d

Please sign in to comment.