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_subscription - fix ability to specify DevTest as workload #12066

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -86,7 +86,10 @@ func resourceSubscription() *pluginsdk.Resource {
}, false),
// Workload is not exposed in any way, so must be ignored if the resource is imported.
DiffSuppressFunc: func(k, old, new string, d *pluginsdk.ResourceData) bool {
return old == ""
if new != "" {
return false
}
return true
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
},
},

Expand Down Expand Up @@ -152,7 +155,8 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err
defer locks.UnlockByName(aliasName, SubscriptionResourceName)

workload := subscriptionAlias.Production
if workloadRaw := d.Get("workload").(string); workloadRaw != "" {
workloadRaw := d.Get("workload").(string)
if workloadRaw != "" {
workload = subscriptionAlias.Workload(workloadRaw)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ func TestAccSubscriptionResource_update(t *testing.T) {
})
}

func TestAccSubscriptionResource_devTest(t *testing.T) {
if os.Getenv("ARM_BILLING_ACCOUNT") == "" {
t.Skip("skipping tests - no billing account data provided")
}

data := acceptance.BuildTestData(t, "azurerm_subscription", "test")
r := SubscriptionResource{}

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

func (SubscriptionResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.SubscriptionAliasID(state.ID)
if err != nil {
Expand Down Expand Up @@ -134,6 +152,28 @@ resource "azurerm_subscription" "test" {
`, billingAccount, enrollmentAccount, data.RandomInteger)
}

func (SubscriptionResource) basicEnrollmentAccountDevTest(data acceptance.TestData) string {
billingAccount := os.Getenv("ARM_BILLING_ACCOUNT")
enrollmentAccount := os.Getenv("ARM_BILLING_ENROLLMENT_ACCOUNT")
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

data "azurerm_billing_enrollment_account_scope" "test" {
billing_account_name = "%s"
enrollment_account_name = "%s"
}

resource "azurerm_subscription" "test" {
alias = "testAcc-%[3]d"
subscription_name = "testAccSubscription Renamed %[3]d"
billing_scope_id = data.azurerm_billing_enrollment_account_scope.test.id
workload = "DevTest"
}
`, billingAccount, enrollmentAccount, data.RandomInteger)
}

func (r SubscriptionResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down