Commit b3ca3cc9 authored by Daisuke Fujita's avatar Daisuke Fujita

Generate IAM group policy tfstate

parent 63f0f7ed
......@@ -20,16 +20,17 @@ module Terraforming
end
def tfstate
resources = iam_user_policies.inject({}) do |result, policy|
resources = iam_group_policies.inject({}) do |result, policy|
attributes = {
"id" => iam_user_policy_id_of(policy),
"group" => policy.group_name,
"id" => iam_group_policy_id_of(policy),
"name" => policy.policy_name,
"policy" => CGI.unescape(policy.policy_document)
}
result["aws_iam_user_policy.#{policy.policy_name}"] = {
"type" => "aws_iam_user_policy",
result["aws_iam_group_policy.#{policy.policy_name}"] = {
"type" => "aws_iam_group_policy",
"primary" => {
"id" => iam_user_policy_id_of(policy),
"id" => iam_group_policy_id_of(policy),
"attributes" => attributes
}
}
......
......@@ -94,7 +94,7 @@ EOF
end
describe ".tfstate" do
xit "should generate tfstate" do
it "should generate tfstate" do
expect(described_class.tfstate(client)).to eq JSON.pretty_generate({
"version" => 1,
"serial" => 1,
......@@ -104,22 +104,24 @@ EOF
],
"outputs" => {},
"resources" => {
"aws_iam_user_policy.hoge_policy" => {
"type" => "aws_iam_user_policy",
"aws_iam_group_policy.hoge_policy" => {
"type" => "aws_iam_group_policy",
"primary" => {
"id" => "hoge:hoge_policy",
"attributes" => {
"group" => "hoge",
"id" => "hoge:hoge_policy",
"name" => "hoge_policy",
"policy" => "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Action\": [\n \"ec2:Describe*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": \"*\"\n }\n ]\n}\n",
}
}
},
"aws_iam_user_policy.fuga_policy" => {
"type" => "aws_iam_user_policy",
"aws_iam_group_policy.fuga_policy" => {
"type" => "aws_iam_group_policy",
"primary" => {
"id" => "fuga:fuga_policy",
"attributes" => {
"group" => "fuga",
"id" => "fuga:fuga_policy",
"name" => "fuga_policy",
"policy" => "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Action\": [\n \"ec2:Describe*\"\n ],\n \"Effect\": \"Allow\",\n \"Resource\": \"*\"\n }\n ]\n}\n",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment