Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_storage_bucket_acl role_entities don't work #50

Closed
hashibot opened this issue Jun 13, 2017 · 9 comments
Closed

google_storage_bucket_acl role_entities don't work #50

hashibot opened this issue Jun 13, 2017 · 9 comments
Assignees
Labels

Comments

@hashibot
Copy link

This issue was originally opened by @mikemcrill as hashicorp/terraform#10612. It was migrated here as part of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.7.13

Affected Resource(s)

  • google_storage_bucket_acl

Terraform Configuration Files

resource "google_storage_bucket_acl" "scripts-acl" {
  bucket = "${google_storage_bucket.scripts.name}"
  default_acl = "private"

  role_entity = [
    "OWNER:project-owners-123456",
    "READER:[email protected]",                                                                                          "READER:[email protected]",
    "READER:[email protected]",
  ]
 }

Debug Output

https://gist.github.com/mikemcrill/b43cb01767812985338b9bb890da4a9b

Expected Behavior

ACL should be applied without errors

Actual Behavior

ACL tries to delete owner and fails

Steps to Reproduce

Apply terraform with the above state

Important Factoids

I tried with and without referencing the OWNER entity, same effect. Terraform keeps trying to destroy the OWNER permission.

@joe-boyce
Copy link

Any updates on this one? not being able to use terraform for bucket acl's is making this resource unusable

@caseylang
Copy link

Having this problem with 0.9.11 as well, including the reappearing work issue described in hashicorp/terraform#10612 (comment)

I differ from the parent bug however. By removing a reference to OWNER in my ACL I'm able to create additional permissions, without having terraform attempt to delete the real owner.

It also seems worth mentioning that the permissions Terraform creates are of the older Storage Legacy Bucket variety.

@paddycarver
Copy link
Contributor

Is this still an ongoing issue? I've got a working config at the moment that adds a user in the OWNER role, and it's working without a hitch for me. Does anyone have a minimal reproduction handy?

@lobeck
Copy link

lobeck commented Aug 18, 2017

This is our case which is affected, the ACL will be updated on every apply

resource "google_storage_bucket" "blubb_bucket" {
  name     = "${var.bucket_name}"
  location = "${var.location}"
  storage_class = "${var.storage_class}"

  website {
    main_page_suffix = "index.html"
  }
}

resource "google_storage_bucket_acl" "blubb_bucket" {
  bucket = "${google_storage_bucket.blubb_bucket.name}"

  role_entity = [
    "READER:AllUsers",
  ]
}

gsutil acl:

[
  {
    "entity": "project-owners-1234",
    "projectTeam": {
      "projectNumber": "1234",
      "team": "owners"
    },
    "role": "OWNER"
  },
  {
    "entity": "project-editors-1234",
    "projectTeam": {
      "projectNumber": "1234",
      "team": "editors"
    },
    "role": "OWNER"
  },
  {
    "entity": "project-viewers-1234",
    "projectTeam": {
      "projectNumber": "1234",
      "team": "viewers"
    },
    "role": "READER"
  },
  {
    "entity": "allUsers",
    "role": "READER"
  }
]

Apply output:

~ module.infrastructure.foo.google_storage_bucket_acl.blubb_bucket
    role_entity.#: "0" => "1"
    role_entity.0: "" => "READER:AllUsers"

Terraform v0.9.11

paddycarver added a commit that referenced this issue Aug 24, 2017
Storage bucket ACLs inherited the behaviour of only updating the fields
that were set in the config file. Terraform should track all the fields
in the resource, whether the user has specified a value for them or not,
and correct any drift that may occur.

This has manifested in an issue and unexpected behaviour in #50, and
this PR restores the expected behaviour.
@paddycarver
Copy link
Contributor

paddycarver commented Aug 24, 2017

Thanks! That clarified things immensely.

I've got good news and bad news.

  • Good news: I've found the cause of this, and opened a PR (storage: make bucket ACLs control the entire resource. #358) to address it.
  • Bad news: because this is a breaking change (even though, technically, the former behaviour was just incorrect) I think it best we wait for 1.0.0 to release this.
  • Good news: 1.0.0 was going to be (unless something's changed) the next release, anyways.
  • Bad news: even then, your config still won't work; you'll get a permanent diff from "READER:AllUsers" to "READER:allUsers".
  • Good news: if you fix that now, your config works as expected even without the fix.
  • Bad news: You'll have to add the project-owners-.... ACLs and the other default configs into your ACL, or the will be removed, which may cause problems for you. This is divergent from the current behaviour, but how the resource was intended to work the entire time.

Sorry for the rollercoaster, there. Hopefully that solution helps you out now, and the PR makes the problem clearer in the future. :)

@paddycarver
Copy link
Contributor

Ah, sorry, misclick.

@paddycarver paddycarver reopened this Aug 24, 2017
@paddycarver
Copy link
Contributor

This has been merged to master, and will be released with the next release.

negz pushed a commit to negz/terraform-provider-google that referenced this issue Oct 17, 2017
Storage bucket ACLs inherited the behaviour of only updating the fields
that were set in the config file. Terraform should track all the fields
in the resource, whether the user has specified a value for them or not,
and correct any drift that may occur.

This has manifested in an issue and unexpected behaviour in hashicorp#50, and
this PR restores the expected behaviour.
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this issue May 21, 2019
Move beta providers to their own block in provider.go
@jrluis
Copy link

jrluis commented Sep 2, 2019

Hi,

We seemed to have found a regression or an edge case for the google_storage_object_acl resource that is very similar to this one.

The terraform version is: v0.11.13

The file permissions were lost after a re-upload of the same files. Terraform detected the changes because the apply was done on different computers that lead to different paths for the uploaded files.

We've made a regression test. I'm sharing it as it helps understanding the use case.

package test

import (
	"testing"

	"github.com/gruntwork-io/terratest/modules/terraform"
	"github.com/gruntwork-io/terratest/modules/gcp"
	"github.com/gruntwork-io/terratest/modules/http-helper"
	"time"
	"github.com/gruntwork-io/terratest/modules/test-structure"
)

//This test simulates as if the tf code was applied on two terraform operators computers
//The use case is: operator 1 will apply the terraform code from his computer
//and some time later operator 2 will apply it from his computer, making the paths
//from the js tracker to change which leads to terraform detecting changes and forcing
//a re-upload as it thinks the files are different because the paths between operator 1 and 2
//are different.

func TestGCPJSTracker(t *testing.T) {
	t.Parallel()

	options := &terraform.Options{
		TerraformDir: "/Users/polar_bear/work/terraform-modules/gcp_bucket_with_cdn/0.1.0,
		NoColor: true,
	}

	defer terraform.Destroy(t, options)

	//Simulate a terraform apply from a 1st computer
	terraform.Init(t, options)
	terraform.WorkspaceSelectOrNew(t, options, "ice_rink")
	terraform.Apply(t, options)

	tmpDir := test_structure.CopyTerraformFolderToTemp(t, "/Users/polar_bear/work/terraform-modules",
		"gcp_bucket_with_cdn/0.1.0")
	options.TerraformDir = tmpDir

	//Simulate a terraform apply from a 2nd computer
	terraform.Init(t, options)
	terraform.WorkspaceSelectOrNew(t, options, "ice_rink")
	terraform.Apply(t, options)

	gcp.AssertStorageBucketExists(t, "ice_rink_bucket")

	http_helper.HttpGetWithRetryWithCustomValidation(t,
		"https://ice_rink_bucket.example.com/file_uploade_by_tf.js",
		60,
		10 * time.Second,
		func(statusCode int, body string) bool {
			return statusCode == 200
		})
}

The terraform module creates a bucket with a public cdn and then uploads some files that are made public using the google_storage_object_acl resource.

Regards

@ghost
Copy link

ghost commented Sep 3, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants