Skip to content

Commit

Permalink
sdkv2shim - consumption (#11914)
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte authored May 25, 2021
1 parent 407a54c commit 46174df
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2019-10-01/consumption"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/shopspring/decimal"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func resourceArmConsumptionBudgetRead(d *schema.ResourceData, meta interface{}, scope, name string) error {
func resourceArmConsumptionBudgetRead(d *pluginsdk.ResourceData, meta interface{}, scope, name string) error {
client := meta.(*clients.Client).Consumption.BudgetsClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand All @@ -33,13 +33,13 @@ func resourceArmConsumptionBudgetRead(d *schema.ResourceData, meta interface{},
}
d.Set("time_grain", string(resp.TimeGrain))
d.Set("time_period", FlattenConsumptionBudgetTimePeriod(resp.TimePeriod))
d.Set("notification", schema.NewSet(schema.HashResource(SchemaConsumptionBudgetNotificationElement()), FlattenConsumptionBudgetNotifications(resp.Notifications)))
d.Set("notification", pluginsdk.NewSet(pluginsdk.HashResource(SchemaConsumptionBudgetNotificationElement()), FlattenConsumptionBudgetNotifications(resp.Notifications)))
d.Set("filter", FlattenConsumptionBudgetFilter(resp.Filter))

return nil
}

func resourceArmConsumptionBudgetDelete(d *schema.ResourceData, meta interface{}, scope string) error {
func resourceArmConsumptionBudgetDelete(d *pluginsdk.ResourceData, meta interface{}, scope string) error {
client := meta.(*clients.Client).Consumption.BudgetsClient
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand All @@ -56,7 +56,7 @@ func resourceArmConsumptionBudgetDelete(d *schema.ResourceData, meta interface{}
return nil
}

func resourceArmConsumptionBudgetCreateUpdate(d *schema.ResourceData, meta interface{}, resourceName, scope string) error {
func resourceArmConsumptionBudgetCreateUpdate(d *pluginsdk.ResourceData, meta interface{}, resourceName, scope string) error {
client := meta.(*clients.Client).Consumption.BudgetsClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -91,7 +91,7 @@ func resourceArmConsumptionBudgetCreateUpdate(d *schema.ResourceData, meta inter
Amount: &amount,
Category: &category,
Filter: ExpandConsumptionBudgetFilter(d.Get("filter").([]interface{})),
Notifications: ExpandConsumptionBudgetNotifications(d.Get("notification").(*schema.Set).List()),
Notifications: ExpandConsumptionBudgetNotifications(d.Get("notification").(*pluginsdk.Set).List()),
TimeGrain: consumption.TimeGrainType(d.Get("time_grain").(string)),
TimePeriod: timePeriod,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package consumption
import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/consumption/parse"
resourceParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
)

func resourceArmConsumptionBudgetResourceGroup() *schema.Resource {
return &schema.Resource{
func resourceArmConsumptionBudgetResourceGroup() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceArmConsumptionBudgetResourceGroupCreateUpdate,
Read: resourceArmConsumptionBudgetResourceGroupRead,
Update: resourceArmConsumptionBudgetResourceGroupCreateUpdate,
Expand All @@ -20,18 +19,18 @@ func resourceArmConsumptionBudgetResourceGroup() *schema.Resource {
return err
}),

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
Timeouts: &pluginsdk.ResourceTimeout{
Create: pluginsdk.DefaultTimeout(30 * time.Minute),
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
Update: pluginsdk.DefaultTimeout(30 * time.Minute),
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

Schema: SchemaConsumptionBudgetResourceGroupResource(),
}
}

func resourceArmConsumptionBudgetResourceGroupCreateUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceArmConsumptionBudgetResourceGroupCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
resourceGroupId, err := resourceParse.ResourceGroupID(d.Get("resource_group_id").(string))
if err != nil {
Expand All @@ -48,7 +47,7 @@ func resourceArmConsumptionBudgetResourceGroupCreateUpdate(d *schema.ResourceDat
return resourceArmConsumptionBudgetResourceGroupRead(d, meta)
}

func resourceArmConsumptionBudgetResourceGroupRead(d *schema.ResourceData, meta interface{}) error {
func resourceArmConsumptionBudgetResourceGroupRead(d *pluginsdk.ResourceData, meta interface{}) error {
consumptionBudgetId, err := parse.ConsumptionBudgetResourceGroupID(d.Id())
if err != nil {
return err
Expand All @@ -67,7 +66,7 @@ func resourceArmConsumptionBudgetResourceGroupRead(d *schema.ResourceData, meta
return nil
}

func resourceArmConsumptionBudgetResourceGroupDelete(d *schema.ResourceData, meta interface{}) error {
func resourceArmConsumptionBudgetResourceGroupDelete(d *pluginsdk.ResourceData, meta interface{}) error {
consumptionBudgetId, err := parse.ConsumptionBudgetResourceGroupID(d.Id())
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/consumption/parse"
resourceParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -22,10 +21,10 @@ func TestAccConsumptionBudgetResourceGroup_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_resource_group", "test")
r := ConsumptionBudgetResourceGroupResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -37,17 +36,17 @@ func TestAccConsumptionBudgetResourceGroup_basicUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_resource_group", "test")
r := ConsumptionBudgetResourceGroupResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicUpdate(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -59,10 +58,10 @@ func TestAccConsumptionBudgetResourceGroup_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_resource_group", "test")
r := ConsumptionBudgetResourceGroupResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -77,10 +76,10 @@ func TestAccConsumptionBudgetResourceGroup_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_resource_group", "test")
r := ConsumptionBudgetResourceGroupResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -91,25 +90,25 @@ func TestAccConsumptionBudgetResourceGroup_completeUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_resource_group", "test")
r := ConsumptionBudgetResourceGroupResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.completeUpdate(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (ConsumptionBudgetResourceGroupResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
func (ConsumptionBudgetResourceGroupResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ConsumptionBudgetResourceGroupID(state.ID)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package consumption
import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/consumption/parse"
subscriptionParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/subscription/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
)

func resourceArmConsumptionBudgetSubscription() *schema.Resource {
return &schema.Resource{
func resourceArmConsumptionBudgetSubscription() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceArmConsumptionBudgetSubscriptionCreateUpdate,
Read: resourceArmConsumptionBudgetSubscriptionRead,
Update: resourceArmConsumptionBudgetSubscriptionCreateUpdate,
Expand All @@ -20,18 +19,18 @@ func resourceArmConsumptionBudgetSubscription() *schema.Resource {
return err
}),

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
Timeouts: &pluginsdk.ResourceTimeout{
Create: pluginsdk.DefaultTimeout(30 * time.Minute),
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
Update: pluginsdk.DefaultTimeout(30 * time.Minute),
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

Schema: SchemaConsumptionBudgetSubscriptionResource(),
}
}

func resourceArmConsumptionBudgetSubscriptionCreateUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceArmConsumptionBudgetSubscriptionCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
subscriptionId := subscriptionParse.NewSubscriptionId(d.Get("subscription_id").(string))

Expand All @@ -45,7 +44,7 @@ func resourceArmConsumptionBudgetSubscriptionCreateUpdate(d *schema.ResourceData
return resourceArmConsumptionBudgetSubscriptionRead(d, meta)
}

func resourceArmConsumptionBudgetSubscriptionRead(d *schema.ResourceData, meta interface{}) error {
func resourceArmConsumptionBudgetSubscriptionRead(d *pluginsdk.ResourceData, meta interface{}) error {
consumptionBudgetId, err := parse.ConsumptionBudgetSubscriptionID(d.Id())
if err != nil {
return err
Expand All @@ -63,7 +62,7 @@ func resourceArmConsumptionBudgetSubscriptionRead(d *schema.ResourceData, meta i
return nil
}

func resourceArmConsumptionBudgetSubscriptionDelete(d *schema.ResourceData, meta interface{}) error {
func resourceArmConsumptionBudgetSubscriptionDelete(d *pluginsdk.ResourceData, meta interface{}) error {
consumptionBudgetId, err := parse.ConsumptionBudgetSubscriptionID(d.Id())
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/consumption/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -28,10 +27,10 @@ func TestAccConsumptionBudgetSubscription_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_subscription", "test")
r := ConsumptionBudgetSubscriptionResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -43,17 +42,17 @@ func TestAccConsumptionBudgetSubscription_basicUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_subscription", "test")
r := ConsumptionBudgetSubscriptionResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicUpdate(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -65,10 +64,10 @@ func TestAccConsumptionBudgetSubscription_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_subscription", "test")
r := ConsumptionBudgetSubscriptionResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -83,10 +82,10 @@ func TestAccConsumptionBudgetSubscription_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_subscription", "test")
r := ConsumptionBudgetSubscriptionResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
Expand All @@ -97,25 +96,25 @@ func TestAccConsumptionBudgetSubscription_completeUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_consumption_budget_subscription", "test")
r := ConsumptionBudgetSubscriptionResource{}

data.ResourceTest(t, r, []resource.TestStep{
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.completeUpdate(data),
Check: resource.ComposeTestCheckFunc(
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (ConsumptionBudgetSubscriptionResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
func (ConsumptionBudgetSubscriptionResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ConsumptionBudgetSubscriptionID(state.ID)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 46174df

Please sign in to comment.