forked from arnvid/terraform-provider-appstream
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolas Parfait
committed
Apr 8, 2021
1 parent
aa8e4ce
commit 55ff87c
Showing
4 changed files
with
103 additions
and
6 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,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 | ||
} |
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