Code Monkey home page Code Monkey logo

Comments (19)

krogebry avatar krogebry commented on June 18, 2024 2

I'd like to revisit this conversation and add some learnings that we've gained from our side.

What we started doing was basically this (metacode):

ec2_client = Aws::EC2::Client.new()
res = ec2_client.describe_blah_resource(filters: [{filter thngie}])
my_resource__id = res['blah']['Id']

describe resource(my_resource_id) do....

There are a few problems at play here:

  1. We have dynamically created resources, so our names cannot be guaranteed.
  2. The code above won't work because of the converge model of a standard ruby based DSL. In other words, we can't create our stack, then check for the resources because the code outside of the DSL block ( describe in this case ) is executed before the methods of the DLS. In this case the EC2 client action would happen before the test, which breaks everything because the stack hasn't been created yet.

We have been addressing #2 by creating separate pipelines using different Jenkinsfiles in our projects to address the timing issue. So far it's worked well enough.

However, I would like to propose an idea here that would look like this:

search_thing = Awspec::Helper::SearchFilter.new({ 'Name' => 'NameTagOfThing' })
describe thing(search_thing) do....

The idea being that we have a class that can be passed into any finder that would extend the core search functionality.

I might even take this a step further and propose that we create a default SearchFilter for every finder, then allow the user to override the filter as needed.

This would solve both of our problems, and give awspec the ability to address dynamic resources in valuable way.

Thoughts?

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024 2

Hi @krogebry !

I just released https://github.com/k1LoW/awsrm ! (although it is the minimum function)

If you want to test autoscalint_group by tag on awspec, you can use Awsrm::AutoscallingGroup.one

require 'spec_helper'
require 'awsrm'

describe autoscaling_group(Awsrm::AutoscallingGroup.one(tags: { Role: 'WebServer' }).id) do
  it { should exist }
  it { should have_tag('Role').value('WebServer') }
end

awsrm support only autoscaling_group route_table subnet , now. I will increase support resources.

Regards.

from awspec.

krogebry avatar krogebry commented on June 18, 2024 1

Thanks for the response.

The thing is, we're using CFT's for our infrastructure management, which means we get an autogenerated name for the ASG. We can't guarantee consistency with the name of the ASG, and we also cannot specify the name in the CFT. We're thinking that we might have this problem with other resources down the road that we haven't gotten to yet.

I see that you throw an exception if more than one result is found for any given search, so it seems like you're already handling the condition of multiple resources existing. I would fully expect that if we had multiple resources with the same tag:Name value, that an exception would be thrown and the test would fail.

Can you help me understand what your apprehension is here? I'm interested in learning more about your approach.

from awspec.

georgealton avatar georgealton commented on June 18, 2024 1

I'm in the same situation where I'm using CFN to deploy Autoscaling Groups and other Resources where CloudFormation is assigning the names of those resources.

I'd generally like to be able to 'find' the Resource by using tags to locate it.

from awspec.

krogebry avatar krogebry commented on June 18, 2024

Addressed by #225 .

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

Hi @krogebry ! Thank you for your interesting idea.

I think

It is difficult for me to agree with "using Hash argument for tags ( key & value )".

Because,

Tags are usually assigned to multiple resources (so, you can not use awspec ).
And I do not want to handle only tags specially. ( Name tag is special, because it is special on AMC )

Best Regards.

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

which means we get an autogenerated name for the ASG

mmm... it is true.

I have not use AWS CloudFormation Templates.

I do not want to handle only tags specially ( use Hash ), but I want to solve your problem.

from awspec.

krogebry avatar krogebry commented on June 18, 2024

I do not want to handle only tags specially ( use Hash ), but I want to solve your problem.

only tags? You can send the id of the object or a Hash structure. Or, did I misunderstand what you intended here?

I see you're in Japan, let me know if we have any communication problems with language or whatever. I'm more than happy to accommodate to your needs.

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

Sorry for my poor english;;

I do not want to handle only tags specially ( use Hash ), but I want to solve your problem.

  • I do not want to use Hash args for tags "only"
  • I understood your problem.

from awspec.

krogebry avatar krogebry commented on June 18, 2024

Do you have any ideas on how we might be able to get what we want here?

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

I have no idea now.

from awspec.

herebebogans avatar herebebogans commented on June 18, 2024

@krogebry

The way we've gone about this is to use Cloudformation stack outputs for each resource we want to spec test against. We prefix each output with "SPEC"

With a few helper ruby cloudformation stack utilities (cfndsl / bora) - it's pretty easy to share stack parameters and outputs without much code duplication between the stack template and spec.

from awspec.

krogebry avatar krogebry commented on June 18, 2024

@k1LoW Sorry to bug you, but I wanted to see about putting this on your radar again.

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

@krogebry

Your idea looks good to me ( search filter ).

I'm carefully considering this issue, now.

I will introduce my ideas at the moment.

Idea 1: find "only one" resource helper

describe ec2(ec2_filter(tags: {'Name' => 'NameTagOfThing'})) do
   it { sholud be_running }
end

describe ec2(tags: {'Name' => 'NameTagOfThing'}) do # work ec2_filter() inside
   it { sholud be_running }
end

same as @krogebry 's idea.

Idea 2: find multiple resource ids helper

ec2_instances(tags: {'Name' => 'NameTagOfThing'}).each |id|
  describe ec2(id) do
     it { sholud be_running }
  end
end

ec2_instances(asg: 'my-asg').each |id|
  describe ec2(id) do
     it { sholud be_running }
  end
end

Idea 3: Both 1 and 2

from awspec.

inokappa avatar inokappa commented on June 18, 2024

I agree with Idea 2. 🙇

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

Memo

https://aws.amazon.com/jp/blogs/aws/new-aws-resource-tagging-api/

from awspec.

IssueHuntBot avatar IssueHuntBot commented on June 18, 2024

@issuehuntfest has funded $20.00 to this issue. See it on IssueHunt

from awspec.

glasswalk3r avatar glasswalk3r commented on June 18, 2024

@k1LoW this one can be closed due the release of awsrm.

from awspec.

k1LoW avatar k1LoW commented on June 18, 2024

👍

from awspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.