-
Notifications
You must be signed in to change notification settings - Fork 144
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
feat(container-registry): add OVHcloud IAM feature for Managed Registry #907
Draft
air1bzz
wants to merge
1
commit into
ovh:master
Choose a base branch
from
air1bzz:feat/emo/add_container_registry_iam_feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
subcategory : "Managed Private Registry (MPR)" | ||
--- | ||
|
||
# ovh_cloud_project_containerregistry_iam (Data Source) | ||
|
||
Use this data source to get a OVHcloud Managed Private Registry through OVHcloud IAM. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ovh_cloud_project_containerregistry_iam" "my_iam" { | ||
service_name = "XXXXXX" | ||
registry_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" | ||
} | ||
|
||
output "iam-enabled" { | ||
value = data.ovh_cloud_project_containerregistry_iam.my_iam.iam_enabled | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `service_name` - (Optional) The id of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. | ||
* `registry_id` - The id of the Managed Private Registry. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `service_name` - The ID of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. | ||
* `registry_id` - The ID of the Managed Private Registry. | ||
* `iam-enabled` - OVHcloud IAM feature status. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
subcategory : "Managed Private Registry (MPR)" | ||
--- | ||
|
||
# ovh_cloud_project_containerregistry_iam | ||
|
||
Creates an OVHcloud IAM configuration in an OVHcloud Managed Private Registry. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "ovh_cloud_project_containerregistry_iam" "my_iam" { | ||
service_name = "XXXXXX" | ||
registry_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" | ||
|
||
#optional field | ||
delete_users = false | ||
} | ||
|
||
output "iam-enabled" { | ||
value = ovh_cloud_project_containerregistry_iam.my_iam.iam-enabled | ||
sensitive = true | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `service_name` - The ID of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. **Changing this value recreates the resource.** | ||
* `registry_id` - The ID of the Managed Private Registry. **Changing this value recreates the resource.** | ||
* `delete_users` - Delete existing users from Harbor. IAM feature can't be enabled if there is at least one user already created. This parameter is only used at IAM configuration creation. **Changing this value recreates the resource.** | ||
|
||
## Timeouts | ||
|
||
```hcl | ||
resource "ovh_cloud_project_containerregistry_iam" "my-iam" { | ||
# ... | ||
|
||
timeouts { | ||
create = "1h" | ||
update = "45m" | ||
delete = "50s" | ||
} | ||
} | ||
``` | ||
|
||
* `create` - (Default 10m) | ||
* `update` - (Default 10m) | ||
* `delete` - (Default 10m) | ||
|
||
## Import | ||
|
||
OVHcloud Managed Private Registry OVHcloud IAM can be imported using the tenant `service_name` and registry id `registry_id` separated by "/" E.g., | ||
|
||
```bash | ||
$ terraform import ovh_cloud_project_containerregistry_iam.my-iam service_name/registry_id | ||
``` |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||||
package ovh | ||||||||
|
||||||||
import ( | ||||||||
"fmt" | ||||||||
"log" | ||||||||
|
||||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||||||
) | ||||||||
|
||||||||
func dataSourceCloudProjectContainerRegistryIAM() *schema.Resource { | ||||||||
return &schema.Resource{ | ||||||||
Read: dataSourceCloudProjectContainerRegistryIAMRead, | ||||||||
Schema: map[string]*schema.Schema{ | ||||||||
"service_name": { | ||||||||
Type: schema.TypeString, | ||||||||
Description: "Service name", | ||||||||
Required: true, | ||||||||
ForceNew: true, | ||||||||
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), | ||||||||
}, | ||||||||
"registry_id": { | ||||||||
Type: schema.TypeString, | ||||||||
Description: "Registry ID", | ||||||||
Required: true, | ||||||||
ForceNew: true, | ||||||||
}, | ||||||||
"iam_enabled": { | ||||||||
Type: schema.TypeBool, | ||||||||
Description: "OVHcloud IAM enabled", | ||||||||
Computed: true, | ||||||||
}, | ||||||||
}, | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
func dataSourceCloudProjectContainerRegistryIAMRead(d *schema.ResourceData, meta any) error { | ||||||||
config := meta.(*Config) | ||||||||
serviceName := d.Get("service_name").(string) | ||||||||
registryID := d.Get("registry_id").(string) | ||||||||
|
||||||||
endpoint := fmt.Sprintf("/cloud/project/%s/containerRegistry/%s", serviceName, registryID) | ||||||||
res := &CloudProjectContainerRegistry{} | ||||||||
|
||||||||
log.Printf("[DEBUG] Will read from registry %s and project: %s", registryID, serviceName) | ||||||||
|
||||||||
err := config.OVHClient.Get(endpoint, res) | ||||||||
if err != nil { | ||||||||
return fmt.Errorf("calling get %s %w", endpoint, err) | ||||||||
} | ||||||||
|
||||||||
for k, v := range res.ToMap() { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if k == "iam_enabled" { | ||||||||
d.Set(k, v) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
d.SetId(serviceName + "/" + registryID) | ||||||||
|
||||||||
log.Printf("[DEBUG] Read IAM %+v", res) | ||||||||
|
||||||||
return nil | ||||||||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccCloudProjectContainerRegistryIAMDataSource_basic(t *testing.T) { | ||
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST") | ||
region := os.Getenv("OVH_CLOUD_PROJECT_CONTAINERREGISTRY_REGION_TEST") | ||
registryName := acctest.RandomWithPrefix(test_prefix) | ||
|
||
config := fmt.Sprintf( | ||
testAccCloudProjectContainerRegistryIAMDataSourceConfig, | ||
serviceName, | ||
region, | ||
registryName, | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheckContainerRegistryIAM(t) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.ovh_cloud_project_containerregistry_iam.iamData", "iam_enabled", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var testAccCloudProjectContainerRegistryIAMDataSourceConfig = ` | ||
data "ovh_cloud_project_capabilities_containerregistry_filter" "registryCap" { | ||
service_name = "%s" | ||
plan_name = "SMALL" | ||
region = "%s" | ||
} | ||
|
||
resource "ovh_cloud_project_containerregistry" "registry" { | ||
service_name = data.ovh_cloud_project_capabilities_containerregistry_filter.registryCap.service_name | ||
plan_id = data.ovh_cloud_project_capabilities_containerregistry_filter.registryCap.id | ||
name = "%s" | ||
region = data.ovh_cloud_project_capabilities_containerregistry_filter.registryCap.region | ||
} | ||
|
||
resource "ovh_cloud_project_containerregistry_iam" "iam" { | ||
service_name = ovh_cloud_project_containerregistry.registry.service_name | ||
registry_id = ovh_cloud_project_containerregistry.registry.id | ||
|
||
depends_on = [ | ||
ovh_cloud_project_containerregistry.registry | ||
] | ||
} | ||
|
||
data "ovh_cloud_project_containerregistry_iam" "iamData" { | ||
service_name = ovh_cloud_project_containerregistry.registry.service_name | ||
registry_id = ovh_cloud_project_containerregistry.registry.id | ||
|
||
depends_on = [ | ||
ovh_cloud_project_containerregistry_iam.iam | ||
] | ||
} | ||
` |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rephrase this