Skip to content

Commit

Permalink
add usage report resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Parfait committed Apr 8, 2021
1 parent aa8e4ce commit 55ff87c
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 6 deletions.
1 change: 1 addition & 0 deletions appstream/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Provider() terraform.ResourceProvider {
"appstream_stack": resourceAppstreamStack(),
"appstream_image_builder": resourceAppstreamImageBuilder(),
"appstream_fleet": resourceAppstreamFleet(),
"appstream_usage_report_subscription": resourceAppstreamUsageReportSubscription(),
},
}
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
Expand Down
93 changes: 93 additions & 0 deletions appstream/resource_usage_report_subscription.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package appstream

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appstream"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)


func resourceAppstreamUsageReportSubscription() *schema.Resource {
return &schema.Resource {
Create: resourceAppstreamUsageReportSubscriptionCreate,
Read: resourceAppstreamUsageReportSubscriptionRead,
Delete: resourceAppstreamUsageReportSubscriptionDelete,
Importer: &schema.ResourceImporter {
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"s3_bucket_name": {
Type: schema.TypeString,
Computed: true,
},
"schedule": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceAppstreamUsageReportSubscriptionCreate(d *schema.ResourceData, meta interface{}) error {

svc := meta.(*AWSClient).appstreamconn

CreateUsageReportSubscriptionInputOpts := &appstream.CreateUsageReportSubscriptionInput{}

log.Printf("[DEBUG] Run configuration: %s", CreateUsageReportSubscriptionInputOpts)

resp, err := svc.CreateUsageReportSubscription(CreateUsageReportSubscriptionInputOpts)

if err != nil {
log.Printf("[ERROR] Error creating Appstream Usage Report: %s", err)
return err
}

log.Printf("[DEBUG] Usage Report created %s", resp)

d.SetId(*resp.S3BucketName)
d.Set("s3_bucket_name", resp.S3BucketName)
d.Set("schedule", resp.Schedule)

return nil
}

func resourceAppstreamUsageReportSubscriptionRead(d *schema.ResourceData, meta interface{}) error {

svc := meta.(*AWSClient).appstreamconn

resp, err := svc.DescribeUsageReportSubscriptions(&appstream.DescribeUsageReportSubscriptionsInput{})
if err != nil {
log.Printf("[ERROR] Error describing Appstream Usage Reports Subscription: %s", err)
return err
}
for _, v := range resp.UsageReportSubscriptions {

if aws.StringValue(v.S3BucketName) == d.Get("s3_bucket_name") {
d.Set("s3_bucket_name", v.S3BucketName)
d.Set("schedule", v.Schedule)

return nil
}
}

d.SetId("")
return nil

}

func resourceAppstreamUsageReportSubscriptionDelete(d *schema.ResourceData, meta interface{}) error {
svc := meta.(*AWSClient).appstreamconn

del, err := svc.DeleteUsageReportSubscription(&appstream.DeleteUsageReportSubscriptionInput{})

if err != nil {
log.Printf("[ERROR] Error deleting Appstream Usage Report Subscription: %s", err)
return err
}
log.Printf("[DEBUG] %s", del)

return nil
}
2 changes: 1 addition & 1 deletion build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ node ("master") {
"GOPATH=${env.HOME}/go",
"GOBIN=${env.HOME}/go/bin",
]){
sh "go build -o ${env.HOME}/.terraform.d/plugins/terraform-provider-appstream_1.0.9"
sh "go build -o ${env.HOME}/.terraform.d/plugins/terraform-provider-appstream_1.0.10"
}
}
}
13 changes: 8 additions & 5 deletions examples/appstream.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
provider "appstream" {
version = "1.0.9"
assume_role {
role_arn = var.assume_role_arn
}
region = var.region_primary
version = "1.0.10"
// assume_role {
// role_arn = var.assume_role_arn
// }
// region = var.region_primary
}


Expand Down Expand Up @@ -63,3 +63,6 @@ resource "appstream_fleet" "test-fleet" {
}
state = "RUNNING"
}

resource "appstream_usage_report_subscription" "usage_report" {
}

0 comments on commit 55ff87c

Please sign in to comment.