Skip to content

Commit

Permalink
Merge pull request #4 from umich-vci/cloud_access2
Browse files Browse the repository at this point in the history
Add support for Red Hat Cloud Access
  • Loading branch information
kenmoore25 authored Oct 16, 2020
2 parents 123f3c6 + b48f930 commit a400c54
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ A Terraform provider for Red Hat Subscription Manager (RHSM)
This provider can be used to create and manage allocations, entitlements, and manifests for Red Hat Subscriptions
that can be used with Red Hat Satellite.

Support will be added in the future to manage Red Hat Cloud Access entitlements for cloud accounts.
It can also be used to manage Red Hat Cloud Access for various cloud provider accounts. Requesting access to
gold images is supported as well, but presently is only supported on Azure by Red Hat.

The provider does not have working tests so it should probably be considered beta.

## Building/Installing

The provider is now available on the [Terraform Registry](https://registry.terraform.io/providers/umich-vci/rhsm/latest) so you probably don't need to build the provider.
The provider is now available on the [Terraform Registry](https://registry.terraform.io/providers/umich-vci/rhsm/latest) so you probably don't need to build the provider unless you want to contribute.

That said, running `GO111MODULE=on go get -u github.com/umich-vci/terraform-provider-rhsm` should download
the code and result in a binary at `$GOPATH/bin/terraform-provider-rhsm`. You can then move the
binary to `~/.terraform.d/plugins` to use it with Terraform.

This has been tested with Terraform 0.12.x and Red Hat Satellite 6.6.x and 6.7.x.
This has been tested with Terraform 0.12.x.

## License

Expand Down
44 changes: 44 additions & 0 deletions docs/data-sources/cloud_access.md
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.
33 changes: 33 additions & 0 deletions docs/resources/cloud_access_account.md
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.
140 changes: 140 additions & 0 deletions rhsm/data_source_cloud_access.go
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
}
2 changes: 2 additions & 0 deletions rhsm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ func Provider() *schema.Provider {
"rhsm_allocation": resourceAllocation(),
"rhsm_allocation_entitlement": resourceAllocationEntitlement(),
"rhsm_allocation_manifest": resourceAllocationManifest(),
"rhsm_cloud_access_account": resourceCloudAccessAccount(),
},
DataSourcesMap: map[string]*schema.Resource{
"rhsm_allocation": dataSourceAllocation(),
"rhsm_allocation_entitlement": dataSourceAllocationEntitlement(),
"rhsm_allocation_pools": dataSourceAllocationPools(),
"rhsm_cloud_access": dataSourceCloudAccess(),
},
ConfigureFunc: providerConfigure,
}
Expand Down
Loading

0 comments on commit a400c54

Please sign in to comment.