Skip to content
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

azurerm_cost_management_scheduled_action - add update for email_address_sender #22930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ func (r CostManagementScheduledActionResource) Update() sdk.ResourceFunc {
model.Properties.ViewId = id.ID()
}

if metadata.ResourceData.HasChange("email_address_sender") {
model.Properties.NotificationEmail = utils.String(metadata.ResourceData.Get("email_address_sender").(string))
}

if metadata.ResourceData.HasChange("email_subject") {
model.Properties.Notification.Subject = metadata.ResourceData.Get("email_subject").(string)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ func TestAccCostManagementScheduledAction_requiresImport(t *testing.T) {
})
}

func TestAccCostManagementScheduledAction_emailAddressSender(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cost_management_scheduled_action", "test")
r := CostManagementScheduledAction{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.emailAddressSender(data, "test@test.com"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.emailAddressSender(data, "test2@test2.com"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t CostManagementScheduledAction) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := scheduledactions.ParseScopedScheduledActionID(state.ID)
if err != nil {
Expand Down Expand Up @@ -244,3 +266,31 @@ resource "azurerm_cost_management_scheduled_action" "import" {
}
`, template)
}

func (CostManagementScheduledAction) emailAddressSender(data acceptance.TestData, emailAddressSender string) string {
start := time.Now().AddDate(0, 0, 1).UTC().Format("2006-01-02T00:00:00Z")
end := time.Now().AddDate(0, 0, 2).UTC().Format("2006-01-02T00:00:00Z")

return fmt.Sprintf(`
provider "azurerm" {
features {}
}

data "azurerm_subscription" "test" {}

resource "azurerm_cost_management_scheduled_action" "test" {
name = "testcostview%s"

view_id = "${data.azurerm_subscription.test.id}/providers/Microsoft.CostManagement/views/ms:CostByService"

display_name = "CostByServiceView%s"
email_subject = substr("Cost Management Report for ${data.azurerm_subscription.test.display_name} Subscription", 0, 70)
email_addresses = ["test@test.com", "hashicorp@test.com"]
email_address_sender = "%s"

frequency = "Daily"
start_date = "%s"
end_date = "%s"
}
`, data.RandomString, data.RandomString, emailAddressSender, start, end)
}