-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Resource: azurerm_log_profile #1792
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
93225ee
Add log profile resource
liemnotliam cc059f7
Update log profile read
liemnotliam 003fd2f
Fix unsused variables
liemnotliam 1f416d3
Add non-nil validation on name
liemnotliam 52cf122
Update log profile tests
liemnotliam 4d885b0
Update log profile resource and data source
liemnotliam a1c061b
Update log profile docs
liemnotliam 41d16a1
Update log profile acc tests to run as combined tests
liemnotliam 79b0c6a
Fixes to address PR comments
liemnotliam 72dbe16
Add monitor log profile sweeper
liemnotliam f1c184b
Merge branch 'master' into log-profile
liemnotliam bb575e1
Fix sidebar link text
liemnotliam 1e9b6d0
Return more detailed error
liemnotliam fc52aa2
Merge branch 'master' into log-profile
liemnotliam abe39d7
Rename log profiles client to include monitor prefix
liemnotliam 8f7b279
Merge master into log-profile
katbyte 006ec9d
Merge branch 'master' into log-profile
liemnotliam faabaa8
Update log profile docs wording and format test templates
liemnotliam 3812cc5
Combine log profile tests to prevent conflicts
liemnotliam cb5471a
Added comments and doubled creation timeout
katbyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmMonitorLogProfile() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmLogProfileRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"storage_account_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"servicebus_rule_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"locations": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"categories": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"retention_policy": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"days": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmLogProfileRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).monitorLogProfilesClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resp, err := client.Get(ctx, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Log Profile %q was not found", name) | ||
} | ||
return fmt.Errorf("Error reading Log Profile: %+v", err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
if props := resp.LogProfileProperties; props != nil { | ||
d.Set("storage_account_id", props.StorageAccountID) | ||
d.Set("servicebus_rule_id", props.ServiceBusRuleID) | ||
d.Set("categories", props.Categories) | ||
|
||
if err := d.Set("locations", flattenAzureRmLogProfileLocations(props.Locations)); err != nil { | ||
return fmt.Errorf("Error flattening `locations`: %+v", err) | ||
} | ||
|
||
if err := d.Set("retention_policy", flattenAzureRmLogProfileRetentionPolicy(props.RetentionPolicy)); err != nil { | ||
return fmt.Errorf("Error flattening `retention_policy`: %+v", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMMonitorLogProfile(t *testing.T) { | ||
// NOTE: this is a combined test rather than separate split out tests due to | ||
// Azure only being happy about provisioning one per subscription at once | ||
// (which our test suite can't easily workaround) | ||
testCases := map[string]map[string]func(t *testing.T){ | ||
"basic": { | ||
"eventhub": testAccDataSourceAzureRMMonitorLogProfile_eventhub, | ||
"storageaccount": testAccDataSourceAzureRMMonitorLogProfile_storageaccount, | ||
}, | ||
} | ||
|
||
for group, m := range testCases { | ||
m := m | ||
t.Run(group, func(t *testing.T) { | ||
for name, tc := range m { | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
tc(t) | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func testAccDataSourceAzureRMMonitorLogProfile_storageaccount(t *testing.T) { | ||
dataSourceName := "data.azurerm_monitor_log_profile.test" | ||
ri := acctest.RandInt() | ||
rs := acctest.RandString(10) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogProfileDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(ri, rs, testLocation()), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "categories.#"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "locations.#"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "storage_account_id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "servicebus_rule_id", ""), | ||
resource.TestCheckResourceAttr(dataSourceName, "retention_policy.#", "1"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.enabled"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.days"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMMonitorLogProfile_eventhub(t *testing.T) { | ||
dataSourceName := "data.azurerm_monitor_log_profile.test" | ||
ri := acctest.RandInt() | ||
rs := acctest.RandString(10) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogProfileDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(ri, rs, testLocation()), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "categories.#"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "locations.#"), | ||
resource.TestCheckResourceAttr(dataSourceName, "storage_account_id", ""), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "servicebus_rule_id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "retention_policy.#", "1"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.enabled"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.days"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(rInt int, rString string, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestrg-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_storage_account" "test" { | ||
name = "acctestsa%s" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
location = "${azurerm_resource_group.test.location}" | ||
account_tier = "Standard" | ||
account_replication_type = "GRS" | ||
} | ||
|
||
resource "azurerm_monitor_log_profile" "test" { | ||
name = "acctestlp-%d" | ||
|
||
categories = [ | ||
"Action", | ||
] | ||
|
||
locations = [ | ||
"%s" | ||
] | ||
|
||
storage_account_id = "${azurerm_storage_account.test.id}" | ||
|
||
retention_policy { | ||
enabled = true | ||
days = 7 | ||
} | ||
} | ||
|
||
data "azurerm_monitor_log_profile" "test" { | ||
name = "${azurerm_monitor_log_profile.test.name}" | ||
} | ||
`, rInt, location, rString, rInt, location) | ||
} | ||
|
||
func testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(rInt int, rString string, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestrg-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_eventhub_namespace" "test" { | ||
name = "acctestehns-%s" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
sku = "Standard" | ||
capacity = 2 | ||
} | ||
|
||
resource "azurerm_monitor_log_profile" "test" { | ||
name = "acctestlp-%d" | ||
|
||
categories = [ | ||
"Action", | ||
] | ||
|
||
locations = [ | ||
"%s" | ||
] | ||
|
||
# RootManageSharedAccessKey is created by default with listen, send, manage permissions | ||
servicebus_rule_id = "${azurerm_eventhub_namespace.test.id}/authorizationrules/RootManageSharedAccessKey" | ||
|
||
retention_policy { | ||
enabled = true | ||
days = 7 | ||
} | ||
} | ||
|
||
data "azurerm_monitor_log_profile" "test" { | ||
name = "${azurerm_monitor_log_profile.test.name}" | ||
} | ||
`, rInt, location, rString, rInt, location) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor and not a blocker, but could we left align theres: