Skip to content

Commit

Permalink
feat(ResourceController): Added onetime_credentials to ResourceInstan…
Browse files Browse the repository at this point in the history
…ce and ResourceKey read schemas

Signed-off-by: arshabbir <arshabbir@gmail.com>
  • Loading branch information
arshabbir committed Jul 26, 2024
1 parent 67305d7 commit a450a02
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
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

0 comments on commit a450a02

Please sign in to comment.