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

New data source: azurerm_subscription #285

Merged
merged 1 commit into from
Aug 30, 2017
Merged

New data source: azurerm_subscription #285

merged 1 commit into from
Aug 30, 2017

Conversation

ewbankkit
Copy link
Contributor

New data source to return information about a specific Azure subscription.
If not subscription ID is specified, the subscription ID of the current Azure Resource Manager provider is used.
Fixes #284.

@ewbankkit
Copy link
Contributor Author

ewbankkit commented Aug 29, 2017

The resources/subscriptions package was added via:

govendor fetch github.com/Azure/azure-sdk-for-go/arm/resources/[email protected]

@ewbankkit
Copy link
Contributor Author

Acceptance tests:

make testacc TEST=./azurerm TESTARGS='-run=TestAccDataSourceAzureRMSubscription_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./azurerm -v -run=TestAccDataSourceAzureRMSubscription_ -timeout 120m
=== RUN   TestAccDataSourceAzureRMSubscription_current
--- PASS: TestAccDataSourceAzureRMSubscription_current (9.59s)
=== RUN   TestAccDataSourceAzureRMSubscription_specific
--- PASS: TestAccDataSourceAzureRMSubscription_specific (8.23s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	18.380s

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ewbankkit

Thanks for this PR - I've taken a look and left a few minor comments but this generally looks good to me :)

Out of interest - would it be possible to give an example of when this Data Source would be used? Presumably this is to access information about multiple subscriptions within the same Tenant?

Thanks!

"display_name": {
Type: schema.TypeString,
Computed: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any other fields (e.g. Tenant ID?) that would make sense to be exposed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the subscription state and possible subscription policies.
I'm not adding the tenant as the tenant API only works for the "current" account.


resp, err := groupClient.Get(subscriptionId)
if err != nil {
return fmt.Errorf("Error reading subscription: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the SDK's currently masking some error messages - can we change this the formatted string to %+v to return the full error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Config: testAccDataSourceAzureRMSubscription_specificConfig(os.Getenv("ARM_SUBSCRIPTION_ID")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "subscription_id"),
testCheckAzureRMSubscriptionId(resourceName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this in favour of checking via:

resource.TestCheckResourceAttr(resourceName, "subscription_id", "{Subscription ID Value}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we can't do as suggested is that {Subscription ID Value} is obtained from the ArmClient for the running test step and this can't be done when the steps are declared (testAccProvider.Meta().(*ArmClient) is nil at this point).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, but we could instead check this against the ARM_SUBSCRIPTION_ID environment variable? It's not a blocker by any means and this otherwise LGTM :)

@ewbankkit
Copy link
Contributor Author

I'll work on the changes you suggested.
My use case is for obtaining the subscription's display name and then using it for naming various other resources but I can certainly see value in returning other information.
The underlying API returns some additional fields.

Changes after review.

Correct schema and add test steps.
@ewbankkit
Copy link
Contributor Author

Made changes after review and rebased.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ewbankkit

Thanks for pushing those updates - I've taken another look and this LGTM :)

Tests Pass:

$ acctests azurerm TestAccDataSourceAzureRMSubscription
=== RUN   TestAccDataSourceAzureRMSubscription_current
--- PASS: TestAccDataSourceAzureRMSubscription_current (8.29s)
=== RUN   TestAccDataSourceAzureRMSubscription_specific
--- PASS: TestAccDataSourceAzureRMSubscription_specific (7.36s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	15.681s

Thanks!

@tombuildsstuff tombuildsstuff merged commit 0d450a1 into hashicorp:master Aug 30, 2017
tombuildsstuff added a commit that referenced this pull request Aug 30, 2017
nicholasjackson pushed a commit to nicholasjackson/terraform-provider-azurerm that referenced this pull request Aug 31, 2017
@ewbankkit ewbankkit deleted the azurerm_subscription-data-source branch August 31, 2017 13:45
@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data source to get information about a specified Azure subscription
2 participants