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 plugins_s3_object_version to resourceAwsMwaaEnvironmentUpdate #19266

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19266.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_mwaa_environment: Correctly apply `plugins_s3_object_version` change
```
4 changes: 4 additions & 0 deletions aws/resource_aws_mwaa_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
92 changes: 80 additions & 12 deletions aws/resource_aws_mwaa_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
}