-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
monitor_private_link_scope_resource_test.go
161 lines (134 loc) · 4.52 KB
/
monitor_private_link_scope_resource_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package monitor_test
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-07-01-preview/privatelinkscopesapis"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
type MonitorPrivateLinkScopeResource struct{}
func TestAccMonitorPrivateLinkScope_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_private_link_scope", "test")
r := MonitorPrivateLinkScopeResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}
func TestAccMonitorPrivateLinkScope_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_private_link_scope", "test")
r := MonitorPrivateLinkScopeResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.RequiresImportErrorStep(r.requiresImport),
})
}
func TestAccMonitorPrivateLinkScope_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_private_link_scope", "test")
r := MonitorPrivateLinkScopeResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data, "Test", "Open", "Open"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}
func TestAccMonitorPrivateLinkScope_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_private_link_scope", "test")
r := MonitorPrivateLinkScopeResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data, "Test1", "Open", "Open"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.complete(data, "Test2", "PrivateOnly", "PrivateOnly"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}
func (r MonitorPrivateLinkScopeResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := privatelinkscopesapis.ParsePrivateLinkScopeID(state.ID)
if err != nil {
return nil, err
}
resp, err := client.Monitor.PrivateLinkScopesClient.PrivateLinkScopesGet(ctx, *id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return utils.Bool(false), nil
}
return nil, fmt.Errorf("retrieving %q %+v", id, err)
}
return utils.Bool(resp.Model != nil), nil
}
func (r MonitorPrivateLinkScopeResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-pls-%d"
location = "%s"
}
`, data.RandomInteger, data.Locations.Primary)
}
func (r MonitorPrivateLinkScopeResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_monitor_private_link_scope" "test" {
name = "acctest-ampls-%d"
resource_group_name = azurerm_resource_group.test.name
}
`, r.template(data), data.RandomInteger)
}
func (r MonitorPrivateLinkScopeResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_monitor_private_link_scope" "import" {
name = azurerm_monitor_private_link_scope.test.name
resource_group_name = azurerm_monitor_private_link_scope.test.resource_group_name
ingestion_access_mode = "Open"
query_access_mode = "Open"
}
`, r.basic(data))
}
func (r MonitorPrivateLinkScopeResource) complete(data acceptance.TestData, tag string, ingestionAccessMode string, queryAccessMode string) string {
return fmt.Sprintf(`
%s
resource "azurerm_monitor_private_link_scope" "test" {
name = "acctest-AMPLS-%d"
resource_group_name = azurerm_resource_group.test.name
ingestion_access_mode = "%s"
query_access_mode = "%s"
tags = {
ENV = "%s"
}
}
`, r.template(data), data.RandomInteger, ingestionAccessMode, queryAccessMode, tag)
}