Skip to content

Commit

Permalink
Merge pull request #238 from inspec/add_tags_to_resource_group
Browse files Browse the repository at this point in the history
Add tags to resource group
  • Loading branch information
rmoles authored Apr 17, 2020
2 parents ea688b7 + f11d9a5 commit 2b762c7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'rake', '~> 12.3', '>= 12.3.1'

group :development do
gem 'pry', '~> 0.11.3'
gem 'pry-byebug'
end

group :developmen, :test do
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace :test do
task :integration, [:controls] => ['attributes:write', :setup_env] do |_t, args|
cmd = %W( bin/inspec exec #{INTEGRATION_DIR}
--input-file terraform/#{ENV['ATTRIBUTES_FILE']}
--reporter progress
--reporter cli
--no-distinct-exit
-t azure://#{ENV['AZURE_SUBSCRIPTION_ID']} )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,23 @@ is a string value.

## Attributes

- `ids`
- `names`
- `tags`

### names

The names property provides a list of all the Resource Group ids.

its('ids') { should include 'MyResourceGroupID' }

The names property provides a list of all the Resource Group names.

its('names') { should include 'MyResourceGroup' }

The names property provides a list of all the Resource Group tags.

its('tags') { should include '{MyResourceGroupTag=""}' }

## Matchers

Expand Down
9 changes: 8 additions & 1 deletion libraries/azurerm_resource_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class AzurermResourceGroups < AzurermPluralResource
EXAMPLE

FilterTable.create
.register_column(:names, field: 'name')
.register_column(:names, field: :name)
.register_column(:ids, field: :id)
.register_column(:tags, field: :tags)
.install_filter_methods_on_resource(self, :table)

attr_reader :table
Expand All @@ -21,6 +23,11 @@ def initialize
resp = management.resource_groups
return if has_error?(resp)

resp.map! do |r|
r=r.to_h
r[:tags]={} unless r[:tags]
r
end
@table = resp
end

Expand Down
2 changes: 2 additions & 0 deletions terraform/azure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ resource "azurerm_monitor_log_profile" "log_profile" {

locations = [
"eastus",
"global",
]

storage_account_id = azurerm_storage_account.sa.id
Expand All @@ -394,6 +395,7 @@ resource "azurerm_monitor_log_profile" "log_profile" {
enabled = true
days = 365
}
depends_on = [azurerm_storage_account.sa]
}

# MSI External Access VM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
describe azurerm_resource_groups do
it { should exist }
its('names') { should include(resource_group) }
its('tags') { should include({}) }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

describe azurerm_security_center_policy(name: 'default') do
it { should exist }
# if this fails run 'az security auto-provisioning-setting update -n "default" --auto-provision "On"'
it { should have_auto_provisioning_enabled }
its('id') { should eq("/subscriptions/#{ENV['AZURE_SUBSCRIPTION_ID']}/providers/Microsoft.Security/policies/default") }
its('name') { should eq('default') }
Expand Down

0 comments on commit 2b762c7

Please sign in to comment.