Commit a79e2c07 authored by Daisuke Fujita's avatar Daisuke Fujita

Generate IAM Group tf

parent 87f6ec9d
......@@ -15,6 +15,7 @@ require "terraforming/resource/db_security_group"
require "terraforming/resource/db_subnet_group"
require "terraforming/resource/ec2"
require "terraforming/resource/elb"
require "terraforming/resource/iam_group"
require "terraforming/resource/iam_user"
require "terraforming/resource/network_acl"
require "terraforming/resource/rds"
......
module Terraforming
module Resource
class IAMGroup
include Terraforming::Util
def self.tf(client = Aws::IAM::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::IAM::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/iam_group")
end
def tfstate
end
private
def iam_groups
@client.list_groups.groups
end
end
end
end
<% iam_groups.each do |group| -%>
resource "aws_iam_group" "<%= group.group_name %>" {
name = "<%= group.group_name %>"
path = "<%= group.path %>"
}
<% end -%>
require "spec_helper"
module Terraforming
module Resource
describe IAMGroup do
let(:client) do
Aws::IAM::Client.new(stub_responses: true)
end
let(:groups) do
[
{
path: "/",
group_name: "hoge",
group_id: "ABCDEFGHIJKLMN1234567",
arn: "arn:aws:iam::123456789012:user/hoge",
create_date: Time.parse("2015-04-01 12:34:56 UTC"),
},
{
path: "/system/",
group_name: "fuga",
group_id: "OPQRSTUVWXYZA8901234",
arn: "arn:aws:iam::345678901234:user/fuga",
create_date: Time.parse("2015-05-01 12:34:56 UTC"),
},
]
end
before do
client.stub_responses(:list_groups, groups: groups)
end
describe ".tf" do
it "should generate tf" do
expect(described_class.tf(client)).to eq <<-EOS
resource "aws_iam_group" "hoge" {
name = "hoge"
path = "/"
}
resource "aws_iam_group" "fuga" {
name = "fuga"
path = "/system/"
}
EOS
end
end
describe ".tfstate" do
xit "should generate tfstate" do
expect(described_class.tfstate(client)).to eq JSON.pretty_generate({
"version" => 1,
"serial" => 1,
"modules" => {
"path" => [
"root"
],
"outputs" => {},
"resources" => {
"aws_iam_user.hoge" => {
"type" => "aws_iam_user",
"primary" => {
"id" => "hoge",
"attributes" => {
"arn"=> "arn:aws:iam::123456789012:user/hoge",
"id" => "hoge",
"name" => "hoge",
"path" => "/",
"unique_id" => "ABCDEFGHIJKLMN1234567",
}
}
},
"aws_iam_user.fuga" => {
"type" => "aws_iam_user",
"primary" => {
"id" => "fuga",
"attributes" => {
"arn"=> "arn:aws:iam::345678901234:user/fuga",
"id" => "fuga",
"name" => "fuga",
"path" => "/system/",
"unique_id" => "OPQRSTUVWXYZA8901234",
}
}
},
}
}
})
end
end
end
end
end
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