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/Resource: azurerm_cdn_frontdoor_origin_group / New Resource: azurerm_cdn_frontdoor_origin #17089

Merged
merged 16 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 3.14.0 (Unreleased)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you will have to roll back the merge main

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed.

## 3.15.0 (Unreleased)

FEATURES:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ resource "azurerm_resource_group" "test" {

resource "azurerm_cdn_frontdoor_profile" "test" {
name = "acctest-cdnfdprofile-%d"
sku_name = "Standard_AzureFrontDoor"
resource_group_name = azurerm_resource_group.test.name
sku_name = "Standard_AzureFrontDoor"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
144 changes: 144 additions & 0 deletions internal/services/cdn/cdn_frontdoor_origin_group_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package cdn

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/cdn/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/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 dataSourceCdnFrontDoorOriginGroup() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceCdnFrontDoorOriginGroupRead,

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.FrontDoorOriginGroupName,
},

"profile_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.FrontDoorName,
},

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

// Computed
"cdn_frontdoor_profile_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"health_probe": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"interval_in_seconds": {
Type: pluginsdk.TypeInt,
Computed: true,
},
"path": {
Type: pluginsdk.TypeString,
Computed: true,
},
"protocol": {
Type: pluginsdk.TypeString,
Computed: true,
},

"request_type": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"load_balancing": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"additional_latency_in_milliseconds": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"sample_size": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"successful_samples_required": {
Type: pluginsdk.TypeInt,
Computed: true,
},
},
},
},

"restore_traffic_time_to_healed_or_new_endpoint_in_minutes": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"session_affinity_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
},
}
}

func dataSourceCdnFrontDoorOriginGroupRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Cdn.FrontDoorOriginGroupsClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewFrontDoorOriginGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("profile_name").(string), d.Get("name").(string))
resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName, id.OriginGroupName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("retrieving %s: %+v", id, err)
}

d.SetId(id.ID())
d.Set("name", id.OriginGroupName)
d.Set("profile_name", id.ProfileName)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("cdn_frontdoor_profile_id", parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName).ID())

if props := resp.AFDOriginGroupProperties; props != nil {
if err := d.Set("health_probe", flattenCdnFrontDoorOriginGroupHealthProbeParameters(props.HealthProbeSettings)); err != nil {
return fmt.Errorf("setting `health_probe`: %+v", err)
}

if err := d.Set("load_balancing", flattenCdnFrontDoorOriginGroupLoadBalancingSettingsParameters(props.LoadBalancingSettings)); err != nil {
return fmt.Errorf("setting `load_balancing`: %+v", err)
}

d.Set("session_affinity_enabled", flattenEnabledBool(props.SessionAffinityState))
d.Set("restore_traffic_time_to_healed_or_new_endpoint_in_minutes", props.TrafficRestorationTimeToHealedOrNewEndpointsInMinutes)
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cdn_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type CdnFrontDoorOriginGroupDataSource struct{}

func TestAccCdnFrontDoorOriginGroupDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_origin_group", "test")
d := CdnFrontDoorOriginGroupDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("cdn_frontdoor_profile_id").MatchesOtherKey(check.That("azurerm_cdn_frontdoor_profile.test").Key("id")),
),
},
})
}

func (CdnFrontDoorOriginGroupDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_cdn_frontdoor_origin_group" "test" {
name = azurerm_cdn_frontdoor_origin_group.test.name
profile_name = azurerm_cdn_frontdoor_profile.test.name
resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name
}
`, CdnFrontDoorOriginGroupResource{}.complete(data))
}
Loading