diff --git a/.changelog/19266.txt b/.changelog/19266.txt new file mode 100644 index 00000000000..9fb84153fb8 --- /dev/null +++ b/.changelog/19266.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_mwaa_environment: Correctly apply `plugins_s3_object_version` change +``` \ No newline at end of file diff --git a/aws/resource_aws_mwaa_environment.go b/aws/resource_aws_mwaa_environment.go index 3e586bd67a5..d913ee01be9 100644 --- a/aws/resource_aws_mwaa_environment.go +++ b/aws/resource_aws_mwaa_environment.go @@ -433,6 +433,10 @@ func resourceAwsMwaaEnvironmentUpdate(d *schema.ResourceData, meta interface{}) input.NetworkConfiguration = expandMwaaEnvironmentNetworkConfigurationUpdate(d.Get("network_configuration").([]interface{})) } + if d.HasChange("plugins_s3_object_version") { + input.PluginsS3ObjectVersion = aws.String(d.Get("plugins_s3_object_version").(string)) + } + if d.HasChange("plugins_s3_path") { input.PluginsS3Path = aws.String(d.Get("plugins_s3_path").(string)) } diff --git a/aws/resource_aws_mwaa_environment_test.go b/aws/resource_aws_mwaa_environment_test.go index 2e58405b671..7b3bdbbc400 100644 --- a/aws/resource_aws_mwaa_environment_test.go +++ b/aws/resource_aws_mwaa_environment_test.go @@ -61,7 +61,7 @@ func TestAccAWSMwaaEnvironment_basic(t *testing.T) { CheckDestroy: testAccCheckAWSMwaaEnvironmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSMwssEnvironmentBasicConfig(rName), + Config: testAccAWSMwaaEnvironmentBasicConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttrSet(resourceName, "airflow_version"), @@ -123,7 +123,7 @@ func TestAccAWSMwaaEnvironment_disappears(t *testing.T) { CheckDestroy: testAccCheckAWSMwaaEnvironmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSMwssEnvironmentBasicConfig(rName), + Config: testAccAWSMwaaEnvironmentBasicConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), testAccCheckResourceDisappears(testAccProvider, resourceAwsMwaaEnvironment(), resourceName), @@ -147,7 +147,7 @@ func TestAccAWSMwaaEnvironment_AirflowConfigurationOptions(t *testing.T) { CheckDestroy: testAccCheckAWSMwaaEnvironmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSMwssEnvironmentAirflowConfigurationOptionsConfig(rName, "1", "16"), + Config: testAccAWSMwaaEnvironmentAirflowConfigurationOptionsConfig(rName, "1", "16"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttr(resourceName, "airflow_configuration_options.%", "2"), @@ -161,7 +161,7 @@ func TestAccAWSMwaaEnvironment_AirflowConfigurationOptions(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSMwssEnvironmentAirflowConfigurationOptionsConfig(rName, "2", "32"), + Config: testAccAWSMwaaEnvironmentAirflowConfigurationOptionsConfig(rName, "2", "32"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttr(resourceName, "airflow_configuration_options.%", "2"), @@ -170,7 +170,7 @@ func TestAccAWSMwaaEnvironment_AirflowConfigurationOptions(t *testing.T) { ), }, { - Config: testAccAWSMwssEnvironmentBasicConfig(rName), + Config: testAccAWSMwaaEnvironmentBasicConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttr(resourceName, "airflow_configuration_options.%", "0"), @@ -193,7 +193,7 @@ func TestAccAWSMwaaEnvironment_LogConfiguration(t *testing.T) { CheckDestroy: testAccCheckAWSMwaaEnvironmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSMwssEnvironmentLoggingConfigurationConfig(rName, "true", mwaa.LoggingLevelCritical), + Config: testAccAWSMwaaEnvironmentLoggingConfigurationConfig(rName, "true", mwaa.LoggingLevelCritical), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), @@ -230,7 +230,7 @@ func TestAccAWSMwaaEnvironment_LogConfiguration(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSMwssEnvironmentLoggingConfigurationConfig(rName, "false", mwaa.LoggingLevelInfo), + Config: testAccAWSMwaaEnvironmentLoggingConfigurationConfig(rName, "false", mwaa.LoggingLevelInfo), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), @@ -278,7 +278,7 @@ func TestAccAWSMwaaEnvironment_full(t *testing.T) { CheckDestroy: testAccCheckAWSMwaaEnvironmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSMwssEnvironmentFullConfig(rName), + Config: testAccAWSMwaaEnvironmentFullConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), resource.TestCheckResourceAttr(resourceName, "airflow_configuration_options.%", "2"), @@ -339,6 +339,47 @@ func TestAccAWSMwaaEnvironment_full(t *testing.T) { }) } +func TestAccAWSMwaaEnvironment_PluginsS3ObjectVersion(t *testing.T) { + var environment mwaa.GetEnvironmentOutput + + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_mwaa_environment.test" + s3BucketObjectResourceName := "aws_s3_bucket_object.plugins" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, mwaa.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSMwaaEnvironmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSMwaaEnvironmentPluginsS3ObjectVersionConfig(rName, "test"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), + resource.TestCheckResourceAttrPair(resourceName, "plugins_s3_object_version", s3BucketObjectResourceName, "version_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSMwaaEnvironmentPluginsS3ObjectVersionConfig(rName, "test-updated"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSMwaaEnvironmentExists(resourceName, &environment), + resource.TestCheckResourceAttrPair(resourceName, "plugins_s3_object_version", s3BucketObjectResourceName, "version_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAWSMwaaEnvironmentExists(resourceName string, environment *mwaa.GetEnvironmentOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -574,7 +615,7 @@ POLICY `, rName) } -func testAccAWSMwssEnvironmentBasicConfig(rName string) string { +func testAccAWSMwaaEnvironmentBasicConfig(rName string) string { return testAccAWSMwaaEnvironmentBase(rName) + fmt.Sprintf(` resource "aws_mwaa_environment" "test" { dag_s3_path = aws_s3_bucket_object.dags.key @@ -591,7 +632,7 @@ resource "aws_mwaa_environment" "test" { `, rName) } -func testAccAWSMwssEnvironmentAirflowConfigurationOptionsConfig(rName, retries, parallelism string) string { +func testAccAWSMwaaEnvironmentAirflowConfigurationOptionsConfig(rName, retries, parallelism string) string { return testAccAWSMwaaEnvironmentBase(rName) + fmt.Sprintf(` resource "aws_mwaa_environment" "test" { airflow_configuration_options = { @@ -613,7 +654,7 @@ resource "aws_mwaa_environment" "test" { `, rName, retries, parallelism) } -func testAccAWSMwssEnvironmentLoggingConfigurationConfig(rName, logEnabled, logLevel string) string { +func testAccAWSMwaaEnvironmentLoggingConfigurationConfig(rName, logEnabled, logLevel string) string { return testAccAWSMwaaEnvironmentBase(rName) + fmt.Sprintf(` resource "aws_mwaa_environment" "test" { dag_s3_path = aws_s3_bucket_object.dags.key @@ -658,7 +699,7 @@ resource "aws_mwaa_environment" "test" { `, rName, logEnabled, logLevel) } -func testAccAWSMwssEnvironmentFullConfig(rName string) string { +func testAccAWSMwaaEnvironmentFullConfig(rName string) string { return testAccAWSMwaaEnvironmentBase(rName) + fmt.Sprintf(` resource "aws_mwaa_environment" "test" { airflow_configuration_options = { @@ -767,3 +808,30 @@ resource "aws_s3_bucket_object" "requirements" { `, rName) } + +func testAccAWSMwaaEnvironmentPluginsS3ObjectVersionConfig(rName, content string) string { + return testAccAWSMwaaEnvironmentBase(rName) + fmt.Sprintf(` +resource "aws_mwaa_environment" "test" { + dag_s3_path = aws_s3_bucket_object.dags.key + execution_role_arn = aws_iam_role.test.arn + name = %[1]q + + network_configuration { + security_group_ids = [aws_security_group.test.id] + subnet_ids = aws_subnet.private[*].id + } + + plugins_s3_path = aws_s3_bucket_object.plugins.key + plugins_s3_object_version = aws_s3_bucket_object.plugins.version_id + + source_bucket_arn = aws_s3_bucket.test.arn +} + +resource "aws_s3_bucket_object" "plugins" { + bucket = aws_s3_bucket.test.id + acl = "private" + key = "plugins.zip" + content = %q +} +`, rName, content) +}