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 support IAM policy for the Environment of Apigee X #5270

Merged
merged 18 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mmv1/products/apigee/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ objects:
message: 'message'
description: |
An `Environment` in Apigee.
iam_policy: !ruby/object:Api::Resource::IamPolicy
exclude: false
method_name_separator: ':'
parent_resource_attribute: 'env_id'
import_format: ["{{org_id}}/environments/{{name}}", "{{name}}"]
Copy link
Member

Choose a reason for hiding this comment

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

This % will indicate that the org_id can contain slashes, which should resolve the problem. (Currently the import_format regex excludes the "organization/" at the start of the org id.)

Suggested change
import_format: ["{{org_id}}/environments/{{name}}", "{{name}}"]
import_format: ["{{%org_id}}/environments/{{name}}", "{{name}}"]

base_url: "{{org_id}}/environments/{{name}}"
self_link: "{{org_id}}/environments/{{name}}"
parameters:
- !ruby/object:Api::Type::String
name: 'orgId'
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/apigee/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
# the resources needed for the acceptance test.
name: "apigee_environment_basic_test"
primary_resource_id: "apigee_environment"
primary_resource_name: "getTestProjectFromEnv(), fmt.Sprintf(\"tf-test-apigee-env%s\", context[\"random_suffix\"])"
Copy link
Member

@melinath melinath Nov 10, 2021

Choose a reason for hiding this comment

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

It looks like this is causing issues; it is causing things like this to be generated:

			{
				ResourceName:      "google_apigee_environment_iam_binding.foo",
				ImportStateId:     fmt.Sprintf("%s/environments/%s roles/viewer", getTestProjectFromEnv(), fmt.Sprintf("tf-test-apigee-env%s", context["random_suffix"])),
				ImportState:       true,
				ImportStateVerify: true,
			},

This results in the import id being set to something like my-project/environments/tf-test-apigee-envasdfklj but it should be organizations/tf-testasdfklj/environments/tf-testasdfklj. I think you could resolve the issue with something like this:

Suggested change
primary_resource_name: "getTestProjectFromEnv(), fmt.Sprintf(\"tf-test-apigee-env%s\", context[\"random_suffix\"])"
primary_resource_name: "fmt.Sprintf(\"organizations/tf-test%s\", context[\"random_suffix\"]), fmt.Sprintf(\"tf-test%s\", context[\"random_suffix\"])"

Copy link
Member

Choose a reason for hiding this comment

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

Let me know if that helps the tests pass for you locally!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done! I'm still working with my team to setup the permission for me to run tests locally. We can try and see if the tests pass in your system.

test_env_vars:
org_id: :ORG_ID
billing_account: :BILLING_ACCT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
obj["name"] = d.Get("project_id").(string)
return obj, nil
return obj, nil
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ resource "google_apigee_organization" "org" {
google_service_networking_connection.apigee_vpc_connection,
google_kms_crypto_key_iam_binding.apigee_sa_keyuser,
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ resource "google_apigee_organization" "<%= ctx[:primary_resource_id] %>" {
google_service_networking_connection.apigee_vpc_connection,
google_kms_crypto_key_iam_binding.apigee_sa_keyuser,
]
}
}
9 changes: 7 additions & 2 deletions mmv1/templates/terraform/iam/iam_attributes.tf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<% example = object.examples.reject(&:skip_test)
.reject { |e| @api.version_obj_or_closest(version) < @api.version_obj_or_closest(e.min_version) }
.first -%>
<% if !example -%>
<% example = object.examples
.reject { |e| @api.version_obj_or_closest(version) < @api.version_obj_or_closest(e.min_version) }
.first -%>
.first -%>
<% end -%>
<% self_link_url = object.iam_policy.self_link || object.self_link_url -%>
<% parent_resource_last_param_name = extract_identifiers(self_link_url).last -%>
<% parent_resource_type_type = object.iam_policy.parent_resource_type || resource_ns -%>
Expand All @@ -11,4 +16,4 @@
<% attribute_val = p.underscore -%>
<% end -%>
<%= attribute_val.underscore -%> = <%= parent_resource_type_type -%>.<%= example.primary_resource_id -%>.<%= p.underscore %>
<% end -%>
<% end -%>