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

Add new resource to support IAM custom project roles. #709

Merged
merged 7 commits into from
Nov 10, 2017

Conversation

rosbo
Copy link
Contributor

@rosbo rosbo commented Nov 8, 2017

Addresses the first half of #540

I also had to update the IAM client to the latest version.

I wasn't sure if I should name the resource google_project_iam_role or google_project_custom_iam_role.

In the general docs, it is call Customized Role or Custom Role. In the API documentation, it is only role.

@rosbo rosbo requested a review from danawillow November 8, 2017 22:27
@rosbo
Copy link
Contributor Author

rosbo commented Nov 8, 2017

TF_ACC=1 go test ./google -v -run TestAccGoogleProjectIamRole_ -timeout 120m
=== RUN   TestAccGoogleProjectIamRole_import
=== RUN   TestAccGoogleProjectIamRole_basic
=== RUN   TestAccGoogleProjectIamRole_undelete
--- PASS: TestAccGoogleProjectIamRole_import (2.86s)
--- PASS: TestAccGoogleProjectIamRole_basic (3.76s)
--- PASS: TestAccGoogleProjectIamRole_undelete (4.86s)
PASS

@pdecat
Copy link
Contributor

pdecat commented Nov 9, 2017

Awesome!

Do you plan to also add google_organization_iam_role in the same PR?

@rosbo
Copy link
Contributor Author

rosbo commented Nov 9, 2017

@pdecat I will add support for the organization custom IAM roles in a separate PR to make it easier to review.

@rosbo rosbo changed the title Add new resource to support IAM custom roles. Add new resource to support IAM custom project roles. Nov 9, 2017
Copy link
Contributor

@danawillow danawillow left a comment

Choose a reason for hiding this comment

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

I don't have a strong preference on role vs custom_role. I feel like custom_role would make it more obvious to find for people looking for it, but role matches the API and is less wordy. @pdecat since you'd be using this, do you have a preference?


func testAccCheckGoogleProjectIamRole_basic(roleId string) string {
return fmt.Sprintf(`
resource "google_project_iam_role" "foo" {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you terraform fmt these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

This snippet creates a customized IAM role.

```hcl
resource "google_project_iam_role" "myCustomRole" {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think we actually have an opinion on this, but I feel like I very rarely see camelcasing in resource names. Most of the examples I found were one word, or used hyphens.

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 am ok with renaming the resource name. However, the role_id cannot have an hyphen: It doesn't match pattern [a-zA-Z0-9_\.]{3,64}.


```hcl
resource "google_project_iam_role" "myCustomRole" {
role_id = "myCustomRole"
Copy link
Contributor

Choose a reason for hiding this comment

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

terraform fmt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Type: schema.TypeString,
Required: true,
},
"permissions": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be MinItems: 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't mind seeing an error thrown if a user tries to set deleted on create

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@rosbo
Copy link
Contributor Author

rosbo commented Nov 9, 2017

Yeah, I think also _custom_role is probably better since this creates and deletes custom roles. It doesn't deal with regular role. I think it is a good case to diverge from the API and use the nomenclature used in the GCP docs instead.

@rosbo
Copy link
Contributor Author

rosbo commented Nov 9, 2017

I renamed the resource to google_project_iam_custom_role. I am also curious in @pdecat opinion on it. I can easily revert the latest commit.

@pdecat
Copy link
Contributor

pdecat commented Nov 10, 2017

Hi @danawillow @rosbo, in the issue description, I just wanted to match the API as I thought was the norm.

I agree google_project_iam_custom_role is more explicit and was a bit confused at the beginning with the doc/API inconsistency.

Also, I guessed that if custom was not used in the API, it was probably to make it more generic and allow other usages in the future.

@rosbo
Copy link
Contributor Author

rosbo commented Nov 10, 2017

Great, we are all in agreement :)

@danawillow could re-review it with the latest adjustments?

Thanks

@rosbo rosbo merged commit ab68b06 into hashicorp:master Nov 10, 2017
@rosbo rosbo deleted the custom-roles branch November 10, 2017 19:01
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* Upgrade iam client to latest version
* Add new resource to support IAM custom roles.
* Add documentation
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
@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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants