Skip to content

Commit

Permalink
self_link 4.0.0 changes (#5314) (#3783)
Browse files Browse the repository at this point in the history
* Remove several self link fields

* Add note on snapshot

* Remove uses of keyring.self_link in tests and docs

* Unused var

* Remove references in tests

* Change kms key ring data source id format, add note to upgrade guide

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 27, 2021
1 parent 8a448e7 commit b8c7f9b
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 82 deletions.
9 changes: 9 additions & 0 deletions .changelog/5314.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:breaking-change
pubsub: removed `path` field from `google_pubsub_subscription`
```
```release-note:breaking-change
kms: removed `self_link` field from `google_kms_crypto_key` and `google_kms_key_ring`
```
```release-note:breaking-change
compute: removed `source_disk_link` field from `google_compute_snapshot`
```
2 changes: 1 addition & 1 deletion google-beta/data_source_google_kms_crypto_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAccDataSourceGoogleKmsCryptoKey_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleKmsCryptoKey_basic(kms.KeyRing.Name, cryptoKeyId),
Check: resource.TestMatchResourceAttr("data.google_kms_crypto_key.kms_crypto_key", "self_link", regexp.MustCompile(kms.CryptoKey.Name)),
Check: resource.TestMatchResourceAttr("data.google_kms_crypto_key.kms_crypto_key", "id", regexp.MustCompile(kms.CryptoKey.Name)),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion google-beta/data_source_google_kms_key_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func dataSourceGoogleKmsKeyRingRead(d *schema.ResourceData, meta interface{}) er
Location: d.Get("location").(string),
Project: project,
}
d.SetId(keyRingId.terraformId())
d.SetId(keyRingId.keyRingId())

return resourceKMSKeyRingRead(d, meta)
}
2 changes: 1 addition & 1 deletion google-beta/data_source_google_kms_key_ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccDataSourceGoogleKmsKeyRing_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleKmsKeyRing_basic(keyRingId),
Check: resource.TestMatchResourceAttr("data.google_kms_key_ring.kms_key_ring", "self_link", regexp.MustCompile(kms.KeyRing.Name)),
Check: resource.TestMatchResourceAttr("data.google_kms_key_ring.kms_key_ring", "id", regexp.MustCompile(kms.KeyRing.Name)),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
purpose = "ASYMMETRIC_DECRYPT"
version_template {
algorithm = "RSA_DECRYPT_OAEP_4096_SHA256"
Expand Down
2 changes: 1 addition & 1 deletion google-beta/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ resource "google_kms_key_ring" "project-2-keyring" {
resource "google_kms_crypto_key" "project-2-key" {
provider = google.project-1-token
name = "%s"
key_ring = google_kms_key_ring.project-2-keyring.self_link
key_ring = google_kms_key_ring.project-2-keyring.id
}
data "google_kms_secret_ciphertext" "project-2-ciphertext" {
Expand Down
8 changes: 0 additions & 8 deletions google-beta/resource_compute_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ snapshot using a customer-supplied encryption key.`,
storage, this number is expected to change with snapshot
creation/deletion.`,
},
"source_disk_link": {
Type: schema.TypeString,
Computed: true,
Deprecated: "Deprecated in favor of source_disk, which contains a compatible value. This field will be removed in the next major release of the provider.",
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -843,8 +838,5 @@ func resourceComputeSnapshotDecoder(d *schema.ResourceData, meta interface{}, re
res["sourceDiskEncryptionKey"] = transformed
}

if err := d.Set("source_disk_link", ConvertSelfLinkToV1(res["sourceDisk"].(string))); err != nil {
return nil, fmt.Errorf("Error setting source_disk_link: %s", err)
}
return res, nil
}
8 changes: 4 additions & 4 deletions google-beta/resource_container_analysis_occurrence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ data "google_kms_key_ring" "keyring" {
data "google_kms_crypto_key" "crypto-key" {
name = "%{crypto_key}"
key_ring = data.google_kms_key_ring.keyring.self_link
key_ring = data.google_kms_key_ring.keyring.id
}
data "google_kms_crypto_key_version" "version" {
crypto_key = data.google_kms_crypto_key.crypto-key.self_link
crypto_key = data.google_kms_crypto_key.crypto-key.id
}
resource "google_container_analysis_occurrence" "occurrence" {
Expand Down Expand Up @@ -240,12 +240,12 @@ data "google_kms_key_ring" "keyring" {
data "google_kms_crypto_key" "crypto-key1" {
name = "%{key1}"
key_ring = data.google_kms_key_ring.keyring.self_link
key_ring = data.google_kms_key_ring.keyring.id
}
data "google_kms_crypto_key" "crypto-key2" {
name = "%{key2}"
key_ring = data.google_kms_key_ring.keyring.self_link
key_ring = data.google_kms_key_ring.keyring.id
}
data "google_kms_crypto_key_version" "version-key1" {
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3288,7 +3288,7 @@ resource "google_kms_key_ring" "keyring" {
resource "google_kms_crypto_key" "example-key" {
name = "%s-kms-key"
key_ring = google_kms_key_ring.keyring.self_link
key_ring = google_kms_key_ring.keyring.id
rotation_period = "100000s"
}
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ resource "google_kms_key_ring" "keyring" {
resource "google_kms_crypto_key" "example-key" {
name = "%s-kms-key"
key_ring = google_kms_key_ring.keyring.self_link
key_ring = google_kms_key_ring.keyring.id
rotation_period = "100000s"
}
Expand Down
6 changes: 1 addition & 5 deletions google-beta/resource_healthcare_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,10 @@ func expandHealthcareDatasetTimeZone(v interface{}, d TerraformResourceData, con
}

func resourceHealthcareDatasetDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
6 changes: 1 addition & 5 deletions google-beta/resource_healthcare_dicom_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,10 @@ func expandHealthcareDicomStoreStreamConfigsBigqueryDestinationTableUri(v interf
}

func resourceHealthcareDicomStoreDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
6 changes: 1 addition & 5 deletions google-beta/resource_healthcare_fhir_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,10 @@ func expandHealthcareFhirStoreStreamConfigsBigqueryDestinationSchemaConfigRecurs
}

func resourceHealthcareFhirStoreDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
6 changes: 1 addition & 5 deletions google-beta/resource_healthcare_hl7_v2_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,10 @@ func expandHealthcareHl7V2StoreNotificationConfigPubsubTopic(v interface{}, d Te
}

func resourceHealthcareHl7V2StoreDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
12 changes: 1 addition & 11 deletions google-beta/resource_kms_crypto_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ See the [algorithm reference](https://cloud.google.com/kms/docs/reference/rest/v
},
},
},
"self_link": {
Type: schema.TypeString,
Computed: true,
Deprecated: "Deprecated in favor of id, which contains an identical value. This field will be removed in the next major release of the provider.",
Description: "The self link of the created KeyRing in the format projects/{project}/locations/{location}/keyRings/{name}.",
},
},
UseJSONNumber: true,
}
Expand Down Expand Up @@ -577,14 +571,10 @@ func resourceKMSCryptoKeyUpdateEncoder(d *schema.ResourceData, meta interface{},
}

func resourceKMSCryptoKeyDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
Expand Down
12 changes: 6 additions & 6 deletions google-beta/resource_kms_crypto_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
labels = {
key = "value"
}
Expand Down Expand Up @@ -487,7 +487,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
rotation_period = "%s"
}
`, projectId, projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, rotationPeriod)
Expand Down Expand Up @@ -515,7 +515,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
}
`, projectId, projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName)
}
Expand All @@ -542,7 +542,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
purpose = "ASYMMETRIC_SIGN"
version_template {
Expand Down Expand Up @@ -596,7 +596,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
labels = {
key = "value"
}
Expand Down Expand Up @@ -627,7 +627,7 @@ resource "google_kms_key_ring" "key_ring" {
resource "google_kms_crypto_key" "crypto_key" {
name = "%s"
key_ring = google_kms_key_ring.key_ring.self_link
key_ring = google_kms_key_ring.key_ring.id
labels = {
key = "value"
}
Expand Down
12 changes: 1 addition & 11 deletions google-beta/resource_kms_key_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ A full list of valid locations can be found by running 'gcloud kms locations lis
ForceNew: true,
Description: `The resource name for the KeyRing.`,
},
"self_link": {
Type: schema.TypeString,
Computed: true,
Deprecated: "Deprecated in favor of id, which contains an identical value. This field will be removed in the next major release of the provider.",
Description: "The self link of the created KeyRing in the format projects/{project}/locations/{location}/keyRings/{name}.",
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -230,14 +224,10 @@ func resourceKMSKeyRingEncoder(d *schema.ResourceData, meta interface{}, obj map
}

func resourceKMSKeyRingDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
1 change: 0 additions & 1 deletion google-beta/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestAccPubsubSubscription_update(t *testing.T) {

topic := fmt.Sprintf("tf-test-topic-%s", randString(t, 10))
subscriptionShort := fmt.Sprintf("tf-test-sub-%s", randString(t, 10))
subscriptionLong := fmt.Sprintf("projects/%s/subscriptions/%s", getTestProjectFromEnv(), subscriptionShort)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
6 changes: 1 addition & 5 deletions google-beta/resource_vpc_access_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,10 @@ func resourceVPCAccessConnectorEncoder(d *schema.ResourceData, meta interface{},
}

func resourceVPCAccessConnectorDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Take the returned long form of the name and use it as `self_link`.
// Then modify the name to be the user specified form.
// Modify the name to be the user specified form.
// We can't just ignore_read on `name` as the linter will
// complain that the returned `res` is never used afterwards.
// Some field needs to be actually set, and we chose `name`.
if err := d.Set("self_link", res["name"].(string)); err != nil {
return nil, fmt.Errorf("Error setting self_link: %s", err)
}
res["name"] = d.Get("name").(string)
return res, nil
}
2 changes: 1 addition & 1 deletion website/docs/d/kms_crypto_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data "google_kms_key_ring" "my_key_ring" {
data "google_kms_crypto_key" "my_crypto_key" {
name = "my-crypto-key"
key_ring = data.google_kms_key_ring.my_key_ring.self_link
key_ring = data.google_kms_key_ring.my_key_ring.id
}
```

Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/kms_secret.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "google_kms_key_ring" "my_key_ring" {
resource "google_kms_crypto_key" "my_crypto_key" {
name = "my-crypto-key"
key_ring = google_kms_key_ring.my_key_ring.self_link
key_ring = google_kms_key_ring.my_key_ring.id
}
```

Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/kms_secret_asymmetric.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "google_kms_key_ring" "my_key_ring" {
resource "google_kms_crypto_key" "my_crypto_key" {
name = "my-crypto-key"
key_ring = google_kms_key_ring.my_key_ring.self_link
key_ring = google_kms_key_ring.my_key_ring.id
purpose = "ASYMMETRIC_DECRYPT"
version_template {
algorithm = "RSA_DECRYPT_OAEP_4096_SHA256"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/kms_secret_ciphertext.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ resource "google_kms_key_ring" "my_key_ring" {
resource "google_kms_crypto_key" "my_crypto_key" {
name = "my-crypto-key"
key_ring = google_kms_key_ring.my_key_ring.self_link
key_ring = google_kms_key_ring.my_key_ring.id
}
```

Expand Down
26 changes: 26 additions & 0 deletions website/docs/guides/version_4_upgrade.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,32 @@ This field was incorrectly included in the GA `google` provider in past releases
In order to continue to use the feature, add `provider = google-beta` to your
resource definition.

## Resource: `google_compute_snapshot`

### `source_disk_link` is now removed

Removed in favor of `source_disk`.

## Resource: `google_kms_crypto_key`

### `self_link` is now removed

Removed in favor of `id`.

## Resource: `google_kms_key_ring`

### `self_link` is now removed

Removed in favor of `id`.

## Datasource: `google_kms_key_ring`

### `id` now matches the `google_kms_key_ring` id format

The format has changed to better match the resource's ID format.

Interpolations based on the `id` of the datasource may require updates.

## Resource: `google_data_loss_prevention_trigger`

### Exactly one of `inspect_job.0.storage_config.0.cloud_storage_options.0.file_set.0.url` or `inspect_job.0.storage_config.0.cloud_storage_options.0.file_set.0.regex_file_set` is required
Expand Down
Loading

0 comments on commit b8c7f9b

Please sign in to comment.