Skip to content

Commit 6f5f895

Browse files
authored
azurerm_key_vault_certificate_contacts - Update contact to Required in 5.0 (#30461)
1 parent a060c6c commit 6f5f895

File tree

4 files changed

+30
-54
lines changed

4 files changed

+30
-54
lines changed

internal/services/keyvault/key_vault_certificate_contacts_resource.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1515
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
16+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
1617
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
1718
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
1819
"github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse"
@@ -43,7 +44,7 @@ func (r KeyVaultCertificateContactsResource) Arguments() map[string]*pluginsdk.S
4344

4445
"contact": {
4546
Type: pluginsdk.TypeSet,
46-
Optional: true,
47+
Required: true,
4748
Elem: &pluginsdk.Resource{
4849
Schema: map[string]*pluginsdk.Schema{
4950
"email": {
@@ -68,6 +69,11 @@ func (r KeyVaultCertificateContactsResource) Arguments() map[string]*pluginsdk.S
6869
},
6970
}
7071

72+
if !features.FivePointOh() {
73+
schema["contact"].Required = false
74+
schema["contact"].Optional = true
75+
}
76+
7177
return schema
7278
}
7379

@@ -132,9 +138,15 @@ func (r KeyVaultCertificateContactsResource) Create() sdk.ResourceFunc {
132138
ContactList: expandKeyVaultCertificateContactsContact(state.Contact),
133139
}
134140

135-
if len(*contacts.ContactList) == 0 {
136-
if _, err := client.DeleteCertificateContacts(ctx, id.KeyVaultBaseUrl); err != nil {
137-
return fmt.Errorf("removing Key Vault Certificate Contacts %s: %+v", id, err)
141+
if !features.FivePointOh() {
142+
if len(*contacts.ContactList) == 0 {
143+
if _, err := client.DeleteCertificateContacts(ctx, id.KeyVaultBaseUrl); err != nil {
144+
return fmt.Errorf("removing Key Vault Certificate Contacts %s: %+v", id, err)
145+
}
146+
} else {
147+
if _, err := client.SetCertificateContacts(ctx, *keyVaultBaseUri, contacts); err != nil {
148+
return fmt.Errorf("creating Key Vault Certificate Contacts %s: %+v", id, err)
149+
}
138150
}
139151
} else {
140152
if _, err := client.SetCertificateContacts(ctx, *keyVaultBaseUri, contacts); err != nil {
@@ -222,9 +234,15 @@ func (r KeyVaultCertificateContactsResource) Update() sdk.ResourceFunc {
222234
existing.ContactList = expandKeyVaultCertificateContactsContact(state.Contact)
223235
}
224236

225-
if len(*existing.ContactList) == 0 {
226-
if _, err := client.DeleteCertificateContacts(ctx, id.KeyVaultBaseUrl); err != nil {
227-
return fmt.Errorf("removing Key Vault Certificate Contacts %s: %+v", id, err)
237+
if !features.FivePointOh() {
238+
if len(*existing.ContactList) == 0 {
239+
if _, err := client.DeleteCertificateContacts(ctx, id.KeyVaultBaseUrl); err != nil {
240+
return fmt.Errorf("removing Key Vault Certificate Contacts %s: %+v", id, err)
241+
}
242+
} else {
243+
if _, err := client.SetCertificateContacts(ctx, id.KeyVaultBaseUrl, existing); err != nil {
244+
return fmt.Errorf("updating Key Vault Certificate Contacts %s: %+v", id, err)
245+
}
228246
}
229247
} else {
230248
if _, err := client.SetCertificateContacts(ctx, id.KeyVaultBaseUrl, existing); err != nil {

internal/services/keyvault/key_vault_certificate_contacts_resource_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -102,37 +102,6 @@ func TestAccKeyVaultCertificateContacts_nonExistentVault(t *testing.T) {
102102
})
103103
}
104104

105-
func TestAccKeyVaultCertificateContacts_remove(t *testing.T) {
106-
data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate_contacts", "test")
107-
r := KeyVaultCertificateContactsResource{}
108-
109-
data.ResourceTest(t, r, []acceptance.TestStep{
110-
{
111-
Config: r.basic(data),
112-
Check: acceptance.ComposeTestCheckFunc(
113-
check.That(data.ResourceName).ExistsInAzure(r),
114-
),
115-
},
116-
data.ImportStep(),
117-
{
118-
Config: r.remove(data),
119-
Check: acceptance.ComposeTestCheckFunc(
120-
check.That(data.ResourceName).ExistsInAzure(r),
121-
check.That(data.ResourceName).Key("contact").IsEmpty(),
122-
),
123-
},
124-
data.ImportStep(),
125-
{
126-
Config: r.basic(data),
127-
Check: acceptance.ComposeTestCheckFunc(
128-
check.That(data.ResourceName).ExistsInAzure(r),
129-
check.That(data.ResourceName).Key("contact").IsNotEmpty(),
130-
),
131-
},
132-
data.ImportStep(),
133-
})
134-
}
135-
136105
func (r KeyVaultCertificateContactsResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
137106
id, err := parse.CertificateContactsID(state.ID)
138107
if err != nil {
@@ -280,18 +249,3 @@ resource "azurerm_key_vault_access_policy" "test" {
280249
}
281250
`, data.Locations.Primary, data.RandomInteger, data.RandomString)
282251
}
283-
284-
func (r KeyVaultCertificateContactsResource) remove(data acceptance.TestData) string {
285-
template := r.template(data)
286-
return fmt.Sprintf(`
287-
%s
288-
289-
resource "azurerm_key_vault_certificate_contacts" "test" {
290-
key_vault_id = azurerm_key_vault.test.id
291-
292-
depends_on = [
293-
azurerm_key_vault_access_policy.test
294-
]
295-
}
296-
`, template)
297-
}

website/docs/5.0-upgrade-guide.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ Please follow the format in the example below for listing breaking changes in re
389389
* The deprecated `contact` property has been removed as it is no longer supported by the resource.
390390
* The deprecated `enable_rbac_authorization` property has been removed in favour of the `rbac_authorization_enabled` property.
391391

392+
### `azurerm_key_vault_certificate_contacts`
393+
394+
* The `contact` property is now Required.
395+
392396
### `azurerm_kubernetes_cluster`
393397

394398
* The deprecated `default_node_pool.linux_os_config.transparent_huge_page_enabled` property has been removed in favour of the `default_node_pool.linux_os_config.transparent_huge_page` property.

website/docs/r/key_vault_certificate_contacts.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The following arguments are supported:
7272

7373
* `key_vault_id` - (Required) The ID of the Key Vault. Changing this forces a new resource to be created.
7474

75-
* `contact` - (Optional) One or more `contact` blocks as defined below.
75+
* `contact` - (Required) One or more `contact` blocks as defined below.
7676

7777
---
7878

0 commit comments

Comments
 (0)