-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
r/redshift_cluster: Nest all logging fields #2230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,22 +219,54 @@ func resourceAwsRedshiftCluster() *schema.Resource { | |
Set: schema.HashString, | ||
}, | ||
|
||
"enable_logging": { | ||
Type: schema.TypeBool, | ||
"logging": { | ||
Type: schema.TypeList, | ||
MaxItems: 1, | ||
Optional: true, | ||
Default: false, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"enable": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
}, | ||
|
||
"bucket_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"s3_key_prefix": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"enable_logging": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Computed: true, | ||
Deprecated: "Use enable in the 'logging' block instead", | ||
ConflictsWith: []string{"logging"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make more sense to make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's no harm in conflicting with the whole |
||
}, | ||
|
||
"bucket_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Deprecated: "Use bucket_name in the 'logging' block instead", | ||
ConflictsWith: []string{"logging"}, | ||
}, | ||
|
||
"s3_key_prefix": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Deprecated: "Use s3_key_prefix in the 'logging' block instead", | ||
ConflictsWith: []string{"logging"}, | ||
}, | ||
|
||
"snapshot_identifier": { | ||
|
@@ -439,8 +471,9 @@ func resourceAwsRedshiftClusterCreate(d *schema.ResourceData, meta interface{}) | |
return fmt.Errorf("[WARN] Error waiting for Redshift Cluster state to be \"available\": %s", err) | ||
} | ||
|
||
if _, ok := d.GetOk("enable_logging"); ok { | ||
|
||
logging, ok := d.GetOk("logging.0.enable") | ||
_, deprecatedOk := d.GetOk("enable_logging") | ||
if (ok && logging.(bool)) || deprecatedOk { | ||
loggingErr := enableRedshiftClusterLogging(d, conn) | ||
if loggingErr != nil { | ||
log.Printf("[ERROR] Error Enabling Logging on Redshift Cluster: %s", err) | ||
|
@@ -553,10 +586,13 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er | |
d.Set("cluster_revision_number", rsc.ClusterRevisionNumber) | ||
d.Set("tags", tagsToMapRedshift(rsc.Tags)) | ||
|
||
// TODO: Deprecated fields - remove in next major version | ||
d.Set("bucket_name", loggingStatus.BucketName) | ||
d.Set("enable_logging", loggingStatus.LoggingEnabled) | ||
d.Set("s3_key_prefix", loggingStatus.S3KeyPrefix) | ||
|
||
d.Set("logging", flattenRedshiftLogging(loggingStatus)) | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -711,17 +747,20 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) | |
} | ||
} | ||
|
||
if d.HasChange("enable_logging") || d.HasChange("bucket_name") || d.HasChange("s3_key_prefix") { | ||
deprecatedHasChange := (d.HasChange("enable_logging") || d.HasChange("bucket_name") || d.HasChange("s3_key_prefix")) | ||
if d.HasChange("logging") || deprecatedHasChange { | ||
var loggingErr error | ||
if _, ok := d.GetOk("enable_logging"); ok { | ||
|
||
logging, ok := d.GetOk("logging.0.enable") | ||
_, deprecatedOk := d.GetOk("enable_logging") | ||
|
||
if (ok && logging.(bool)) || deprecatedOk { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want to check the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is a boolean field it shouldn't matter, b/c it will always be present - that is in fact why we introduced |
||
log.Printf("[INFO] Enabling Logging for Redshift Cluster %q", d.Id()) | ||
loggingErr = enableRedshiftClusterLogging(d, conn) | ||
if loggingErr != nil { | ||
return loggingErr | ||
} | ||
} else { | ||
|
||
log.Printf("[INFO] Disabling Logging for Redshift Cluster %q", d.Id()) | ||
_, loggingErr = conn.DisableLogging(&redshift.DisableLoggingInput{ | ||
ClusterIdentifier: aws.String(d.Id()), | ||
|
@@ -732,6 +771,7 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) | |
} | ||
|
||
d.SetPartial("enable_logging") | ||
d.SetPartial("logging") | ||
} | ||
|
||
d.Partial(false) | ||
|
@@ -740,17 +780,30 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) | |
} | ||
|
||
func enableRedshiftClusterLogging(d *schema.ResourceData, conn *redshift.Redshift) error { | ||
if _, ok := d.GetOk("bucket_name"); !ok { | ||
var bucketName, v interface{} | ||
var deprecatedOk, ok bool | ||
bucketName, deprecatedOk = d.GetOk("bucket_name") | ||
v, ok = d.GetOk("logging.0.bucket_name") | ||
if ok { | ||
bucketName = v | ||
} | ||
if !ok && !deprecatedOk { | ||
return fmt.Errorf("bucket_name must be set when enabling logging for Redshift Clusters") | ||
} | ||
|
||
params := &redshift.EnableLoggingInput{ | ||
ClusterIdentifier: aws.String(d.Id()), | ||
BucketName: aws.String(d.Get("bucket_name").(string)), | ||
BucketName: aws.String(bucketName.(string)), | ||
} | ||
|
||
if v, ok := d.GetOk("s3_key_prefix"); ok { | ||
params.S3KeyPrefix = aws.String(v.(string)) | ||
var s3KeyPrefix interface{} | ||
s3KeyPrefix, deprecatedOk = d.GetOk("s3_key_prefix") | ||
v, ok = d.GetOk("logging.0.s3_key_prefix") | ||
if ok { | ||
s3KeyPrefix = v | ||
} | ||
if ok || deprecatedOk { | ||
params.S3KeyPrefix = aws.String(s3KeyPrefix.(string)) | ||
} | ||
|
||
_, loggingErr := conn.EnableLogging(params) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this not need a State Migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so - it's only required within the context of
logging
block, i.e. you can't define an emptylogging {}
, it shouldn't affect any existing configs without this block.