-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds the following data sources: - virtual hib router table - marketplace agreement
- Loading branch information
Showing
8 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
internal/services/compute/marketplace_agreement_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package compute | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
func dataSourceMarketplaceAgreement() *pluginsdk.Resource { | ||
return &pluginsdk.Resource{ | ||
Read: dataSourceMarketplaceAgreementRead, | ||
|
||
Timeouts: &pluginsdk.ResourceTimeout{ | ||
Read: pluginsdk.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*pluginsdk.Schema{ | ||
"offer": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"plan": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"publisher": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"license_text_link": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"privacy_policy_link": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMarketplaceAgreementRead(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Compute.MarketplaceAgreementsClient | ||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id := parse.NewPlanID(subscriptionId, d.Get("publisher").(string), d.Get("offer").(string), d.Get("plan").(string)) | ||
|
||
log.Printf("[DEBUG] retrieving %s", id) | ||
|
||
term, err := client.Get(ctx, id.AgreementName, id.OfferName, id.Name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(term.Response) { | ||
return fmt.Errorf("retrieving %s: %s", id, err) | ||
} | ||
} | ||
|
||
d.SetId(id.ID()) | ||
|
||
if props := term.AgreementProperties; props != nil { | ||
d.Set("license_text_link", props.LicenseTextLink) | ||
d.Set("privacy_policy_link", props.PrivacyPolicyLink) | ||
} | ||
|
||
return nil | ||
} |
39 changes: 39 additions & 0 deletions
39
internal/services/compute/marketplace_agreement_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package compute_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type MarketplaceAgreementDataSource struct{} | ||
|
||
func TestAccDataSourceMarketplaceAgreement_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_marketplace_agreement", "test") | ||
r := MarketplaceAgreementDataSource{} | ||
offer := "waf" | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(offer), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("license_text_link").Exists(), | ||
check.That(data.ResourceName).Key("privacy_policy_link").Exists(), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (MarketplaceAgreementDataSource) basic(offer string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_marketplace_agreement" "test" { | ||
publisher = "barracudanetworks" | ||
offer = "%s" | ||
plan = "hourly" | ||
} | ||
`, MarketplaceAgreementResource{}.basic(offer), offer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
internal/services/network/virtual_hub_route_table_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" | ||
networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
func dataSourceVirtualHubRouteTable() *pluginsdk.Resource { | ||
return &pluginsdk.Resource{ | ||
Read: dataSourceVirtualHubRouteTableRead, | ||
|
||
Timeouts: &pluginsdk.ResourceTimeout{ | ||
Read: pluginsdk.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { | ||
_, err := parse.HubRouteTableID(id) | ||
return err | ||
}), | ||
|
||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: networkValidate.HubRouteTableName, | ||
}, | ||
|
||
"resource_group_name": commonschema.ResourceGroupNameForDataSource(), | ||
|
||
"virtual_hub_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: networkValidate.VirtualHubName, | ||
}, | ||
|
||
"virtual_hub_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"labels": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
|
||
"route": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"destinations": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
|
||
"destinations_type": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"next_hop": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"next_hop_type": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVirtualHubRouteTableRead(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Network.HubRouteTableClient | ||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id := parse.NewHubRouteTableID(subscriptionId, d.Get("resource_group_name").(string), d.Get("virtual_hub_name").(string), d.Get("name").(string)) | ||
|
||
resp, err := client.Get(ctx, id.ResourceGroup, id.VirtualHubName, id.Name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("%s was not found", id) | ||
} | ||
return fmt.Errorf("reading %s: %+v", id, err) | ||
} | ||
|
||
d.SetId(id.ID()) | ||
|
||
d.Set("name", id.Name) | ||
d.Set("resource_group_name", id.ResourceGroup) | ||
d.Set("virtual_hub_name", id.VirtualHubName) | ||
d.Set("virtual_hub_id", parse.NewVirtualHubID(id.SubscriptionId, id.ResourceGroup, id.VirtualHubName).ID()) | ||
|
||
if props := resp.HubRouteTableProperties; props != nil { | ||
d.Set("labels", utils.FlattenStringSlice(props.Labels)) | ||
|
||
if err := d.Set("route", flattenVirtualHubRouteTableHubRoutes(props.Routes)); err != nil { | ||
return fmt.Errorf("setting `route`: %+v", err) | ||
} | ||
} | ||
return nil | ||
} |
38 changes: 38 additions & 0 deletions
38
internal/services/network/virtual_hub_route_table_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package network_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type VirtualHubRouteTableDataSource struct{} | ||
|
||
func TestAccDataSourceAzureRMVirtualHubRouteTable_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_virtual_hub_route_table", "test") | ||
r := VirtualHubRouteTableDataSource{} | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("virtual_hub_id").Exists(), | ||
check.That(data.ResourceName).Key("labels.#").Exists(), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (VirtualHubRouteTableDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_virtual_hub_route_table" "test" { | ||
name = azurerm_virtual_hub_route_table.test.name | ||
resource_group_name = azurerm_virtual_hub.test.resource_group_name | ||
virtual_hub_name = azurerm_virtual_hub.test.name | ||
} | ||
`, VirtualHubRouteTableResource{}.basic(data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
subcategory: "Compute" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_marketplace_agreement" | ||
description: |- | ||
Gets information about an existing Marketplace Agreement. | ||
--- | ||
|
||
# azurerm_marketplace_agreement | ||
|
||
Uses this data source to access information about an existing Marketplace Agreement. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_marketplace_agreement" "barracuda" { | ||
publisher = "barracudanetworks" | ||
offer = "waf" | ||
plan = "hourly" | ||
} | ||
output "azurerm_marketplace_agreement_id" { | ||
value = data.azurerm_marketplace_agreement.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `offer` - The Offer of the Marketplace Image. | ||
|
||
* `plan` - The Plan of the Marketplace Image. | ||
|
||
* `publisher` - The Publisher of the Marketplace Image. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ID of the Marketplace Agreement. | ||
|
||
## Timeouts | ||
|
||
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: | ||
|
||
* `read` - (Defaults to 5 minutes) Used when retrieving the Marketplace Agreement. |
Oops, something went wrong.