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

feat(ResourceController): Added onetime_credentials to ResourceInstan… #5532

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/IBM/keyprotect-go-client v0.14.0
github.com/IBM/logs-go-sdk v0.3.0
github.com/IBM/networking-go-sdk v0.48.0
github.com/IBM/platform-services-go-sdk v0.64.4
github.com/IBM/platform-services-go-sdk v0.65.0
github.com/IBM/project-go-sdk v0.3.5
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v5 v5.1.6
Expand Down Expand Up @@ -64,7 +64,7 @@ require (
)

require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20240423071914-9e96525baef4
github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/mqcloud-go-sdk v0.1.0
github.com/IBM/sarama v1.41.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func DataSourceIBMResourceInstance() *schema.Resource {
Description: "Guid of resource instance",
},

// ### Modification addded onetime_credentials to Resource scehama
"onetime_credentials": {
Type: schema.TypeBool,
Computed: true,
Description: "onetime_credentials of resource instance",
},

"parameters_json": {
Description: "Parameters asociated with instance in json string",
Type: schema.TypeString,
Expand Down Expand Up @@ -270,6 +277,8 @@ func DataSourceIBMResourceInstanceRead(d *schema.ResourceData, meta interface{})
d.Set(flex.ResourceName, instance.Name)
d.Set(flex.ResourceCRN, instance.CRN)
d.Set(flex.ResourceStatus, instance.State)
// ### Modifiction : Setting the onetime credientials
d.Set("onetime_credentials", instance.OnetimeCredentials)
if instance.Parameters != nil {
params, err := json.Marshal(instance.Parameters)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func DataSourceIBMResourceKey() *schema.Resource {
Description: "Status of resource key",
},

// ### Modification addded onetime_credentials to Resource scehama
"onetime_credentials": {
Type: schema.TypeBool,
Computed: true,
Description: "onetime_credentials of resource key",
},

"credentials": {
Description: "Credentials asociated with the key",
Sensitive: true,
Expand Down Expand Up @@ -162,6 +169,8 @@ func dataSourceIBMResourceKeyRead(d *schema.ResourceData, meta interface{}) erro
d.Set("role", roleCrn[strings.LastIndex(roleCrn, ":")+1:])
}

// ### Modification for onetime_credientails
d.Set("onetime_credentials", key.OnetimeCredentials)
d.Set("credentials", flex.Flatten(key.Credentials))
creds, err := json.Marshal(key.Credentials)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func ResourceIBMResourceInstance() *schema.Resource {
"resource_group_id"),
},

// ### Modification : Adding onetime_credientails into the response scehama
"onetime_credentials": {
Description: "A boolean that dictates if the onetime_credentials is true or false.",
Type: schema.TypeBool,
Computed: true,
},

"parameters": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -595,6 +602,8 @@ func ResourceIBMResourceInstanceRead(d *schema.ResourceData, meta interface{}) e
}
d.Set("plan", servicePlan)
d.Set("guid", instance.GUID)
// ### Modificataion : Setting "onetime_credentials"
d.Set("onetime_credentials", instance.OnetimeCredentials)
if instance.Parameters != nil {
if endpoint, ok := instance.Parameters["service-endpoints"]; ok {
d.Set("service_endpoints", endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,46 @@ func testAccCheckIBMResourceInstanceServiceendpoints(serviceName string) string

`, serviceName)
}

// /#### Adding new test case for onetime_credentials
func TestAccIBMResourceInstanceWithOnetimeCredentials(t *testing.T) {
serviceName := fmt.Sprintf("tf-Pgress-%d", acctest.RandIntRange(10, 100))
resourceName := "ibm_resource_instance.instance"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMResourceInstanceDestroy,
Steps: []resource.TestStep{

{
Config: testAccCheckIBMResourceInstanceOnetimeCredentals(serviceName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIBMResourceInstanceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", serviceName),
resource.TestCheckResourceAttr(resourceName, "service", "cloud-object-storage"),
resource.TestCheckResourceAttr(resourceName, "plan", "lite"),
resource.TestCheckResourceAttr(resourceName, "location", "global"),
),
},
},
})
}

func testAccCheckIBMResourceInstanceOnetimeCredentals(serviceName string) string {
return fmt.Sprintf(`

resource "ibm_resource_instance" "instance" {
name = "%s"
location = "global"
service = "cloud-object-storage"
plan = "lite"
parameters = {
onetime_credentials = true,
}


}

`, serviceName)
}
9 changes: 8 additions & 1 deletion ibm/service/resourcecontroller/resource_ibm_resource_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ func ResourceIBMResourceKey() *schema.Resource {
DiffSuppressFunc: flex.ApplyOnce,
Description: "Arbitrary parameters to pass. Must be a JSON object",
},

// ### Modification addded onetime_credentials to Resource scehama
"onetime_credentials": {
Type: schema.TypeBool,
Computed: true,
Description: "onetime_credentials of resource key",
},
"credentials": {
Description: "Credentials asociated with the key",
Type: schema.TypeMap,
Expand Down Expand Up @@ -366,6 +371,8 @@ func resourceIBMResourceKeyRead(d *schema.ResourceData, meta interface{}) error
d.Set("resource_group_id", *resourceKey.ResourceGroupID)
d.Set("source_crn", *resourceKey.SourceCRN)
d.Set("state", *resourceKey.State)
// ### Modificataion : Setting "onetime_credentials"
d.Set("onetime_credentials", *resourceKey.OnetimeCredentials)
d.Set("iam_compatible", *resourceKey.IamCompatible)
d.Set("resource_instance_url", *resourceKey.ResourceInstanceURL)
if resourceKey.CreatedAt != nil {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/resource_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ In addition to all argument reference list, you can access the following attribu
- `parameters_json` - (String) The parameters associated with the instance in json format.
- `plan` - (String) The plan for the service offering used by this resource instance.
- `status` - (String) The status of resource instance.
- `onetime_credentials` - (Bool) A boolean that dictates if the onetime_credentials is true or false.
1 change: 1 addition & 0 deletions website/docs/d/resource_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ In addition to all argument reference list, you can access the following attribu
- `id` - (String) The unique identifier of the resource key.
- `role` - (String) The user role.
- `status` - (String) The status of the resource key.
- `onetime_credentials` - (Bool) A boolean that dictates if the onetime_credentials is true or false.

## Note
Credentials will be seen as redacted, if the user does not have access equal to or greater than the access of the service credentials. Please refer to the documentation to access credentials - https://cloud.ibm.com/docs/account?topic=account-service_credentials&interface=ui#viewing-credentials-ui.
1 change: 1 addition & 0 deletions website/docs/r/resource_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,4 @@ In addition to all argument reference list, you can access the following attribu
- `type` - (String) The type of the instance. For example, `service_instance`.
- `update_at` - (Timestamp) The date when the instance last updated.
- `update_by` - (String) The subject who updated the instance.
- `onetime_credentials` - (Bool) A boolean that dictates if the onetime_credentials is true or false.
1 change: 1 addition & 0 deletions website/docs/r/resource_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ In addition to all argument reference list, you can access the following attribu
- `updated_at` - (Timestamp) The date when the key was last updated.
- `updated_by` - (String) The subject who updated the key.
- `url` - (String) When you created a new key, a relative URL path is created identifying the location of the key.
- `onetime_credentials` - (Bool) A boolean that dictates if the onetime_credentials is true or false.

## Note
Credentials will be seen as redacted, if the user does not have access equal to or greater than the access of the service credentials. Please refer to the documentation to access credentials - https://cloud.ibm.com/docs/account?topic=account-service_credentials&interface=ui#viewing-credentials-ui.
Loading