Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Normalize all resource names in tf and tfstate files #296

Merged
merged 3 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/terraforming/resource/efs_file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def tfstate
"tags.Name" => efs.name,
}

resources["aws_efs_file_system.#{efs.file_system_id}"] = {
resources["aws_efs_file_system.#{module_name_of(efs)}"] = {
"type" => "aws_efs_file_system",
"depends_on" => [],
"primary" => {
Expand All @@ -51,6 +51,10 @@ def tfstate
def file_systems
@client.describe_file_systems.data.file_systems.flatten
end

def module_name_of(efs)
normalize_module_name(efs.file_system_id)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/eip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def tfstate
"vpc" => vpc?(addr).to_s,
}
attributes.delete_if { |_k, v| v.nil? }
resources["aws_eip.#{addr.allocation_id}"] = {
resources["aws_eip.#{module_name_of(addr)}"] = {
"type" => "aws_eip",
"primary" => {
"id" => addr.allocation_id,
Expand All @@ -53,6 +53,10 @@ def eips
def vpc?(addr)
addr.domain.eql?("vpc")
end

def module_name_of(addr)
normalize_module_name(addr.allocation_id)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/elasti_cache_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def tfstate
cache_cluster.cache_nodes[0].endpoint.port.to_s
end

resources["aws_elasticache_cluster.#{cache_cluster.cache_cluster_id}"] = {
resources["aws_elasticache_cluster.#{module_name_of(cache_cluster)}"] = {
"type" => "aws_elasticache_cluster",
"primary" => {
"id" => cache_cluster.cache_cluster_id,
Expand Down Expand Up @@ -71,6 +71,10 @@ def security_group_ids_of(cache_cluster)
def security_group_names_of(cache_cluster)
cache_cluster.cache_security_groups.map { |sg| sg.cache_security_group_name }
end

def module_name_of(cache_cluster)
normalize_module_name(cache_cluster.cache_cluster_id)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/elasti_cache_subnet_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def tfstate
"name" => cache_subnet_group.cache_subnet_group_name,
"subnet_ids.#" => subnet_ids_of(cache_subnet_group).length.to_s,
}
resources["aws_elasticache_subnet_group.#{cache_subnet_group.cache_subnet_group_name}"] = {
resources["aws_elasticache_subnet_group.#{module_name_of(cache_subnet_group)}"] = {
"type" => "aws_elasticache_subnet_group",
"primary" => {
"id" => cache_subnet_group.cache_subnet_group_name,
Expand All @@ -47,6 +47,10 @@ def cache_subnet_groups
def subnet_ids_of(cache_subnet_group)
cache_subnet_group.subnets.map { |sn| sn.subnet_identifier }
end

def module_name_of(cache_subnet_group)
normalize_module_name(cache_subnet_group.cache_subnet_group_name)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/iam_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def tfstate
"path" => group.path,
"unique_id" => group.group_id,
}
resources["aws_iam_group.#{group.group_name}"] = {
resources["aws_iam_group.#{module_name_of(group)}"] = {
"type" => "aws_iam_group",
"primary" => {
"id" => group.group_name,
Expand All @@ -45,6 +45,10 @@ def tfstate
def iam_groups
@client.list_groups.map(&:groups).flatten
end

def module_name_of(group)
normalize_module_name(group.group_name)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/iam_group_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def tfstate
"name" => membership_name,
"users.#" => group_members_of(group).length.to_s,
}
resources["aws_iam_group_membership.#{group.group_name}"] = {
resources["aws_iam_group_membership.#{module_name_of(group)}"] = {
"type" => "aws_iam_group_membership",
"primary" => {
"id" => membership_name,
Expand All @@ -54,6 +54,10 @@ def iam_groups
def membership_name_of(group)
"#{group.group_name}-group-membership"
end

def module_name_of(group)
normalize_module_name(group.group_name)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/terraforming/resource/iam_group_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def tfstate
private

def unique_name(policy)
"#{policy.group_name}_#{policy.policy_name}"
"#{normalize_module_name(policy.group_name)}_#{normalize_module_name(policy.policy_name)}"
end

def iam_group_policy_id_of(policy)
Expand Down
6 changes: 5 additions & 1 deletion lib/terraforming/resource/iam_instance_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def tfstate
"path" => profile.path,
"roles.#" => profile.roles.length.to_s,
}
resources["aws_iam_instance_profile.#{profile.instance_profile_name}"] = {
resources["aws_iam_instance_profile.#{module_name_of(profile)}"] = {
"type" => "aws_iam_instance_profile",
"primary" => {
"id" => profile.instance_profile_name,
Expand All @@ -45,6 +45,10 @@ def tfstate
def iam_instance_profiles
@client.list_instance_profiles.map(&:instance_profiles).flatten
end

def module_name_of(profile)
normalize_module_name(profile.instance_profile_name)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/iam_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def tfstate
"description" => iam_policy_description(policy),
"policy" => prettify_policy(version.document, breakline: true, unescape: true),
}
resources["aws_iam_policy.#{policy.policy_name}"] = {
resources["aws_iam_policy.#{module_name_of(policy)}"] = {
"type" => "aws_iam_policy",
"primary" => {
"id" => policy.arn,
Expand All @@ -54,6 +54,10 @@ def iam_policy_description(policy)
def iam_policy_version_of(policy)
@client.get_policy_version(policy_arn: policy.arn, version_id: policy.default_version_id).policy_version
end

def module_name_of(policy)
normalize_module_name(policy.policy_name)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/iam_policy_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def tfstate
"users.#" => policy_attachment[:entities].policy_users.length.to_s,
"roles.#" => policy_attachment[:entities].policy_roles.length.to_s,
}
resources["aws_iam_policy_attachment.#{policy_attachment[:name]}"] = {
resources["aws_iam_policy_attachment.#{module_name_of(policy_attachment)}"] = {
"type" => "aws_iam_policy_attachment",
"primary" => {
"id" => policy_attachment[:name],
Expand Down Expand Up @@ -77,6 +77,10 @@ def iam_policy_attachments
}
end
end

def module_name_of(policy_attachment)
normalize_module_name(policy_attachment[:name])
end
end
end
end
6 changes: 5 additions & 1 deletion lib/terraforming/resource/iam_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def tfstate
"path" => role.path,
"unique_id" => role.role_id,
}
resources["aws_iam_role.#{role.role_name}"] = {
resources["aws_iam_role.#{module_name_of(role)}"] = {
"type" => "aws_iam_role",
"primary" => {
"id" => role.role_name,
Expand All @@ -47,6 +47,10 @@ def tfstate
def iam_roles
@client.list_roles.map(&:roles).flatten
end

def module_name_of(role)
normalize_module_name(role.role_name)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/terraforming/resource/iam_role_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def tfstate
private

def unique_name(policy)
"#{policy.role_name}_#{policy.policy_name}"
"#{normalize_module_name(policy.role_name)}_#{normalize_module_name(policy.policy_name)}"
end

def iam_role_policy_id_of(policy)
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/resource/iam_user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def tfstate
private

def unique_name(policy)
"#{policy.user_name}_#{policy.policy_name}"
"#{normalize_module_name(policy.user_name)}_#{normalize_module_name(policy.policy_name)}"
end

def iam_user_policy_id_of(policy)
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/eip.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% eips.each do |addr| -%>
resource "aws_eip" "<%= addr.allocation_id %>" {
resource "aws_eip" "<%= module_name_of(addr) %>" {
<% if addr.instance_id -%>
instance = "<%= addr.instance_id %>"
<% elsif addr.network_interface_id -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/elasti_cache_cluster.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% cache_clusters.each do |cache_cluster| -%>
resource "aws_elasticache_cluster" "<%= cache_cluster.cache_cluster_id %>" {
resource "aws_elasticache_cluster" "<%= module_name_of(cache_cluster) %>" {
cluster_id = "<%= cache_cluster.cache_cluster_id %>"
engine = "<%= cache_cluster.engine %>"
engine_version = "<%= cache_cluster.engine_version %>"
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/elasti_cache_subnet_group.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% cache_subnet_groups.each do |cache_subnet_group| -%>
resource "aws_elasticache_subnet_group" "<%= cache_subnet_group.cache_subnet_group_name %>" {
resource "aws_elasticache_subnet_group" "<%= module_name_of(cache_subnet_group) %>" {
name = "<%= cache_subnet_group.cache_subnet_group_name %>"
description = "<%= cache_subnet_group.cache_subnet_group_description %>"
subnet_ids = <%= subnet_ids_of(cache_subnet_group).inspect %>
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/elastic_filesystem.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% file_systems.each_with_index do |efs, idx| -%>
resource "aws_efs_file_system" "<%= efs.file_system_id %>" {
resource "aws_efs_file_system" "<%= module_name_of(efs) %>" {
<% if efs.creation_token -%>
creation_token = "<%= efs.creation_token %>"
<% end -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/iam_group.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% iam_groups.each do |group| -%>
resource "aws_iam_group" "<%= group.group_name %>" {
resource "aws_iam_group" "<%= module_name_of(group) %>" {
name = "<%= group.group_name %>"
path = "<%= group.path %>"
}
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/iam_group_membership.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% iam_groups.each do |group| -%>
resource "aws_iam_group_membership" "<%= group.group_name %>" {
resource "aws_iam_group_membership" "<%= module_name_of(group) %>" {
name = "<%= membership_name_of(group) %>"
users = <%= group_members_of(group).inspect %>
group = "<%= group.group_name %>"
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/iam_instance_profile.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% iam_instance_profiles.each do |profile| -%>
resource "aws_iam_instance_profile" "<%= profile.instance_profile_name %>" {
resource "aws_iam_instance_profile" "<%= module_name_of(profile) %>" {
name = "<%= profile.instance_profile_name %>"
path = "<%= profile.path %>"
roles = <%= profile.roles.map { |role| role.role_name }.inspect %>
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/iam_policy.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% iam_policies.each do |policy| -%>
<%- version = iam_policy_version_of(policy) -%>
resource "aws_iam_policy" "<%= policy.policy_name %>" {
resource "aws_iam_policy" "<%= module_name_of(policy) %>" {
name = "<%= policy.policy_name %>"
path = "<%= policy.path %>"
description = "<%= iam_policy_description(policy) %>"
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/iam_policy_attachment.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% iam_policy_attachments.each do |policy_attachment| -%>
resource "aws_iam_policy_attachment" "<%= policy_attachment[:name] %>" {
resource "aws_iam_policy_attachment" "<%= module_name_of(policy_attachment) %>" {
name = "<%= policy_attachment[:name] %>"
policy_arn = "<%= policy_attachment[:arn] %>"
groups = <%= policy_attachment[:entities].policy_groups.map(&:group_name).inspect %>
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/iam_role.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% iam_roles.each do |role| -%>
resource "aws_iam_role" "<%= role.role_name %>" {
resource "aws_iam_role" "<%= module_name_of(role) %>" {
name = "<%= role.role_name %>"
path = "<%= role.path %>"
assume_role_policy = <<POLICY
Expand Down
2 changes: 1 addition & 1 deletion lib/terraforming/template/tf/redshift.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% clusters.each do |cluster| -%>
resource "aws_redshift_cluster" "<%= cluster.cluster_identifier %>" {
resource "aws_redshift_cluster" "<%= module_name_of(cluster) %>" {
cluster_identifier = "<%= cluster.cluster_identifier %>"
<%- if cluster.db_name -%>
database_name = "<%= cluster.db_name %>"
Expand Down