|
| 1 | +package ovh |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAccCloudProjectContainerRegistryOIDCDataSource_basic(t *testing.T) { |
| 13 | + serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST") |
| 14 | + region := os.Getenv("OVH_CLOUD_PROJECT_CONTAINERREGISTRY_REGION_TEST") |
| 15 | + registryName := acctest.RandomWithPrefix(test_prefix) |
| 16 | + oidcEndpoint := os.Getenv("OVH_CLOUD_PROJECT_CONTAINERREGISTRY_OIDC_ENDPOINT_TEST") |
| 17 | + |
| 18 | + config := fmt.Sprintf( |
| 19 | + testAccCloudProjectContainerRegistryOIDCDataSourceConfig, |
| 20 | + serviceName, |
| 21 | + region, |
| 22 | + registryName, |
| 23 | + oidcEndpoint, |
| 24 | + ) |
| 25 | + |
| 26 | + resource.Test(t, resource.TestCase{ |
| 27 | + PreCheck: func() { |
| 28 | + testAccPreCheckContainerRegistryOIDC(t) |
| 29 | + }, |
| 30 | + Providers: testAccProviders, |
| 31 | + Steps: []resource.TestStep{ |
| 32 | + { |
| 33 | + Config: config, |
| 34 | + Check: resource.ComposeTestCheckFunc( |
| 35 | + resource.TestCheckResourceAttr( |
| 36 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_name", "name"), |
| 37 | + resource.TestCheckResourceAttr( |
| 38 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_endpoint", oidcEndpoint), |
| 39 | + resource.TestCheckResourceAttr( |
| 40 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_client_id", "clientID"), |
| 41 | + resource.TestCheckResourceAttr( |
| 42 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_scope", "openid,profile,email,offline_access"), |
| 43 | + resource.TestCheckResourceAttr( |
| 44 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_groups_claim", "groupsClaim"), |
| 45 | + resource.TestCheckResourceAttr( |
| 46 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_admin_group", "adminGroup"), |
| 47 | + resource.TestCheckResourceAttr( |
| 48 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_verify_cert", "true"), |
| 49 | + resource.TestCheckResourceAttr( |
| 50 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_auto_onboard", "true"), |
| 51 | + resource.TestCheckResourceAttr( |
| 52 | + "data.ovh_cloud_project_containerregistry_oidc.oidcData", "oidc_user_claim", "userClaim"), |
| 53 | + ), |
| 54 | + }, |
| 55 | + }, |
| 56 | + }) |
| 57 | +} |
| 58 | + |
| 59 | +var testAccCloudProjectContainerRegistryOIDCDataSourceConfig = ` |
| 60 | +data "ovh_cloud_project_capabilities_containerregistry_filter" "registryCap" { |
| 61 | + service_name = "%s" |
| 62 | + plan_name = "SMALL" |
| 63 | + region = "%s" |
| 64 | +} |
| 65 | +
|
| 66 | +resource "ovh_cloud_project_containerregistry" "registry" { |
| 67 | + service_name = data.ovh_cloud_project_capabilities_containerregistry_filter.registryCap.service_name |
| 68 | + plan_id = data.ovh_cloud_project_capabilities_containerregistry_filter.registryCap.id |
| 69 | + name = "%s" |
| 70 | + region = data.ovh_cloud_project_capabilities_containerregistry_filter.registryCap.region |
| 71 | +} |
| 72 | +
|
| 73 | +resource "ovh_cloud_project_containerregistry_oidc" "oidc" { |
| 74 | + service_name = ovh_cloud_project_containerregistry.registry.service_name |
| 75 | + registry_id = ovh_cloud_project_containerregistry.registry.id |
| 76 | + |
| 77 | + oidc_name = "name" |
| 78 | + oidc_endpoint = "%s" |
| 79 | + oidc_client_id = "clientID" |
| 80 | + oidc_client_secret = "clientSecret" |
| 81 | + oidc_scope = "openid,profile,email,offline_access" |
| 82 | + oidc_groups_claim = "groupsClaim" |
| 83 | + oidc_admin_group = "adminGroup" |
| 84 | + oidc_verify_cert = "true" |
| 85 | + oidc_auto_onboard = "true" |
| 86 | + oidc_user_claim = "userClaim" |
| 87 | +
|
| 88 | + depends_on = [ |
| 89 | + ovh_cloud_project_containerregistry.registry |
| 90 | + ] |
| 91 | +} |
| 92 | +
|
| 93 | +data "ovh_cloud_project_containerregistry_oidc" "oidcData" { |
| 94 | + service_name = ovh_cloud_project_containerregistry.registry.service_name |
| 95 | + registry_id = ovh_cloud_project_containerregistry.registry.id |
| 96 | +
|
| 97 | + depends_on = [ |
| 98 | + ovh_cloud_project_containerregistry_oidc.oidc |
| 99 | + ] |
| 100 | +} |
| 101 | +` |
0 commit comments