diff --git a/azurerm/config.go b/azurerm/config.go index 499374a2dac9..d6eef74e042f 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -22,6 +22,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/network" "github.com/Azure/azure-sdk-for-go/arm/redis" "github.com/Azure/azure-sdk-for-go/arm/resources/resources" + "github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions" "github.com/Azure/azure-sdk-for-go/arm/scheduler" "github.com/Azure/azure-sdk-for-go/arm/search" "github.com/Azure/azure-sdk-for-go/arm/servicebus" @@ -94,6 +95,8 @@ type ArmClient struct { tagsClient resources.TagsClient resourceFindClient resources.GroupClient + subscriptionsGroupClient subscriptions.GroupClient + jobsClient scheduler.JobsClient jobsCollectionsClient scheduler.JobCollectionsClient @@ -446,6 +449,12 @@ func (c *Config) getArmClient() (*ArmClient, error) { rf.Sender = autorest.CreateSender(withRequestLogging()) client.resourceFindClient = rf + subgc := subscriptions.NewGroupClientWithBaseURI(endpoint) + setUserAgent(&subgc.Client) + subgc.Authorizer = auth + subgc.Sender = autorest.CreateSender(withRequestLogging()) + client.subscriptionsGroupClient = subgc + jc := scheduler.NewJobsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&jc.Client) jc.Authorizer = auth diff --git a/azurerm/data_source_subscription.go b/azurerm/data_source_subscription.go new file mode 100644 index 000000000000..62a9d418371f --- /dev/null +++ b/azurerm/data_source_subscription.go @@ -0,0 +1,73 @@ +package azurerm + +import ( + "fmt" + + "github.com/hashicorp/terraform/helper/schema" +) + +func dataSourceArmSubscription() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmSubscriptionRead, + Schema: map[string]*schema.Schema{ + + "subscription_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "display_name": { + Type: schema.TypeString, + Computed: true, + }, + + "state": { + Type: schema.TypeString, + Computed: true, + }, + + "location_placement_id": { + Type: schema.TypeString, + Computed: true, + }, + + "quota_id": { + Type: schema.TypeString, + Computed: true, + }, + + "spending_limit": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceArmSubscriptionRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient) + groupClient := client.subscriptionsGroupClient + + subscriptionId := d.Get("subscription_id").(string) + if subscriptionId == "" { + subscriptionId = client.subscriptionId + } + + resp, err := groupClient.Get(subscriptionId) + if err != nil { + return fmt.Errorf("Error reading subscription: %+v", err) + } + + d.SetId(*resp.ID) + d.Set("subscription_id", resp.SubscriptionID) + d.Set("display_name", resp.DisplayName) + d.Set("state", resp.State) + if resp.SubscriptionPolicies != nil { + d.Set("location_placement_id", resp.SubscriptionPolicies.LocationPlacementID) + d.Set("quota_id", resp.SubscriptionPolicies.QuotaID) + d.Set("spending_limit", resp.SubscriptionPolicies.SpendingLimit) + } + + return nil +} diff --git a/azurerm/data_source_subscription_test.go b/azurerm/data_source_subscription_test.go new file mode 100644 index 000000000000..3a98473a4839 --- /dev/null +++ b/azurerm/data_source_subscription_test.go @@ -0,0 +1,83 @@ +package azurerm + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccDataSourceAzureRMSubscription_current(t *testing.T) { + resourceName := "data.azurerm_subscription.current" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMSubscription_currentConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), + testCheckAzureRMSubscriptionId(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "display_name"), + resource.TestCheckResourceAttr(resourceName, "state", "Enabled"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMSubscription_specific(t *testing.T) { + resourceName := "data.azurerm_subscription.specific" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMSubscription_specificConfig(os.Getenv("ARM_SUBSCRIPTION_ID")), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), + testCheckAzureRMSubscriptionId(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "display_name"), + resource.TestCheckResourceAttrSet(resourceName, "location_placement_id"), + resource.TestCheckResourceAttrSet(resourceName, "quota_id"), + resource.TestCheckResourceAttrSet(resourceName, "spending_limit"), + ), + }, + }, + }) +} + +func testCheckAzureRMSubscriptionId(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + attributeName := "subscription_id" + subscriptionId := rs.Primary.Attributes[attributeName] + client := testAccProvider.Meta().(*ArmClient) + if subscriptionId != client.subscriptionId { + return fmt.Errorf("%s: Attribute '%s' expected \"%s\", got \"%s\"", name, attributeName, client.subscriptionId, subscriptionId) + } + + return nil + } +} + +const testAccDataSourceAzureRMSubscription_currentConfig = ` +data "azurerm_subscription" "current" {} +` + +func testAccDataSourceAzureRMSubscription_specificConfig(subscriptionId string) string { + return fmt.Sprintf(` + data "azurerm_subscription" "specific" { + subscription_id = "%s" + } + `, subscriptionId) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 0bf477ab774d..3fa362c062a0 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -63,6 +63,7 @@ func Provider() terraform.ResourceProvider { "azurerm_resource_group": dataSourceArmResourceGroup(), "azurerm_public_ip": dataSourceArmPublicIP(), "azurerm_managed_disk": dataSourceArmManagedDisk(), + "azurerm_subscription": dataSourceArmSubscription(), }, ResourcesMap: map[string]*schema.Resource{ diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/client.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/client.go new file mode 100755 index 000000000000..31a6090910e4 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/client.go @@ -0,0 +1,54 @@ +// Package subscriptions implements the Azure ARM Subscriptions service API +// version 2016-06-01. +// +// All resource groups and resources exist within subscriptions. These +// operation enable you get information about your subscriptions and tenants. A +// tenant is a dedicated instance of Azure Active Directory (Azure AD) for your +// organization. +package subscriptions + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Subscriptions + DefaultBaseURI = "https://management.azure.com" +) + +// ManagementClient is the base client for Subscriptions. +type ManagementClient struct { + autorest.Client + BaseURI string +} + +// New creates an instance of the ManagementClient client. +func New() ManagementClient { + return NewWithBaseURI(DefaultBaseURI) +} + +// NewWithBaseURI creates an instance of the ManagementClient client. +func NewWithBaseURI(baseURI string) ManagementClient { + return ManagementClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/models.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/models.go new file mode 100755 index 000000000000..e2cf1743fe76 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/models.go @@ -0,0 +1,132 @@ +package subscriptions + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/to" + "net/http" +) + +// SpendingLimit enumerates the values for spending limit. +type SpendingLimit string + +const ( + // CurrentPeriodOff specifies the current period off state for spending + // limit. + CurrentPeriodOff SpendingLimit = "CurrentPeriodOff" + // Off specifies the off state for spending limit. + Off SpendingLimit = "Off" + // On specifies the on state for spending limit. + On SpendingLimit = "On" +) + +// State enumerates the values for state. +type State string + +const ( + // Deleted specifies the deleted state for state. + Deleted State = "Deleted" + // Disabled specifies the disabled state for state. + Disabled State = "Disabled" + // Enabled specifies the enabled state for state. + Enabled State = "Enabled" + // PastDue specifies the past due state for state. + PastDue State = "PastDue" + // Warned specifies the warned state for state. + Warned State = "Warned" +) + +// ListResult is subscription list operation response. +type ListResult struct { + autorest.Response `json:"-"` + Value *[]Subscription `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ListResultPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client ListResult) ListResultPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// Location is location information. +type Location struct { + ID *string `json:"id,omitempty"` + SubscriptionID *string `json:"subscriptionId,omitempty"` + Name *string `json:"name,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Latitude *string `json:"latitude,omitempty"` + Longitude *string `json:"longitude,omitempty"` +} + +// LocationListResult is location list operation response. +type LocationListResult struct { + autorest.Response `json:"-"` + Value *[]Location `json:"value,omitempty"` +} + +// Policies is subscription policies. +type Policies struct { + LocationPlacementID *string `json:"locationPlacementId,omitempty"` + QuotaID *string `json:"quotaId,omitempty"` + SpendingLimit SpendingLimit `json:"spendingLimit,omitempty"` +} + +// Subscription is subscription information. +type Subscription struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + SubscriptionID *string `json:"subscriptionId,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + State State `json:"state,omitempty"` + SubscriptionPolicies *Policies `json:"subscriptionPolicies,omitempty"` + AuthorizationSource *string `json:"authorizationSource,omitempty"` +} + +// TenantIDDescription is tenant Id information. +type TenantIDDescription struct { + ID *string `json:"id,omitempty"` + TenantID *string `json:"tenantId,omitempty"` +} + +// TenantListResult is tenant Ids information. +type TenantListResult struct { + autorest.Response `json:"-"` + Value *[]TenantIDDescription `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// TenantListResultPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client TenantListResult) TenantListResultPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/subscriptionsgroup.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/subscriptionsgroup.go new file mode 100755 index 000000000000..b8042f65df44 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/subscriptionsgroup.go @@ -0,0 +1,252 @@ +package subscriptions + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// GroupClient is the all resource groups and resources exist within +// subscriptions. These operation enable you get information about your +// subscriptions and tenants. A tenant is a dedicated instance of Azure Active +// Directory (Azure AD) for your organization. +type GroupClient struct { + ManagementClient +} + +// NewGroupClient creates an instance of the GroupClient client. +func NewGroupClient() GroupClient { + return NewGroupClientWithBaseURI(DefaultBaseURI) +} + +// NewGroupClientWithBaseURI creates an instance of the GroupClient client. +func NewGroupClientWithBaseURI(baseURI string) GroupClient { + return GroupClient{NewWithBaseURI(baseURI)} +} + +// Get gets details about a specified subscription. +// +// subscriptionID is the ID of the target subscription. +func (client GroupClient) Get(subscriptionID string) (result Subscription, err error) { + req, err := client.GetPreparer(subscriptionID) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client GroupClient) GetPreparer(subscriptionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2016-06-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client GroupClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client GroupClient) GetResponder(resp *http.Response) (result Subscription, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List gets all subscriptions for a tenant. +func (client GroupClient) List() (result ListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client GroupClient) ListPreparer() (*http.Request, error) { + const APIVersion = "2016-06-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/subscriptions"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client GroupClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client GroupClient) ListResponder(resp *http.Response) (result ListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client GroupClient) ListNextResults(lastResults ListResult) (result ListResult, err error) { + req, err := lastResults.ListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "subscriptions.GroupClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "subscriptions.GroupClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "List", resp, "Failure responding to next results request") + } + + return +} + +// ListLocations this operation provides all the locations that are available +// for resource providers; however, each resource provider may support a subset +// of this list. +// +// subscriptionID is the ID of the target subscription. +func (client GroupClient) ListLocations(subscriptionID string) (result LocationListResult, err error) { + req, err := client.ListLocationsPreparer(subscriptionID) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "ListLocations", nil, "Failure preparing request") + return + } + + resp, err := client.ListLocationsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "ListLocations", resp, "Failure sending request") + return + } + + result, err = client.ListLocationsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.GroupClient", "ListLocations", resp, "Failure responding to request") + } + + return +} + +// ListLocationsPreparer prepares the ListLocations request. +func (client GroupClient) ListLocationsPreparer(subscriptionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2016-06-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/locations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListLocationsSender sends the ListLocations request. The method will close the +// http.Response Body if it receives an error. +func (client GroupClient) ListLocationsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListLocationsResponder handles the response to the ListLocations request. The method always +// closes the http.Response Body. +func (client GroupClient) ListLocationsResponder(resp *http.Response) (result LocationListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/tenants.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/tenants.go new file mode 100755 index 000000000000..35b2cd26daf1 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/tenants.go @@ -0,0 +1,124 @@ +package subscriptions + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// TenantsClient is the all resource groups and resources exist within +// subscriptions. These operation enable you get information about your +// subscriptions and tenants. A tenant is a dedicated instance of Azure Active +// Directory (Azure AD) for your organization. +type TenantsClient struct { + ManagementClient +} + +// NewTenantsClient creates an instance of the TenantsClient client. +func NewTenantsClient() TenantsClient { + return NewTenantsClientWithBaseURI(DefaultBaseURI) +} + +// NewTenantsClientWithBaseURI creates an instance of the TenantsClient client. +func NewTenantsClientWithBaseURI(baseURI string) TenantsClient { + return TenantsClient{NewWithBaseURI(baseURI)} +} + +// List gets the tenants for your account. +func (client TenantsClient) List() (result TenantListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.TenantsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "subscriptions.TenantsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.TenantsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client TenantsClient) ListPreparer() (*http.Request, error) { + const APIVersion = "2016-06-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/tenants"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client TenantsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client TenantsClient) ListResponder(resp *http.Response) (result TenantListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client TenantsClient) ListNextResults(lastResults TenantListResult) (result TenantListResult, err error) { + req, err := lastResults.TenantListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "subscriptions.TenantsClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "subscriptions.TenantsClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.TenantsClient", "List", resp, "Failure responding to next results request") + } + + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/version.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/version.go new file mode 100755 index 000000000000..20bc2efced66 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions/version.go @@ -0,0 +1,28 @@ +package subscriptions + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.2.2.0 +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/v10.3.0-beta arm-subscriptions/2016-06-01" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return "v10.3.0-beta" +} diff --git a/vendor/vendor.json b/vendor/vendor.json index d5b7c61cab1a..4ba0ffe2f94b 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -122,6 +122,14 @@ "version": "=v10.3.0-beta", "versionExact": "v10.3.0-beta" }, + { + "checksumSHA1": "oi+hcenC7nVFHiFKXzOOqjcDMDg=", + "path": "github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions", + "revision": "57db66900881e9fd21fd041a9d013514700ecab3", + "revisionTime": "2017-08-18T20:19:01Z", + "version": "v10.3.0-beta", + "versionExact": "v10.3.0-beta" + }, { "checksumSHA1": "EMCPf+TJK2GeUHGXbC2vVgfyfhY=", "path": "github.com/Azure/azure-sdk-for-go/arm/scheduler", diff --git a/website/azurerm.erb b/website/azurerm.erb index e39393b05092..0c5f79ef7612 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -30,6 +30,10 @@ azurerm_resource_group +