Skip to content

Commit

Permalink
add nil checks to bucket policy and allow updating to false (#3886)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and danawillow committed Jun 19, 2019
1 parent 5fca8af commit d875edc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions google/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ func resourceStorageBucketRead(d *schema.ResourceData, meta interface{}) error {
d.Set("versioning", flattenBucketVersioning(res.Versioning))
d.Set("lifecycle_rule", flattenBucketLifecycle(res.Lifecycle))
d.Set("labels", res.Labels)
d.Set("bucket_policy_only", res.IamConfiguration.BucketPolicyOnly.Enabled)
if res.IamConfiguration != nil && res.IamConfiguration.BucketPolicyOnly != nil {
d.Set("bucket_policy_only", res.IamConfiguration.BucketPolicyOnly.Enabled)
} else {
d.Set("bucket_policy_only", false)
}

if res.Billing == nil {
d.Set("requester_pays", nil)
Expand Down Expand Up @@ -795,13 +799,13 @@ func flattenBucketLifecycleRuleCondition(condition *storage.BucketLifecycleRuleC
}

func expandIamConfiguration(d *schema.ResourceData) *storage.BucketIamConfiguration {
iamConfig := &storage.BucketIamConfiguration{}
if v, ok := d.GetOk("bucket_policy_only"); ok {
iamConfig.BucketPolicyOnly = &storage.BucketIamConfigurationBucketPolicyOnly{
Enabled: v.(bool),
}
return &storage.BucketIamConfiguration{
ForceSendFields: []string{"BucketPolicyOnly"},
BucketPolicyOnly: &storage.BucketIamConfigurationBucketPolicyOnly{
Enabled: d.Get("bucket_policy_only").(bool),
ForceSendFields: []string{"Enabled"},
},
}
return iamConfig
}

func expandStorageBucketLifecycle(v interface{}) (*storage.BucketLifecycle, error) {
Expand Down
4 changes: 2 additions & 2 deletions google/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,15 +772,15 @@ func TestAccStorageBucket_bucketPolicyOnly(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccStorageBucket_bucketPolicyOnly(bucketName, false),
Config: testAccStorageBucket_bucketPolicyOnly(bucketName, true),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccStorageBucket_bucketPolicyOnly(bucketName, true),
Config: testAccStorageBucket_bucketPolicyOnly(bucketName, false),
},
{
ResourceName: "google_storage_bucket.bucket",
Expand Down

0 comments on commit d875edc

Please sign in to comment.