Skip to content

Commit 3d08cd0

Browse files
committed
Review by @paddyforan: Set attributes returned by API
1 parent 731fcea commit 3d08cd0

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

builtin/providers/google/resource_compute_snapshot.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,19 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error
147147
}
148148

149149
d.Set("self_link", snapshot.SelfLink)
150+
150151
if snapshot.SnapshotEncryptionKey != nil && snapshot.SnapshotEncryptionKey.Sha256 != "" {
151152
d.Set("snapshot_encryption_key_sha256", snapshot.SnapshotEncryptionKey.Sha256)
152153
}
153154

155+
if snapshot.SourceDiskEncryptionKey != nil && snapshot.SourceDiskEncryptionKey.Sha256 != "" {
156+
d.Set("source_disk_encryption_key_sha256", snapshot.SourceDiskEncryptionKey.Sha256)
157+
}
158+
159+
d.Set("source_disk_id", snapshot.SourceDiskId)
160+
161+
d.Set("source_disk", snapshot.SourceDisk)
162+
154163
return nil
155164
}
156165

builtin/providers/google/resource_compute_snapshot_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,61 @@ func testAccCheckComputeSnapshotExists(n string, snapshot *compute.Snapshot) res
9292
}
9393

9494
if found.Name != rs.Primary.ID {
95-
return fmt.Errorf("Snapshot not found")
95+
return fmt.Errorf("Snapshot %s not found", n)
96+
}
97+
98+
attr := rs.Primary.Attributes["snapshot_encryption_key_sha256"]
99+
if found.SnapshotEncryptionKey != nil && found.SnapshotEncryptionKey.Sha256 != attr {
100+
return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v",
101+
n, attr, found.SnapshotEncryptionKey.Sha256)
102+
} else if found.SnapshotEncryptionKey == nil && attr != "" {
103+
return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v",
104+
n, attr, found.SnapshotEncryptionKey)
105+
}
106+
107+
attr = rs.Primary.Attributes["snapshot_encryption_key_raw"]
108+
if found.SnapshotEncryptionKey != nil && found.SnapshotEncryptionKey.RawKey != attr {
109+
return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v",
110+
n, attr, found.SnapshotEncryptionKey.RawKey)
111+
} else if found.SnapshotEncryptionKey == nil && attr != "" {
112+
return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v",
113+
n, attr, found.SnapshotEncryptionKey)
114+
}
115+
116+
attr = rs.Primary.Attributes["source_disk_encryption_key_sha256"]
117+
if found.SourceDiskEncryptionKey != nil && found.SourceDiskEncryptionKey.Sha256 != attr {
118+
return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v",
119+
n, attr, found.SourceDiskEncryptionKey.Sha256)
120+
} else if found.SourceDiskEncryptionKey == nil && attr != "" {
121+
return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v",
122+
n, attr, found.SourceDiskEncryptionKey)
123+
}
124+
125+
attr = rs.Primary.Attributes["source_disk_encryption_key_raw"]
126+
if found.SourceDiskEncryptionKey != nil && found.SourceDiskEncryptionKey.RawKey != attr {
127+
return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v",
128+
n, attr, found.SourceDiskEncryptionKey.RawKey)
129+
} else if found.SourceDiskEncryptionKey == nil && attr != "" {
130+
return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v",
131+
n, attr, found.SourceDiskEncryptionKey)
132+
}
133+
134+
attr = rs.Primary.Attributes["source_disk_id"]
135+
if found.SourceDiskId != attr {
136+
return fmt.Errorf("Snapshot %s has mismatched source disk id.\nTF State: %+v.\nGCP State: %+v",
137+
n, attr, found.SourceDiskId)
138+
}
139+
140+
attr = rs.Primary.Attributes["source_disk"]
141+
if found.SourceDisk != attr {
142+
return fmt.Errorf("Snapshot %s has mismatched source disk.\nTF State: %+v.\nGCP State: %+v",
143+
n, attr, found.SourceDisk)
144+
}
145+
146+
attr = rs.Primary.Attributes["self_link"]
147+
if found.SelfLink != attr {
148+
return fmt.Errorf("Snapshot %s has mismatched self link.\nTF State: %+v.\nGCP State: %+v",
149+
n, attr, found.SelfLink)
96150
}
97151

98152
*snapshot = *found

0 commit comments

Comments
 (0)