From 67231200192b62b6138efa5046fbe9d507cc9f87 Mon Sep 17 00:00:00 2001 From: Gareth Oakley Date: Wed, 12 Dec 2018 21:35:49 +0000 Subject: [PATCH 1/3] r/aws_licensemanager: Add aws_licensemanager_license_configuration --- aws/config.go | 3 + aws/provider.go | 1 + ...ws_licensemanager_license_configuration.go | 189 ++++++++++++++++++ ...censemanager_license_configuration_test.go | 161 +++++++++++++++ aws/tagsLicenseManager.go | 115 +++++++++++ ...ensemanager_license_configuration.markdown | 57 ++++++ 6 files changed, 526 insertions(+) create mode 100644 aws/resource_aws_licensemanager_license_configuration.go create mode 100644 aws/resource_aws_licensemanager_license_configuration_test.go create mode 100644 aws/tagsLicenseManager.go create mode 100644 website/docs/r/licensemanager_license_configuration.markdown diff --git a/aws/config.go b/aws/config.go index 35b9cc1099b..d07ba68b3ce 100644 --- a/aws/config.go +++ b/aws/config.go @@ -74,6 +74,7 @@ import ( "github.com/aws/aws-sdk-go/service/kms" "github.com/aws/aws-sdk-go/service/lambda" "github.com/aws/aws-sdk-go/service/lexmodelbuildingservice" + "github.com/aws/aws-sdk-go/service/licensemanager" "github.com/aws/aws-sdk-go/service/lightsail" "github.com/aws/aws-sdk-go/service/macie" "github.com/aws/aws-sdk-go/service/mediastore" @@ -222,6 +223,7 @@ type AWSClient struct { elasticbeanstalkconn *elasticbeanstalk.ElasticBeanstalk elastictranscoderconn *elastictranscoder.ElasticTranscoder lambdaconn *lambda.Lambda + licensemanagerconn *licensemanager.LicenseManager lightsailconn *lightsail.Lightsail macieconn *macie.Macie mqconn *mq.MQ @@ -552,6 +554,7 @@ func (c *Config) Client() (interface{}, error) { client.kmsconn = kms.New(awsKmsSess) client.lambdaconn = lambda.New(awsLambdaSess) client.lexmodelconn = lexmodelbuildingservice.New(sess) + client.licensemanagerconn = licensemanager.New(sess) client.lightsailconn = lightsail.New(sess) client.macieconn = macie.New(sess) client.mqconn = mq.New(sess) diff --git a/aws/provider.go b/aws/provider.go index 398ce94e55b..23432689ced 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -527,6 +527,7 @@ func Provider() terraform.ResourceProvider { "aws_lambda_permission": resourceAwsLambdaPermission(), "aws_launch_configuration": resourceAwsLaunchConfiguration(), "aws_launch_template": resourceAwsLaunchTemplate(), + "aws_licensemanager_license_configuration": resourceAwsLicenseManagerLicenseConfiguration(), "aws_lightsail_domain": resourceAwsLightsailDomain(), "aws_lightsail_instance": resourceAwsLightsailInstance(), "aws_lightsail_key_pair": resourceAwsLightsailKeyPair(), diff --git a/aws/resource_aws_licensemanager_license_configuration.go b/aws/resource_aws_licensemanager_license_configuration.go new file mode 100644 index 00000000000..cc7df4c328c --- /dev/null +++ b/aws/resource_aws_licensemanager_license_configuration.go @@ -0,0 +1,189 @@ +package aws + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/licensemanager" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" +) + +func resourceAwsLicenseManagerLicenseConfiguration() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsLicenseManagerLicenseConfigurationCreate, + Read: resourceAwsLicenseManagerLicenseConfigurationRead, + Update: resourceAwsLicenseManagerLicenseConfigurationUpdate, + Delete: resourceAwsLicenseManagerLicenseConfigurationDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "description": { + Type: schema.TypeString, + Optional: true, + }, + "license_count": { + Type: schema.TypeInt, + Optional: true, + }, + "license_count_hard_limit": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "license_counting_type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + licensemanager.LicenseCountingTypeVCpu, + licensemanager.LicenseCountingTypeInstance, + licensemanager.LicenseCountingTypeCore, + licensemanager.LicenseCountingTypeSocket, + }, false), + }, + "license_rules": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "tags": tagsSchema(), + }, + } +} + +func resourceAwsLicenseManagerLicenseConfigurationCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).licensemanagerconn + + opts := &licensemanager.CreateLicenseConfigurationInput{ + LicenseCountingType: aws.String(d.Get("license_counting_type").(string)), + Name: aws.String(d.Get("name").(string)), + } + + if v, ok := d.GetOk("description"); ok { + opts.Description = aws.String(v.(string)) + } + + if v, ok := d.GetOk("license_count"); ok { + opts.LicenseCount = aws.Int64(int64(v.(int))) + } + + if v, ok := d.GetOk("license_count_hard_limit"); ok { + opts.LicenseCountHardLimit = aws.Bool(v.(bool)) + } + + if v, ok := d.GetOk("license_rules"); ok { + opts.LicenseRules = expandStringList(v.([]interface{})) + } + + if v, ok := d.GetOk("tags"); ok && len(v.(map[string]interface{})) > 0 { + opts.Tags = tagsFromMapLicenseManager(v.(map[string]interface{})) + } + + log.Printf("[DEBUG] License Manager license configuration: %s", opts) + + resp, err := conn.CreateLicenseConfiguration(opts) + if err != nil { + return fmt.Errorf("Error creating License Manager license configuration: %s", err) + } + d.SetId(*resp.LicenseConfigurationArn) + return resourceAwsLicenseManagerLicenseConfigurationRead(d, meta) +} + +func resourceAwsLicenseManagerLicenseConfigurationRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).licensemanagerconn + + resp, err := conn.GetLicenseConfiguration(&licensemanager.GetLicenseConfigurationInput{ + LicenseConfigurationArn: aws.String(d.Id()), + }) + + if err != nil { + if isAWSErr(err, licensemanager.ErrCodeInvalidParameterValueException, "") { + log.Printf("[WARN] License Manager license configuration (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading License Manager license configuration: %s", err) + } + + d.Set("description", resp.Description) + d.Set("license_count", resp.LicenseCount) + d.Set("license_count_hard_limit", resp.LicenseCountHardLimit) + d.Set("license_counting_type", resp.LicenseCountingType) + d.Set("license_rules", flattenStringList(resp.LicenseRules)) + d.Set("name", resp.Name) + + if err := d.Set("tags", tagsToMapLicenseManager(resp.Tags)); err != nil { + return fmt.Errorf("error setting tags: %s", err) + } + + return nil +} + +func resourceAwsLicenseManagerLicenseConfigurationUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).licensemanagerconn + + d.Partial(true) + + if d.HasChange("tags") { + if err := setTagsLicenseManager(conn, d); err != nil { + return err + } else { + d.SetPartial("tags") + } + } + + d.Partial(false) + + opts := &licensemanager.UpdateLicenseConfigurationInput{ + LicenseConfigurationArn: aws.String(d.Id()), + Name: aws.String(d.Get("name").(string)), + } + + if v, ok := d.GetOk("description"); ok { + opts.Description = aws.String(v.(string)) + } + + if v, ok := d.GetOk("license_count"); ok { + opts.LicenseCount = aws.Int64(int64(v.(int))) + } + + if v, ok := d.GetOk("license_count_hard_limit"); ok { + opts.LicenseCountHardLimit = aws.Bool(v.(bool)) + } + + log.Printf("[DEBUG] License Manager license configuration: %s", opts) + + _, err := conn.UpdateLicenseConfiguration(opts) + if err != nil { + return fmt.Errorf("Error updating License Manager license configuration: %s", err) + } + return resourceAwsLicenseManagerLicenseConfigurationRead(d, meta) +} + +func resourceAwsLicenseManagerLicenseConfigurationDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).licensemanagerconn + + opts := &licensemanager.DeleteLicenseConfigurationInput{ + LicenseConfigurationArn: aws.String(d.Id()), + } + + _, err := conn.DeleteLicenseConfiguration(opts) + if err != nil { + if isAWSErr(err, licensemanager.ErrCodeInvalidParameterValueException, "") { + log.Printf("[WARN] License Manager license configuration (%s) not found", d.Id()) + return nil + } + return fmt.Errorf("Error deleting License Manager license configuration: %s", err) + } + + return nil +} diff --git a/aws/resource_aws_licensemanager_license_configuration_test.go b/aws/resource_aws_licensemanager_license_configuration_test.go new file mode 100644 index 00000000000..19a312cdba0 --- /dev/null +++ b/aws/resource_aws_licensemanager_license_configuration_test.go @@ -0,0 +1,161 @@ +package aws + +import ( + "fmt" + "log" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/licensemanager" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func init() { + resource.AddTestSweepers("aws_licensemanager_license_configuration", &resource.Sweeper{ + Name: "aws_licensemanager_license_configuration", + F: testSweepLicenseManagerLicenseConfigurations, + }) +} + +func testSweepLicenseManagerLicenseConfigurations(region string) error { + client, err := sharedClientForRegion(region) + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } + conn := client.(*AWSClient).licensemanagerconn + + resp, err := conn.ListLicenseConfigurations(&licensemanager.ListLicenseConfigurationsInput{}) + + if err != nil { + return fmt.Errorf("Error retrieving License Manager license configurations: %s", err) + } + + if len(resp.LicenseConfigurations) == 0 { + log.Print("[DEBUG] No License Manager license configurations to sweep") + return nil + } + + for _, lc := range resp.LicenseConfigurations { + id := aws.StringValue(lc.LicenseConfigurationArn) + + log.Printf("[INFO] Deleting License Manager license configuration: %s", id) + + opts := &licensemanager.DeleteLicenseConfigurationInput{ + LicenseConfigurationArn: aws.String(id), + } + + _, err := conn.DeleteLicenseConfiguration(opts) + + if err != nil { + log.Printf("[ERROR] Error deleting License Manager license configuration (%s): %s", id, err) + } + } + + return nil +} + +func TestAccAWSLicenseManagerLicenseConfiguration_basic(t *testing.T) { + var licenseConfiguration licensemanager.LicenseConfiguration + resourceName := "aws_licensemanager_license_configuration.example" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLicenseManagerLicenseConfigurationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLicenseManagerLicenseConfigurationConfig_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckLicenseManagerLicenseConfigurationExists(resourceName, &licenseConfiguration), + resource.TestCheckResourceAttr(resourceName, "name", "Example"), + resource.TestCheckResourceAttr(resourceName, "description", "Example"), + resource.TestCheckResourceAttr(resourceName, "license_count", "10"), + resource.TestCheckResourceAttr(resourceName, "license_count_hard_limit", "true"), + resource.TestCheckResourceAttr(resourceName, "license_counting_type", "Socket"), + resource.TestCheckResourceAttr(resourceName, "license_rules.#", "1"), + resource.TestCheckResourceAttr(resourceName, "license_rules.0", "#minimumSockets=3"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.foo", "barr"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckLicenseManagerLicenseConfigurationExists(resourceName string, licenseConfiguration *licensemanager.LicenseConfiguration) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No ID is set") + } + + conn := testAccProvider.Meta().(*AWSClient).licensemanagerconn + resp, err := conn.ListLicenseConfigurations(&licensemanager.ListLicenseConfigurationsInput{ + LicenseConfigurationArns: [](*string){aws.String(rs.Primary.ID)}, + }) + + if err != nil { + return fmt.Errorf("Error retrieving License Manager license configuration (%s): %s", rs.Primary.ID, err) + } + + if len(resp.LicenseConfigurations) == 0 { + return fmt.Errorf("Error retrieving License Manager license configuration (%s): Not found", rs.Primary.ID) + } + + *licenseConfiguration = *resp.LicenseConfigurations[0] + return nil + } +} + +func testAccCheckLicenseManagerLicenseConfigurationDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).licensemanagerconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_licensemanager_license_configuration" { + continue + } + + // Try to find the resource + _, err := conn.GetLicenseConfiguration(&licensemanager.GetLicenseConfigurationInput{ + LicenseConfigurationArn: aws.String(rs.Primary.ID), + }) + + if err != nil { + if isAWSErr(err, licensemanager.ErrCodeInvalidParameterValueException, "") { + continue + } + return err + } + } + + return nil + +} + +const testAccLicenseManagerLicenseConfigurationConfig_basic = ` +resource "aws_licensemanager_license_configuration" "example" { + name = "Example" + description = "Example" + license_count = 10 + license_count_hard_limit = true + license_counting_type = "Socket" + + license_rules = [ + "#minimumSockets=3" + ] + + tags { + foo = "barr" + } +} +` diff --git a/aws/tagsLicenseManager.go b/aws/tagsLicenseManager.go new file mode 100644 index 00000000000..02c183d12fb --- /dev/null +++ b/aws/tagsLicenseManager.go @@ -0,0 +1,115 @@ +package aws + +import ( + "log" + "regexp" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/licensemanager" + "github.com/hashicorp/terraform/helper/schema" +) + +// setTags is a helper to set the tags for a resource. It expects the +// tags field to be named "tags" +func setTagsLicenseManager(conn *licensemanager.LicenseManager, d *schema.ResourceData) error { + if d.HasChange("tags") { + oraw, nraw := d.GetChange("tags") + o := oraw.(map[string]interface{}) + n := nraw.(map[string]interface{}) + create, remove := diffTagsLicenseManager(tagsFromMapLicenseManager(o), tagsFromMapLicenseManager(n)) + + // Set tags + if len(remove) > 0 { + log.Printf("[DEBUG] Removing tags: %#v", remove) + k := make([]*string, len(remove), len(remove)) + for i, t := range remove { + k[i] = t.Key + } + + _, err := conn.UntagResource(&licensemanager.UntagResourceInput{ + ResourceArn: aws.String(d.Id()), + TagKeys: k, + }) + if err != nil { + return err + } + } + if len(create) > 0 { + log.Printf("[DEBUG] Creating tags: %#v", create) + _, err := conn.TagResource(&licensemanager.TagResourceInput{ + ResourceArn: aws.String(d.Id()), + Tags: create, + }) + if err != nil { + return err + } + } + } + + return nil +} + +// diffTags takes our tags locally and the ones remotely and returns +// the set of tags that must be created, and the set of tags that must +// be destroyed. +func diffTagsLicenseManager(oldTags, newTags []*licensemanager.Tag) ([]*licensemanager.Tag, []*licensemanager.Tag) { + // First, we're creating everything we have + create := make(map[string]interface{}) + for _, t := range newTags { + create[*t.Key] = *t.Value + } + + // Build the list of what to remove + var remove []*licensemanager.Tag + for _, t := range oldTags { + old, ok := create[*t.Key] + if !ok || old != *t.Value { + // Delete it! + remove = append(remove, t) + } + } + + return tagsFromMapLicenseManager(create), remove +} + +// tagsFromMap returns the tags for the given map of data. +func tagsFromMapLicenseManager(m map[string]interface{}) []*licensemanager.Tag { + result := make([]*licensemanager.Tag, 0, len(m)) + for k, v := range m { + t := &licensemanager.Tag{ + Key: aws.String(k), + Value: aws.String(v.(string)), + } + if !tagIgnoredLicenseManager(t) { + result = append(result, t) + } + } + + return result +} + +// tagsToMap turns the list of tags into a map. +func tagsToMapLicenseManager(ts []*licensemanager.Tag) map[string]string { + result := make(map[string]string) + for _, t := range ts { + if !tagIgnoredLicenseManager(t) { + result[*t.Key] = *t.Value + } + } + + return result +} + +// compare a tag against a list of strings and checks if it should +// be ignored or not +func tagIgnoredLicenseManager(t *licensemanager.Tag) bool { + filter := []string{"^aws:"} + for _, v := range filter { + log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) + if r, _ := regexp.MatchString(v, *t.Key); r == true { + log.Printf("[DEBUG] Found AWS specific tag %s (val: %s), ignoring.\n", *t.Key, *t.Value) + return true + } + } + return false +} diff --git a/website/docs/r/licensemanager_license_configuration.markdown b/website/docs/r/licensemanager_license_configuration.markdown new file mode 100644 index 00000000000..8c473b0b829 --- /dev/null +++ b/website/docs/r/licensemanager_license_configuration.markdown @@ -0,0 +1,57 @@ +--- +layout: "aws" +page_title: "AWS: aws_licensemanager_license_configuration" +sidebar_current: "docs-aws-resource-licensemanager-license-configuration" +description: |- + Provides a License Manager license configuration resource. +--- + +# aws_licensemanager_license_configuration + +Provides a License Manager license configuration resource. + +## Example Usage + +```hcl +resource "aws_licensemanager_license_configuration" "example" { + name = "Example" + description = "Example" + license_count = 10 + license_count_hard_limit = true + license_counting_type = "Socket" + + license_rules = [ + "#minimumSockets=2" + ] + + tags { + foo = "barr" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Name of the license configuration. +* `description` - (Optional) Description of the license configuration. +* `license_count` - (Optional) Number of licenses managed by the license configuration. +* `license_count_hard_limit` - (Optional) Sets the number of available licenses as a hard limit. +* `license_counting_type` - (Required) Dimension to use to track license inventory. Specify either `vCPU`, `Instance`, `Core` or `Socket`. +* `license_rules` - (Optional) Array of configured License Manager rules. +* `tags` - (Optional) A mapping of tags to assign to the resource. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The license configuration ARN. + +## Import + +License configurations can be imported using the `id`, e.g. + +``` +$ terraform import aws_licensemanager_license_configuration.example arn:aws:license-manager:eu-west-1:123456789012:license-configuration:lic-0123456789abcdef0123456789abcdef +``` From 8ce85f714f9f48257cc902bb0f068e731e43e203 Mon Sep 17 00:00:00 2001 From: Gareth Oakley Date: Fri, 14 Dec 2018 11:16:31 +0000 Subject: [PATCH 2/3] r/aws_licensemanager: Address comments on aws_licensemanager_license_configuration --- ...ws_licensemanager_license_configuration.go | 14 +++-- ...censemanager_license_configuration_test.go | 60 +++++++++++++++++++ website/aws.erb | 11 ++++ ...ensemanager_license_configuration.markdown | 12 ++++ 4 files changed, 92 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_licensemanager_license_configuration.go b/aws/resource_aws_licensemanager_license_configuration.go index cc7df4c328c..b08f55f7761 100644 --- a/aws/resource_aws_licensemanager_license_configuration.go +++ b/aws/resource_aws_licensemanager_license_configuration.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "regexp" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/licensemanager" @@ -49,7 +50,10 @@ func resourceAwsLicenseManagerLicenseConfiguration() *schema.Resource { Type: schema.TypeList, Optional: true, ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringMatch(regexp.MustCompile("^#([^=]+)=(.+)$"), "Expected format is #RuleType=RuleValue"), + }, }, "name": { Type: schema.TypeString, @@ -118,7 +122,9 @@ func resourceAwsLicenseManagerLicenseConfigurationRead(d *schema.ResourceData, m d.Set("license_count", resp.LicenseCount) d.Set("license_count_hard_limit", resp.LicenseCountHardLimit) d.Set("license_counting_type", resp.LicenseCountingType) - d.Set("license_rules", flattenStringList(resp.LicenseRules)) + if err := d.Set("license_rules", flattenStringList(resp.LicenseRules)); err != nil { + return fmt.Errorf("error setting license_rules: %s", err) + } d.Set("name", resp.Name) if err := d.Set("tags", tagsToMapLicenseManager(resp.Tags)); err != nil { @@ -136,9 +142,8 @@ func resourceAwsLicenseManagerLicenseConfigurationUpdate(d *schema.ResourceData, if d.HasChange("tags") { if err := setTagsLicenseManager(conn, d); err != nil { return err - } else { - d.SetPartial("tags") } + d.SetPartial("tags") } d.Partial(false) @@ -179,7 +184,6 @@ func resourceAwsLicenseManagerLicenseConfigurationDelete(d *schema.ResourceData, _, err := conn.DeleteLicenseConfiguration(opts) if err != nil { if isAWSErr(err, licensemanager.ErrCodeInvalidParameterValueException, "") { - log.Printf("[WARN] License Manager license configuration (%s) not found", d.Id()) return nil } return fmt.Errorf("Error deleting License Manager license configuration: %s", err) diff --git a/aws/resource_aws_licensemanager_license_configuration_test.go b/aws/resource_aws_licensemanager_license_configuration_test.go index 19a312cdba0..ab32840badb 100644 --- a/aws/resource_aws_licensemanager_license_configuration_test.go +++ b/aws/resource_aws_licensemanager_license_configuration_test.go @@ -28,6 +28,10 @@ func testSweepLicenseManagerLicenseConfigurations(region string) error { resp, err := conn.ListLicenseConfigurations(&licensemanager.ListLicenseConfigurationsInput{}) if err != nil { + if testSweepSkipSweepError(err) { + log.Printf("[WARN] Skipping License Manager License Configuration sweep for %s: %s", region, err) + return nil + } return fmt.Errorf("Error retrieving License Manager license configurations: %s", err) } @@ -88,6 +92,43 @@ func TestAccAWSLicenseManagerLicenseConfiguration_basic(t *testing.T) { }) } +func TestAccAWSLicenseManagerLicenseConfiguration_update(t *testing.T) { + var licenseConfiguration licensemanager.LicenseConfiguration + resourceName := "aws_licensemanager_license_configuration.example" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLicenseManagerLicenseConfigurationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLicenseManagerLicenseConfigurationConfig_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckLicenseManagerLicenseConfigurationExists(resourceName, &licenseConfiguration), + ), + }, + { + Config: testAccLicenseManagerLicenseConfigurationConfig_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckLicenseManagerLicenseConfigurationExists(resourceName, &licenseConfiguration), + resource.TestCheckResourceAttr(resourceName, "name", "NewName"), + resource.TestCheckResourceAttr(resourceName, "description", "NewDescription"), + resource.TestCheckResourceAttr(resourceName, "license_count", ""), + resource.TestCheckResourceAttr(resourceName, "license_count_hard_limit", "false"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.test", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.abc", "def"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckLicenseManagerLicenseConfigurationExists(resourceName string, licenseConfiguration *licensemanager.LicenseConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -159,3 +200,22 @@ resource "aws_licensemanager_license_configuration" "example" { } } ` + +const testAccLicenseManagerLicenseConfigurationConfig_update = ` +resource "aws_licensemanager_license_configuration" "example" { + name = "NewName" + description = "NewDescription" + # license_count = 99 + license_count_hard_limit = false + license_counting_type = "Socket" + + license_rules = [ + "#minimumSockets=3" + ] + + tags { + test = "test" + abc = "def" + } +} +` diff --git a/website/aws.erb b/website/aws.erb index 8b385476db6..91c3d5e64e5 100644 --- a/website/aws.erb +++ b/website/aws.erb @@ -1664,6 +1664,17 @@ + > + License Manager Resources + + + > Lightsail Resources