This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from notjames/efs
Extended terraforming to create EFS terraform resource.
- Loading branch information
Showing
6 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Terraforming | ||
module Resource | ||
class EFSFileSystem | ||
include Terraforming::Util | ||
|
||
def self.tf(client: Aws::EFS::Client.new) | ||
self.new(client).tf | ||
end | ||
|
||
def self.tfstate(client: Aws::EFS::Client.new) | ||
self.new(client).tfstate | ||
end | ||
|
||
def initialize(client) | ||
@client = client | ||
end | ||
|
||
def tf | ||
apply_template(@client, "tf/elastic_filesystem") | ||
end | ||
|
||
def tfstate | ||
file_systems.inject({}) do |resources, efs| | ||
attributes = { | ||
"creation_token" => efs.creation_token, | ||
"id" => efs.file_system_id, | ||
"performance_mode" => efs.performance_mode, | ||
"tags.%" => "1", | ||
"tags.Name" => efs.name, | ||
} | ||
|
||
resources["aws_efs_file_system.#{efs.file_system_id}"] = { | ||
"type" => "aws_efs_file_system", | ||
"depends_on" => [], | ||
"primary" => { | ||
"id" => efs.file_system_id, | ||
"attributes" => attributes, | ||
"meta" => {}, | ||
"tainted" => false, | ||
}, | ||
"deposed" => [], | ||
"provider" => "aws", | ||
} | ||
|
||
resources | ||
end | ||
end | ||
|
||
private | ||
|
||
def file_systems | ||
@client.describe_file_systems.data.file_systems.flatten | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% file_systems.each_with_index do |efs, idx| -%> | ||
resource "aws_efs_file_system" "<%= efs.file_system_id %>" { | ||
<% if efs.creation_token -%> | ||
creation_token = "<%= efs.creation_token %>" | ||
<% end -%> | ||
<% if efs.file_system_id -%> | ||
file_system_id = "<%= efs.file_system_id %>" | ||
<% end -%> | ||
<% if efs.performance_mode -%> | ||
performance_mode = "<%= efs.performance_mode %>" | ||
<% end -%> | ||
<% if efs.name -%> | ||
tags { | ||
Name = "<%= efs.name %>" | ||
} | ||
<% end -%> | ||
} | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
require "spec_helper" | ||
|
||
module Terraforming | ||
module Resource | ||
describe EFSFileSystem do | ||
let(:client) do | ||
Aws::EFS::Client.new(stub_responses: true) | ||
end | ||
|
||
let(:efs_description_0) do | ||
{ | ||
creation_time: Time.parse("2016-11-01 11:30:00 -0700"), | ||
creation_token: "console-1234abcd-1234-abcd-a123-d34db33f0000", | ||
file_system_id: "fs-0000abcd", | ||
life_cycle_state: "available", | ||
name: "efs_name_0", | ||
number_of_mount_targets: 3, | ||
owner_id: "999999999999", | ||
performance_mode: "generalPurpose", | ||
size_in_bytes: { value: 6144 }, | ||
} | ||
end | ||
|
||
let(:efs_description_1) do | ||
{ | ||
creation_time: Time.parse("2016-10-24 11:42:21 -0700"), | ||
creation_token: "console-0000abcd-4321-dcba-a123-d34db33f0000", | ||
file_system_id: "fs-abcd1234", | ||
life_cycle_state: "available", | ||
name: "efs_name_1", | ||
number_of_mount_targets: 3, | ||
owner_id: "999999999999", | ||
performance_mode: "generalPurpose", | ||
size_in_bytes: { value: 23481234 }, | ||
} | ||
end | ||
|
||
before do | ||
client.stub_responses(:describe_file_systems, file_systems: [efs_description_0, efs_description_1]) | ||
end | ||
|
||
describe ".tf" do | ||
it "should generate tf" do | ||
expect(described_class.tf(client: client)).to eq <<-EOS | ||
resource "aws_efs_file_system" "fs-0000abcd" { | ||
creation_token = "console-1234abcd-1234-abcd-a123-d34db33f0000" | ||
file_system_id = "fs-0000abcd" | ||
performance_mode = "generalPurpose" | ||
tags { | ||
Name = "efs_name_0" | ||
} | ||
} | ||
resource "aws_efs_file_system" "fs-abcd1234" { | ||
creation_token = "console-0000abcd-4321-dcba-a123-d34db33f0000" | ||
file_system_id = "fs-abcd1234" | ||
performance_mode = "generalPurpose" | ||
tags { | ||
Name = "efs_name_1" | ||
} | ||
} | ||
EOS | ||
end | ||
end | ||
|
||
describe ".tfstate" do | ||
it "should generate tfstate" do | ||
expect(described_class.tfstate(client: client)).to eq({ | ||
"aws_efs_file_system.fs-0000abcd" => { | ||
"type" => "aws_efs_file_system", | ||
"depends_on" => [], | ||
"primary" => { | ||
"id" => "fs-0000abcd", | ||
"meta" => {}, | ||
"tainted" => false, | ||
"attributes" => { | ||
"creation_token" => "console-1234abcd-1234-abcd-a123-d34db33f0000", | ||
"id" => "fs-0000abcd", | ||
"performance_mode" => "generalPurpose", | ||
"tags.%" => "1", | ||
"tags.Name" => "efs_name_0" | ||
}, | ||
}, | ||
"deposed" => [], | ||
"provider" => "aws", | ||
}, | ||
"aws_efs_file_system.fs-abcd1234" => { | ||
"type" => "aws_efs_file_system", | ||
"depends_on" => [], | ||
"primary" => { | ||
"id" => "fs-abcd1234", | ||
"meta" => {}, | ||
"tainted" => false, | ||
"attributes" => { | ||
"creation_token" => "console-0000abcd-4321-dcba-a123-d34db33f0000", | ||
"id" => "fs-abcd1234", | ||
"performance_mode" => "generalPurpose", | ||
"tags.%" => "1", | ||
"tags.Name" => "efs_name_1" | ||
}, | ||
}, | ||
"deposed" => [], | ||
"provider" => "aws", | ||
} | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
end |