Skip to content

Init Storage IAM policy #493

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

Closed
wants to merge 14 commits into from
Closed

Conversation

sebglon
Copy link
Contributor

@sebglon sebglon commented Sep 29, 2017

refer to issue #481

@sebglon
Copy link
Contributor Author

sebglon commented Sep 30, 2017

Tested OK for Bucket Iam Policy

@sebglon
Copy link
Contributor Author

sebglon commented Oct 10, 2017

make testacc TEST=./google TESTARGS='-run=TestAccGoogleStorageObjectIAMPolicy'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run=TestAccGoogleStorageObjectIAMPolicy -timeout 120m
=== RUN   TestAccGoogleStorageObjectIAMPolicy_basic
--- SKIP: TestAccGoogleStorageObjectIAMPolicy_basic (0.00s)
	resource_google_project_test.go:432: Environment variable GOOGLE_PROJECT_NUMBER is not set
=== RUN   TestAccGoogleStorageObjectIAMPolicy_upgrade
--- SKIP: TestAccGoogleStorageObjectIAMPolicy_upgrade (0.00s)
	resource_google_project_test.go:432: Environment variable GOOGLE_PROJECT_NUMBER is not set
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	0.009s

@sebglon sebglon force-pushed the storage-iam-policy branch 6 times, most recently from d9413e2 to 7e436a5 Compare October 16, 2017 08:00
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sebglon, this looks fantastic, thanks for the PR! I have some minor, nitpicky comments, and it looks like we're missing documentation for object policy, but other than that, this looks amazing. Thanks so much for the hard work. Do let me know if you have any questions.

@@ -0,0 +1,122 @@
package google
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a nitpick, but I'd love to see a _ between iam and policy in the filename here.

func resourceStorageBucketIAMPolicyCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

if err := setBucketIamPolicy(d, config); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually like to do a log.Printf("[DEBUG] Setting IAM policy for bucket %q", bucket) before we make an API call, and a log.Printf("[DEBUG] Set IAM policy for bucket %q", bucket) after the request completes, to help debug.

}

func marshalStorageIamPolicy(policy *storagev1.Policy) string {
pdBytes, _ := json.Marshal(&storagev1.Policy{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it seems impossible, but I'd really be much more comfortable if we checked this error here.

)

func testBucketIamName() string {
return fmt.Sprintf("%s-%d", "tf-test-iam-bucket", acctest.RandInt())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use acctest.RandomWithPrefix("tf-test-iam-bucket") which is a little less convoluted.


func resourceStorageObjectIAMPolicyCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, debug logs here would be awesome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, just before and after every API request would be 💯

return err
}

d.SetId(d.Get("object").(string))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a combination of bucket and object, to ensure uniqueness? Also, for future import, we'd need at least project, bucket, and object, I think. So I think setting it to a combination of the three would be really useful.

return err
}

d.SetId(d.Get("bucket").(string))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set this to a combination of project and bucket, we won't need to change IDs to support import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand exactly what you want. Actualy i do not have project var.
As seen in resource_storage_bucket_acl, ican set bucket+ "-iam_policy"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what I'm suggesting here and why:

  • When we make resources importable, we need to be able to identify the resources based on their ID. This means the ID needs to not only be unique, but contain all the information necessary to retrieve the resource.
  • For this resource, it looks like we need both the project and the bucket ID to be able to retrieve the bucket.
  • So ideally, our ID would be something like {project}/{bucket}, which we could then parse into the info we need to be able to retrieve the resource given just its ID.

Copy link
Contributor Author

@sebglon sebglon Oct 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On google Policy, i have etag parameter that is an entity ID (return by API). but this does not contain project.
I don't see how to make it.

@@ -852,10 +852,10 @@
"revisionTime": "2016-12-14T09:25:55Z"
},
{
"checksumSHA1": "FEzQdhqmb6aqGL1lKnjOcUHIGSY=",
"checksumSHA1": "F/N7JzfuHZAk1UXi2zw/62hFPpM=",
"path": "google.golang.org/api/bigquery/v2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we're bringing in a lot of unnecessary vendor changes for this PR. Could we clean this up to just update storage, or is there a reason it needs to bring bigquery along?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also, is a storage library update necessary to support this functionality?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes an update is necessary and this update bring bigquery lib with small change type

@sebglon sebglon force-pushed the storage-iam-policy branch from 2eb1c30 to 597e537 Compare October 27, 2017 07:30
@sebglon sebglon force-pushed the storage-iam-policy branch from 3844afc to e3c7096 Compare November 2, 2017 19:59
Sébastien GLON added 2 commits November 2, 2017 21:18
@sebglon
Copy link
Contributor Author

sebglon commented Nov 2, 2017

@paddycarver I have cleaned dependencies with master change

@sebglon
Copy link
Contributor Author

sebglon commented Nov 3, 2017

@danawillow and @paddycarver is itpossible to have status on this PR?

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay on this. Some new comments, but we're pretty close on this one. Thanks for all the great work!

for _, member := range binding.Members {
bindingBuffer.WriteString(fmt.Sprintf("\"%s\",\n", member))
}
bindingBuffer.WriteString("]}\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the code scares me, to be honest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same than resource_google_folder_iam_policy_test.go;

I have added Comment on source code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, missed this response. It largely scares me because we're dynamically building the config string in a buffer, which is more complicated than tests usually require. I think this may be more generalized than is strictly necessary, but it's really not worth holding a merge over.

return err
}

d.SetId(d.Get("bucket").(string) + "-" + d.Get("object").(string) + "-iam-policy")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could use a separator here that is an invalid character for a bucket name, that'd be awesome. (/ is a good choice, I believe.)

The idea is that we can then parse the ID to get the bucket and object back, which helps in a few places. As it stands, there's no real way to reliably turn this ID back into its constituent parts. In my-bucket-object-id-iam-policy, for example, we'd have no idea what was the bucket and what was the object.

%s
}
resource "google_storage_Object_iam_policy" "test" {
Object = "${google_storage_Object.Object.name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a find and replace is doing some weird capitalising here.

)

func testObjectIamName() string {
return fmt.Sprintf("%s-%d", "tf-test-iam-Object", acctest.RandInt())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a find and replace is doing some weird capitalising here.

config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_storage_Object_iam_policy" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a find and replace is doing some weird capitalising here.

@@ -0,0 +1,58 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've duplicated the bucket docs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; Why?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have both a google_storage_bucket_iam_policy.html.markdown and a nearly identical storage_bucket_iam_policy.html.markdown file (without the "google" prefix). I assume that's what @paddycarver is referring to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, sorry. I'm seeing two different files here with almost the same name and can't tell what happened.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, @sebglon deleted the duplicate file. I think the only outstanding issue left is the "this part of the code scares me" section, if you can expand on that?

Allows management of an IAM policy for a Google Storage Bucket Object.
---

# google\_storage\-_object\_iam\_policy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have an extra - in here that's messing things up.


resource "google_storage_object" "object" {
display_name = "%s"
bucket = "${google_storage_bucket.bucket.name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs/spaces problem. Generally we ask that documentation examples be run through terraform fmt.


Changing this updates the policy.

Deleting this removes the policy, but leaves the original object policy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? Looking up at the code, it looks like the policy is just set to an empty policy on delete.

@paddycarver
Copy link
Contributor

It looks like after 580b153, the code no longer builds.

@sebglon
Copy link
Contributor Author

sebglon commented Nov 13, 2017

@paddycarver Compile is corrected.

@sebglon
Copy link
Contributor Author

sebglon commented Dec 5, 2017

@danawillow , @paddycarver Can i have status on validation; this lock my project?

@tragiclifestories
Copy link
Contributor

Cc @rosbo who has been working on the IAM system

@rosbo
Copy link
Contributor

rosbo commented Dec 6, 2017

In #744 we refactored the IAM code to make it easier to write new IAM resources. #822 adds IAM support for storage bucket using the new architecture.

Closing this one in favor #822.

@rosbo rosbo closed this Dec 6, 2017
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
@ghost
Copy link

ghost commented Mar 30, 2020

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 Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants