# Determine inside VPC

**URL:** <https://discourse.chef.io/t/determine-inside-vpc/6211>\
**Category:** Chef Infra (archive)\
**Created:** [January 26, 2015, 7:38pm UTC](https://discourse.chef.io/t/determine-inside-vpc/6211 "2015-01-26T19:38:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [January 26, 2015, 7:38pm UTC](https://discourse.chef.io/t/determine-inside-vpc/6211/1 "2015-01-26T19:38:07Z")

</div>

I’m trying to use ohai to determine if my instance is inside a VPC. There’s  
a key nested down there under node[‘ec2’][‘network\_interfaces\_macs’] when  
this is the case, called vpc\_id, but my ruby is horrible and I’m having  
trouble fetching it. For reasons I don’t understand ohai reports this is a  
dictionary, but when I attempt to iterate over it inside a chef recipe,  
it’s an array.

Is there an easy/better way to determine in chef if your ec2 instance is  
inside a VPC?

Doug

---

<div class="post-metadata">

**Author:** ![Morgan\_Blackthorne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/morgan_blackthorne/32/100_2.png) [@Morgan\_Blackthorne](https://discourse.chef.io/u/Morgan_Blackthorne)\
**Post date:** [January 26, 2015, 7:44pm UTC](https://discourse.chef.io/t/determine-inside-vpc/6211/2 "2015-01-26T19:44:26Z")

</div>

ISTR that you'll have issues with VPC if you don't have the Ohai hint  
loaded. That said, the Ohai hint might actually contain exactly what you're  
looking for to key off of. We run nothing outside of VPC at this point, so  
I can't help beyond that.

--  
~_~ StormeRider ~_~

"Every world needs its heroes [...] They inspire us to be better than we  
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

On Mon, Jan 26, 2015 at 11:38 AM, Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
wrote:

> I'm trying to use ohai to determine if my instance is inside a VPC.  
> There's a key nested down there under  
> node['ec2']['network\_interfaces\_macs'] when this is the case, called  
> vpc\_id, but my ruby is horrible and I'm having trouble fetching it. For  
> reasons I don't understand ohai reports this is a dictionary, but when I  
> attempt to iterate over it inside a chef recipe, it's an array.
> 
> Is there an easy/better way to determine in chef if your ec2 instance is  
> inside a VPC?
> 
> Doug

---

<div class="post-metadata">

**Author:** ![David\_Petzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/david_petzel/32/38_2.png) [@David\_Petzel](https://discourse.chef.io/u/David_Petzel)\
**Post date:** [January 26, 2015, 7:47pm UTC](https://discourse.chef.io/t/determine-inside-vpc/6211/3 "2015-01-26T19:47:07Z")

</div>

Perhaps this will work for you?  
vpc\_id = nil  
node['ec2']['network\_interfaces\_macs'].each\_pair do |iface, data|  
vpc\_id = data['vpc\_id'] if data.key?('vpc\_id')  
end

On Mon, Jan 26, 2015 at 2:38 PM, Douglas Garstang [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
wrote:

> I'm trying to use ohai to determine if my instance is inside a VPC.  
> There's a key nested down there under  
> node['ec2']['network\_interfaces\_macs'] when this is the case, called  
> vpc\_id, but my ruby is horrible and I'm having trouble fetching it. For  
> reasons I don't understand ohai reports this is a dictionary, but when I  
> attempt to iterate over it inside a chef recipe, it's an array.
> 
> Is there an easy/better way to determine in chef if your ec2 instance is  
> inside a VPC?
> 
> Doug
