Module: Terraforming::Util
- Included in:
- Resource::ALB, Resource::AutoScalingGroup, Resource::CloudWatchAlarm, Resource::Config, Resource::DBParameterGroup, Resource::DBSecurityGroup, Resource::DBSubnetGroup, Resource::EC2, Resource::EFSFileSystem, Resource::EIP, Resource::ELB, Resource::ElastiCacheCluster, Resource::ElastiCacheSubnetGroup, Resource::IAMGroup, Resource::IAMGroupMembership, Resource::IAMGroupPolicy, Resource::IAMInstanceProfile, Resource::IAMPolicy, Resource::IAMPolicyAttachment, Resource::IAMRole, Resource::IAMRolePolicy, Resource::IAMUser, Resource::IAMUserPolicy, Resource::InternetGateway, Resource::KMSAlias, Resource::KMSKey, Resource::LaunchConfiguration, Resource::NATGateway, Resource::NetworkACL, Resource::NetworkInterface, Resource::RDS, Resource::Redshift, Resource::Route53Record, Resource::Route53Zone, Resource::RouteTable, Resource::RouteTableAssociation, Resource::S3, Resource::SNSTopic, Resource::SNSTopicSubscription, Resource::SQS, Resource::SecurityGroup, Resource::Subnet, Resource::VPC, Resource::VPNGateway
- Defined in:
- lib/terraforming/util.rb
Instance Method Summary collapse
- #apply_template(client, erb) ⇒ Object
- #name_from_tag(resource, default_name) ⇒ Object
- #normalize_module_name(name) ⇒ Object
- #prettify_policy(document, breakline: false, unescape: false) ⇒ Object
- #template_path(template_name) ⇒ Object
Instance Method Details
#apply_template(client, erb) ⇒ Object
3 4 5 |
# File 'lib/terraforming/util.rb', line 3 def apply_template(client, erb) ERB.new(open(template_path(erb)).read, nil, "-").result(binding) end |
#name_from_tag(resource, default_name) ⇒ Object
7 8 9 10 |
# File 'lib/terraforming/util.rb', line 7 def name_from_tag(resource, default_name) name_tag = resource..find { |tag| tag.key == "Name" } name_tag ? name_tag.value : default_name end |
#normalize_module_name(name) ⇒ Object
12 13 14 |
# File 'lib/terraforming/util.rb', line 12 def normalize_module_name(name) name.gsub(/[^a-zA-Z0-9_-]/, "-") end |
#prettify_policy(document, breakline: false, unescape: false) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/terraforming/util.rb', line 20 def prettify_policy(document, breakline: false, unescape: false) json = JSON.pretty_generate(JSON.parse(unescape ? CGI.unescape(document) : document)) if breakline json[-1] != "\n" ? json << "\n" : json else json.strip end end |
#template_path(template_name) ⇒ Object
16 17 18 |
# File 'lib/terraforming/util.rb', line 16 def template_path(template_name) File.join(File.(File.dirname(__FILE__)), "template", template_name) << ".erb" end |