|
| 1 | +// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package oci |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "strconv" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/terraform" |
| 13 | + |
| 14 | + "github.com/terraform-providers/terraform-provider-oci/httpreplay" |
| 15 | +) |
| 16 | + |
| 17 | +var ( |
| 18 | + generateScopedAccessTokenRepresentation = map[string]interface{}{ |
| 19 | + "public_key": Representation{RepType: Required, Create: `-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuYNxKqyNSTPApIVh1xiR3914Q8Ex+goi8kbMUjMa/b47A12SGdh18SAsZTTkld09MGhIswyv2Eln5MQKyupf646zk0E0kxH4llpfSAtUEaa5bxRXhko5BejvimMy4hCMn+kYkzAre7CoAw97rZ96L+TgkqdtwYXl0JzE4xYwfM7OqkH9/3TIeiX4q8kVDi0CsHMGbBo4gMIIunLoEn27ej/Vm6Nbkgl8AnJaWZq8gG8y6ojDLrJhnTK4IVYZ3XYx2uxz/E5VcjMaTdWVjKVCS4F2yK9hFbL1G2KDDh8k3G7dFDFwGI6qxwidbZW7JtcXQWu0Qx0tBNdB28VlsDWZEQIDAQAB-----END PUBLIC KEY-----`}, |
| 20 | + "scope": Representation{RepType: Required, Create: `urn:oracle:db::id::*`}, |
| 21 | + } |
| 22 | + |
| 23 | + GenerateScopedAccessTokenResourceDependencies = "" |
| 24 | +) |
| 25 | + |
| 26 | +// issue-routing-tag: identity_data_plane/default |
| 27 | +func TestIdentityDataPlaneGenerateScopedAccessTokenResource_basic(t *testing.T) { |
| 28 | + httpreplay.SetScenario("TestIdentityDataPlaneGenerateScopedAccessTokenResource_basic") |
| 29 | + defer httpreplay.SaveScenario() |
| 30 | + |
| 31 | + config := testProviderConfig() |
| 32 | + |
| 33 | + compartmentId := getEnvSettingWithBlankDefault("compartment_ocid") |
| 34 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 35 | + |
| 36 | + resourceName := "oci_identity_data_plane_generate_scoped_access_token.test_generate_scoped_access_token" |
| 37 | + |
| 38 | + var resId string |
| 39 | + // Save TF content to Create resource with only required properties. This has to be exactly the same as the config part in the create step in the test. |
| 40 | + SaveConfigContent(config+compartmentIdVariableStr+GenerateScopedAccessTokenResourceDependencies+ |
| 41 | + GenerateResourceFromRepresentationMap("oci_identity_data_plane_generate_scoped_access_token", "test_generate_scoped_access_token", Required, Create, generateScopedAccessTokenRepresentation), "identitydataplane", "generateScopedAccessToken", t) |
| 42 | + |
| 43 | + ResourceTest(t, nil, []resource.TestStep{ |
| 44 | + // verify Create |
| 45 | + { |
| 46 | + Config: config + compartmentIdVariableStr + GenerateScopedAccessTokenResourceDependencies + |
| 47 | + GenerateResourceFromRepresentationMap("oci_identity_data_plane_generate_scoped_access_token", "test_generate_scoped_access_token", Required, Create, generateScopedAccessTokenRepresentation), |
| 48 | + Check: ComposeAggregateTestCheckFuncWrapper( |
| 49 | + resource.TestCheckResourceAttr(resourceName, "public_key", "-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuYNxKqyNSTPApIVh1xiR3914Q8Ex+goi8kbMUjMa/b47A12SGdh18SAsZTTkld09MGhIswyv2Eln5MQKyupf646zk0E0kxH4llpfSAtUEaa5bxRXhko5BejvimMy4hCMn+kYkzAre7CoAw97rZ96L+TgkqdtwYXl0JzE4xYwfM7OqkH9/3TIeiX4q8kVDi0CsHMGbBo4gMIIunLoEn27ej/Vm6Nbkgl8AnJaWZq8gG8y6ojDLrJhnTK4IVYZ3XYx2uxz/E5VcjMaTdWVjKVCS4F2yK9hFbL1G2KDDh8k3G7dFDFwGI6qxwidbZW7JtcXQWu0Qx0tBNdB28VlsDWZEQIDAQAB-----END PUBLIC KEY-----"), |
| 50 | + resource.TestCheckResourceAttr(resourceName, "scope", "urn:oracle:db::id::*"), |
| 51 | + |
| 52 | + func(s *terraform.State) (err error) { |
| 53 | + resId, err = FromInstanceState(s, resourceName, "id") |
| 54 | + if isEnableExportCompartment, _ := strconv.ParseBool(getEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment { |
| 55 | + if errExport := TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil { |
| 56 | + return errExport |
| 57 | + } |
| 58 | + } |
| 59 | + return err |
| 60 | + }, |
| 61 | + ), |
| 62 | + }, |
| 63 | + }) |
| 64 | +} |
0 commit comments