Open
Conversation
Container-registry: creates CR and generates permissions oci-config: parses oci cli config to be used in terraform s3-compatible: module as drop in replacement of AWS's S3 user: creates user and manages policy in one place
0a80035 to
c8cbcb4
Compare
Comment on lines
+11
to
+23
| module "container_registry_api_php" { | ||
| source = "./.." | ||
|
|
||
| compartment_id = local.tenancy | ||
| project_name = local.project_name | ||
| environment = local.environment | ||
| region = "me-jeddah-1" | ||
| suffix = "api" | ||
|
|
||
| group_name_for_permission = "${local.project_name}-${local.environment}-CICD" | ||
| container_repository_is_immutable = false | ||
| container_repository_is_public = false | ||
| } |
Contributor
There was a problem hiding this comment.
Can you add a sample resource that consumes the policy output to the example?
Comment on lines
+13
to
+20
| output "policy" { | ||
| description = "policies that allow push and pull to this container registry by user" | ||
| value = [ | ||
| "Allow group ${var.group_name_for_permission} to read repos in compartment id ${var.compartment_id} where any { target.repo.name=/${oci_artifacts_container_repository.terraform_container_registry.display_name}*/}", | ||
| "Allow group ${var.group_name_for_permission} to use repos in compartment id ${var.compartment_id} where any { target.repo.name=/${oci_artifacts_container_repository.terraform_container_registry.display_name}*/}", | ||
| "Allow group ${var.group_name_for_permission} to manage repos in compartment id ${var.compartment_id} where any { target.repo.name=/${oci_artifacts_container_repository.terraform_container_registry.display_name}*/}", | ||
| ] | ||
| } |
Contributor
There was a problem hiding this comment.
- That may be just me, but I'm not a fan of a lot of interpolation in
outputs.tfand I'd keep it inmain.tfin locals. You also may try to shorten it a bit by using extra locals. - Isn't it too narrow? I.e. what if I want to allow developers to manage the repo, but allow some application role to just pull fresh images?
Something like this:
#variables.tf
variable "policies" {
type = map(list(string))
}
# main.tf
locals {
repo_name = oci_artifacts_container_repository.terraform_container_registry.display_name
repo_url = "${var.region}.ocir.io/${data.oci_objectstorage_namespace.namespace.namespace}/${local.repo_name}"
policy_actions = ["read", "use", "manage"]
policies = {
for name, permissions in var.policies : name => flatten([
for permission in permissions : [
"Allow ${name} to ${permission} repos in compartment id ${var.compartment_id} where any { target.repo.name=/${local.repo_name}*/}"
]
])
}
}
# outputs.tf
output "url" {
value = local.repo_url
}
output "policies" {
value = local.policies
}
output "policy" {
# You can use flatten() to output everything in a single array as well
}The above should accept something like:
module "container_registry_api_php" {
policies = {
"group foo" = ["read", "use", "manage"],
"group bar" = ["read"]
}
}
locals {
resulting_policies = container_registry_api_php.policies
}
# resulting policies are as below:
{
"group foo" = [
"Allow group foo to read repos in compartment id some_id where any { target.repo.name=/repo_name*/}",
"Allow group foo to use repos in compartment id some_id where any { target.repo.name=/repo_name*/}",
"Allow group foo to manage repos in compartment id some_id where any { target.repo.name=/repo_name*/}",
],
"group bar" = [
"Allow group bar to read repos in compartment id some_id where any { target.repo.name=/repo_name*/}",
],
}
Member
There was a problem hiding this comment.
@grzesjam maybe stick (repo) convention output.tf ->outputs.tf and variable.tf ->variables.tf?
Collaborator
Author
There was a problem hiding this comment.
- I prefer to have output in output, it's much easier to fix i something outputs incorrectly, I don't need to jump between all files. But I'm not sure which approach is more correct
- I do understand you with your approach but with it, we expect someone already understanding how permissions in Oracle Cloud work, and what is needed which I don't like, it should "just work".
How about just ask for "read" and "manage" group name and generate output with "read_permissions" and "full_permissions"?
damlys
approved these changes
Sep 10, 2021
969ecdc to
bfc7df7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Container-registry: creates CR and generates permissions
oci-config: parses oci cli config to be used in terraform
s3-compatible: module as drop in replacement of AWS's S3
user: creates user and manages policy in one place