-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from umich-vci/cloud_access2
Add support for Red Hat Cloud Access
- Loading branch information
Showing
6 changed files
with
451 additions
and
3 deletions.
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
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,44 @@ | ||
# rhsm\_cloud\_access Data Source | ||
|
||
Use this data source to look up information about cloud providers entitled to Red Hat Cloud Access. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "rhsm_cloud_access" "ca" {} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
* `enabled_accounts` - A list where each entry is a single cloud provider | ||
|
||
In each element of `enabled_accounts` are the following attributes: | ||
|
||
* `accounts` - A list of cloud accounts that are enabled for cloud access in the cloud provider. | ||
|
||
* `id` - The id of the cloud | ||
|
||
* `date_added` - The date the account was added to cloud access. | ||
|
||
* `gold_image_status` - The status of any requests for gold image access for a cloud account. | ||
|
||
* `nickname` - A nickname associated with the cloud account. | ||
|
||
* `name` - The name of the cloud provider. | ||
|
||
* `products` - A list of products that are entitled to the cloud provider. | ||
|
||
* `enabled_quantity` - The quantity of subscriptions allowed to be consumed by the cloud provider. | ||
|
||
* `image_groups` - A list of images associated with the cloud provider. These are used when | ||
requesting access to gold images for a cloud account. | ||
|
||
* `name` - The name of the product. | ||
|
||
* `next_renewal` - The renewal date of the subscription. | ||
|
||
* `sku` - The SKU of the product. | ||
|
||
* `total_quantity` - The total number of subscriptions of the product available. | ||
|
||
* `short_name` - An abreviation of the cloud provider name. Used when adding or removing accounts. |
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,33 @@ | ||
# rhsm\_cloud\_access\_account Resource | ||
|
||
Use this resource to create an entitlement for Red Hat Cloud Access for an account in a supported cloud provider. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "rhsm_cloud_access_account" "test_account" { | ||
account_id = "123e4567-e89b-12d3-a456-426614174000" | ||
provider_short_name = "MSAZ" | ||
nickname = "Test Account" | ||
gold_images = ["rhel-byos"] | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `account_id` - (Required) The ID of a cloud account that you would like to request Red Hat Cloud Access for. | ||
|
||
* `provider_short_name` - (Required) The short name of the cloud provider that the `account_id` is in. | ||
This must be one of "AWS", "GCE", or "MSAZ". Other cloud providers are supported but have not been tested | ||
so they are not in the list of valid options. | ||
|
||
* `nickname` - (Optional) A nickname to help describe the account. The default is an empty string. | ||
|
||
* `gold_images` - (Optional) A list of gold images to request access to for the account. | ||
Images available to a cloud provider can be found with the `rhsm_cloud_access` data source. | ||
|
||
## Attributes Reference | ||
|
||
* `date_added` - The date the cloud account was added to Red Hat Cloud Access. | ||
|
||
* `gold_image_status` - The status of requests for access to gold images. |
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,140 @@ | ||
package rhsm | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceCloudAccess() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCloudAccessRead, | ||
Schema: map[string]*schema.Schema{ | ||
"enabled_accounts": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"accounts": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"date_added": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"gold_image_status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"nickname": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"products": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"enabled_quantity": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"image_groups": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: schema.TypeString, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"next_renewal": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sku": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"total_quantity": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"short_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudAccessRead(d *schema.ResourceData, meta interface{}) error { | ||
client, auth, err := meta.(*Config).Client() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cap, _, err := client.CloudaccessApi.ListEnabledCloudAccessProviders(auth) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cloudProviders := make([]map[string]interface{}, 0) | ||
|
||
for _, x := range cap.Body { | ||
cloudProvider := make(map[string]interface{}) | ||
cloudProvider["name"] = x.Name | ||
cloudProvider["short_name"] = x.ShortName | ||
|
||
accounts := make([]map[string]interface{}, 0) | ||
for _, y := range x.Accounts { | ||
account := make(map[string]interface{}) | ||
account["id"] = y.Id | ||
account["nickname"] = y.Nickname | ||
account["date_added"] = y.DateAdded | ||
account["gold_image_status"] = y.GoldImageStatus | ||
accounts = append(accounts, account) | ||
} | ||
cloudProvider["accounts"] = accounts | ||
|
||
products := make([]map[string]interface{}, 0) | ||
for _, y := range x.Products { | ||
product := make(map[string]interface{}) | ||
product["name"] = y.Name | ||
product["sku"] = y.Sku | ||
product["enabled_quantity"] = y.EnabledQuantity | ||
product["total_quantity"] = y.TotalQuantity | ||
product["image_groups"] = y.ImageGroups | ||
product["next_renewal"] = y.NextRenewal | ||
products = append(products, product) | ||
} | ||
cloudProvider["products"] = products | ||
|
||
cloudProviders = append(cloudProviders, cloudProvider) | ||
} | ||
|
||
d.SetId(time.Now().UTC().String()) | ||
|
||
d.Set("enabled_accounts", cloudProviders) | ||
|
||
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
Oops, something went wrong.