Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging options to AWS MQ #6122

Merged
merged 1 commit into from
Nov 1, 2018
Merged

Conversation

elbuo8
Copy link
Contributor

@elbuo8 elbuo8 commented Oct 11, 2018

Changes proposed in this pull request:

  • Add enable_logging flag to aws_mq_broker resource.
  • Add enable_auditing flag to aws_mq_broker resource.
  • Add missing property in instances to the aws_mq_broker data resource.

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSMq'
=== RUN   TestAccDataSourceAWSMqBroker_basic
--- PASS: TestAccDataSourceAWSMqBroker_basic (1320.48s)
=== RUN   TestResourceAWSMqBrokerPasswordValidation
--- PASS: TestResourceAWSMqBrokerPasswordValidation (0.00s)
=== RUN   TestAccAWSMqBroker_basic
--- PASS: TestAccAWSMqBroker_basic (965.95s)
=== RUN   TestAccAWSMqBroker_allFieldsDefaultVpc
--- PASS: TestAccAWSMqBroker_allFieldsDefaultVpc (1976.66s)
=== RUN   TestAccAWSMqBroker_allFieldsCustomVpc
--- PASS: TestAccAWSMqBroker_allFieldsCustomVpc (2081.69s)
=== RUN   TestAccAWSMqBroker_updateUsers
--- PASS: TestAccAWSMqBroker_updateUsers (1425.87s)

@ghost ghost added size/S Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/mq Issues and PRs that pertain to the mq service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 11, 2018
Copy link
Contributor

@joestump joestump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit on the exposed HCL. My non-maintainer opinion can be taken with a grain of salt. 😄

aws/data_source_aws_mq_broker.go Show resolved Hide resolved
@bflad
Copy link
Contributor

bflad commented Oct 31, 2018

Hi @elbuo8 👋 Are you still planning on changing the implementation to match the API? Here's some example code that might help:

Schema attribute declaration (swap Optional: true for Computed: true everywhere in the data source):

"logs": {
	Type:     schema.TypeList,
	Optional: true,
	MaxItems: 1,
	// Ignore missing configuration block
	DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
		if old == "1" && new == "0" {
			return true
		}
		return false
	},
	Elem: &schema.Resource{
	Schema: map[string]*schema.Schema{
		"audit": {
			Type:     schema.TypeBool,
			Optional: true,
		},
		"general": {
			Type:     schema.TypeBool,
			Optional: true,
		},
	},
},

Creating/updating:

func expandMqLogs(l []interface{}) *mq.Logs {
	if len(l) == 0 || l[0] == nil {
		return nil
	}

	m := l[0].(map[string]interface{})

	logs := &mq.Logs{
		Audit: aws.Bool(m["audit"].(bool)),
		General: aws.Bool(m["general"].(bool)),
	}

	return logs
}

// In Create func
Logs: expandMqLogs(d.Get("logs").([]interface{}))

Reading:

func flattenMqLogs(logs *mq.Logs) []interface{} {
	if logs == nil {
		return []interface{}{}
	}

	m := map[string]interface{}{
		"audit": aws.BoolValue(logs.Audit),
		"general": aws.BoolValue(logs.General),
	}

	return []interface{}{m}
}

// In Read func
if err := d.Set("logs", flattenMqLogs(out.Logs)); err != nil {
	return fmt.Errorf("error setting logs: %s", err)
}

Testing:

resource.TestCheckResourceAttr(resourceName, "logs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logs.audit", "false"),
resource.TestCheckResourceAttr(resourceName, "logs.general", "false"),

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 31, 2018
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Nov 1, 2018
@elbuo8
Copy link
Contributor Author

elbuo8 commented Nov 1, 2018

@bflad 🙇 updated with your changes.

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Nov 1, 2018
@bflad bflad added this to the v1.43.0 milestone Nov 1, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this, @elbuo8! LGTM with a few minor fixes, which I will put in a commit after yours. 🚀

--- PASS: TestAccAWSMqBroker_basic (1079.21s)
--- PASS: TestAccDataSourceAWSMqBroker_basic (1462.77s)
--- PASS: TestAccAWSMqBroker_updateUsers (1543.49s)
--- PASS: TestAccAWSMqBroker_allFieldsDefaultVpc (2039.54s)
--- PASS: TestAccAWSMqBroker_allFieldsCustomVpc (2091.40s)

@@ -277,13 +304,19 @@ func resourceAwsMqBrokerRead(d *schema.ResourceData, meta interface{}) error {
d.Set("engine_version", out.EngineVersion)
d.Set("host_instance_type", out.HostInstanceType)
d.Set("publicly_accessible", out.PubliclyAccessible)
d.Set("enable_logging", out.Logs.General)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be removed 😉

@@ -328,6 +361,16 @@ func resourceAwsMqBrokerUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if d.HasChange("logs") {
_, err := conn.UpdateBroker(&mq.UpdateBrokerRequest{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are multiple updates that call the same update API call, we generally combine the requests 👍

@@ -62,6 +62,7 @@ The following arguments are supported:
* `security_groups` - (Required) The list of security group IDs assigned to the broker.
* `subnet_ids` - (Optional) The list of subnet IDs in which to launch the broker. A `SINGLE_INSTANCE` deployment requires one subnet. An `ACTIVE_STANDBY_MULTI_AZ` deployment requires two subnets.
* `maintenance_window_start_time` - (Optional) Maintenance window start time. See below.
* `logging` - (Optional) Logging configuration of the broker. See below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was named logs in the last code update. 😄

@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Nov 1, 2018
@bflad bflad merged commit 03ea52a into hashicorp:master Nov 1, 2018
bflad added a commit that referenced this pull request Nov 1, 2018
```
--- PASS: TestAccAWSMqBroker_basic (1079.21s)
--- PASS: TestAccDataSourceAWSMqBroker_basic (1462.77s)
--- PASS: TestAccAWSMqBroker_updateUsers (1543.49s)
--- PASS: TestAccAWSMqBroker_allFieldsDefaultVpc (2039.54s)
--- PASS: TestAccAWSMqBroker_allFieldsCustomVpc (2091.40s)
```
bflad added a commit that referenced this pull request Nov 1, 2018
@bflad
Copy link
Contributor

bflad commented Nov 7, 2018

This has been released in version 1.43.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 2, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/mq Issues and PRs that pertain to the mq service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants